简体   繁体   中英

Azure Time Series Insights Bucket size

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")
                                    ))
                                ))
                            )
                            ))

                            ))


                         )))

                    );

Time Series Insights uses a method where we count epoch ticks (the number of milliseconds that have elapsed since Jan 1, 0001) and divide the ticks into the selected interval spans, in your case 60 or 62 seconds. We internally adjust the search span to align with the calculated interval timestamps.

Depending on how many intervals result from the calculation, you may see 1 or 2 buckets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM