I have implemented time series insights aggregate API (GA) to get aggregate values of a sensor.
This is my input to the intermediary API that I have built:
{
"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"
}
The response is as expected:
[
{
"productTimeSeries": [
{
"deviceId": "SensorId",
"deviceAggregateTimeSeries": [
{
"bucket": "2020-02-13T04:00:00Z",
"avg": 296.0,
"min": 296.0,
"max": 296.0
}
]
}
]
}
]
However, if I change the from and to date time and then update the bucket size:
{
"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"
}
Here is my response:
[
{
"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
}
]
}
]
}
]
Now, since the bucket size is equal to the time difference between the from and to date time I am expecting just one result as in the first case but what I am getting are two results. Why is this happening?
Internally this calls the actual time series insights aggregates API with the request formed as below:
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")
))
))
)
))
))
)))
);