我已经实现了时间序列洞察聚合 API (GA) 来获取传感器的聚合值。
这是我对已构建的中间 API 的输入:
{
"PropertyName": "Prop1",
"PropertyValue": "ProVal",
"MeasuredValue": "Signal",
"FromDateTime": "2020-02-13T04:00:00.000Z",
"ToDateTime": "2020-02-13T04:01:00.000Z",
"EnvironmentFqdn": "fqdnvalue.env.timeseries.azure.com",
"BucketSize":"60s"
}
响应如预期:
[
{
"productTimeSeries": [
{
"deviceId": "SensorId",
"deviceAggregateTimeSeries": [
{
"bucket": "2020-02-13T04:00:00Z",
"avg": 296.0,
"min": 296.0,
"max": 296.0
}
]
}
]
}
]
但是,如果我更改从和到日期时间,然后更新存储桶大小:
{
"PropertyName": "Prop1",
"PropertyValue": "ProVal",
"MeasuredValue": "Signal",
"FromDateTime": "2020-02-13T04:00:00.000Z",
"ToDateTime": "2020-02-13T04:01:02.000Z",
"EnvironmentFqdn": "fqdnvalue.env.timeseries.azure.com",
"BucketSize":"62s"
}
这是我的回应:
[
{
"productTimeSeries": [
{
"deviceId": "SensorId",
"deviceAggregateTimeSeries": [
{
"bucket": "2020-02-13T03:59:20Z",
"avg": 296.0,
"min": 296.0,
"max": 296.0
},
{
"bucket": "2020-02-13T04:00:22Z",
"avg": 296.0,
"min": 296.0,
"max": 296.0
}
]
}
]
}
]
现在,由于存储桶大小等于从日期时间和到日期时间之间的时间差,我只希望在第一种情况下得到一个结果,但我得到的是两个结果。 为什么会这样?
这在内部调用实际的时间序列洞察聚合 API,请求形成如下:
JObject contentInputPayloadAggregates = new JObject(
new JProperty("searchSpan", new JObject(
new JProperty("from", getTelemetry.FromDateTime),
new JProperty("to", getTelemetry.ToDateTime))),
getPredicateSingle(getTelemetry.PropertyName, getTelemetry.PropertyValue),
new JProperty("aggregates", new JArray(new JObject(
new JProperty("dimension", new JObject(
new JProperty("uniqueValues", new JObject(
new JProperty("input", new JObject(
new JProperty("property", getTelemetry.PropertyName),
new JProperty("type", "String")
)),
new JProperty("take", 100)
))
)),
new JProperty("aggregate", new JObject(
new JProperty("dimension", new JObject(
new JProperty("dateHistogram", new JObject(
new JProperty("input", new JObject(
new JProperty("builtInProperty", "$ts")
)),
new JProperty("breaks", new JObject(
new JProperty("size", getTelemetry.BucketSize)
))
))
)),
new JProperty("measures", new JArray(new JObject(
new JProperty("avg", new JObject(
new JProperty("input", new JObject(
new JProperty("property", getTelemetry.MeasuredValue),
new JProperty("type", "Double")
))
))
),
new JObject(
new JProperty("min", new JObject(
new JProperty("input", new JObject(
new JProperty("property", getTelemetry.MeasuredValue),
new JProperty("type", "Double")
))
))
),
new JObject(
new JProperty("max", new JObject(
new JProperty("input", new JObject(
new JProperty("property", getTelemetry.MeasuredValue),
new JProperty("type", "Double")
))
))
)
))
))
)))
);