IOT TS Aggregates Client for Python¶
The IoT TS Aggregates Python client allows you to query aggregated time series data. Refer to IoT TS Aggregates for more information about the service.
Further implementation of the IOT TS Aggregate SDK library has been shown in a sample project that you can download and test in local or on mindsphere application. Please refer to this repository: mindsphere-python-sdk-examples
In the IoT context, assets are referred to as
entity and aspects as
Placeholders in the following samples are indicated by angular brackets
IOT TSAggregate Operations¶
Client Name: AggregatesClient
Get aggregated time series data for one aspect of an asset.¶
Returns a list of aggregates for a given asset and aspect. The time range of the aggregates can be defined by a combination of parameters; such as from, to, intervalUnit, intervalValue and count. Time range can be specified anywhere in past or future for which timeseries data is present. In the case no time series data was available for an aggregation interval, no aggregate will be returned. Pre-computed aggregates are aligned with the tenant time zone.
- The maximum time range for querying DAY/WEEK/MONTH aggregates is 90 days.
- The maximum time range for querying HOUR aggregates is 7 days.
- The maximum time range for querying 2 MINUTE aggregates is 24 hours.
- The parameters from, to, intervalUnit, intervalValue, and count are used to determine the time range and interval length to return aggregates for.
- Intelligent auto-completion is applied to allow clients to only provide a subset of the parameters, according to the following rules:
- In case none of the parameters is provided, intervalUnit is set to DAY, intervalValue is set to 1, to is set to the current time, and from is set to the current time minus 7 days.
- If only from is provided, to is set such that a 90 day time range results or, in case a larger range would result, to the current time. from is truncated to date-only for this calculation.
- If only to is provided, from is set such that a 90 day time range results.
- If intervalUnit, intervalValue and count are provided, it suffices to either provide to or from in addition. The missing parameter is determined based on the time range computed from intervalUnit, intervlValue and count.
- If intervalUnit and intervalValue are not provided, the largest available interval length fitting into the used time range is chosen.
- If count is not provided, but the other parameters are, count will be derived based on the time range divided by the intervalUnit and intervalValue.
- In case parameters from or to are provided but do not coincide with the pre-calculated interval boundaries of the used interval, from and to are shifted such that the overall time range contains the provided one and time range boundaries coincide with interval boundaries.
- If from, to and count are provided, intervalUnit, intervalValue is determined based on the time range divided by count.
- Example 1: use of intervalUnit, intervalValue and count to derive end of time range.
A request with open time range is made from = 2019-02-01Z intervalUnit = day intervalValue = 1 count = 7
Rule 4 is applied to determine the 'to' parameter to = 2019-02-08Z
- Example 2: time range auto-extension and count derivation.* A request with missing 'to' and 'count' parameters is made, and current system time is 2019-02-01T20:00:00Z from = 2019-02-01T10:00:00Z intervalUnit = hour intervalValue = 1 The 'to' time is derived based on Rule 2 to be the current time and 'count' is determined applying Rule 6 to = 2019-02-01T20:00:00Z count = 10
- Example 3: intervalUnit and intervalValue auto-completion.* A request without 'intervalUnit', 'intervalValue' and 'count' is made from = 2020-10-10T10:00:00Z to = 2020-10-10T10:30:00Z Rule 5 is applied to determine the interval length based on the time range only. The count is derived based on rule 6 in the following. intervalUnit = minute intervalValue = 2 count = 15
- Example 4: intervalUnit and intervalValue auto-completion with larger interval* Similar as Example 3, a request without 'intervalUnit', 'intervalValue' and 'count' is made from = 2020-10-10T10:00:00Z to = 2020-10-10T12:00:00Z Rules 5 and 6 are applied, but since the time range is multiple hours long, the interval is determined to be HOUR intervalUnit = hour intervalValue = 1 count = 2
- Example 5: intervalUnit and intervalValue auto-completion with much larger interval* Similar as Example 3 and 4, a request without 'intervalUnit', 'intervalValue' and 'count' is made from = 2020-10-10T00:00:00Z to = 2020-10-15T00:00:00Z Rules 5 and 6 are applied, but since the time range is multiple days long, the interval is determined to be DAY intervalUnit = day intervalValue = 1 count = 5
- Example 6: intervalUnit and intervalValue auto-completion when count is also provided.* A request without 'intervalUnit' and 'intervalValue' is made from = 2020-10-10T10:00:00Z to = 2020-10-10T10:30:00Z count = 3 Since the difference between from and to date is 30 minute, and count asked is 3. Rule 8 is applied and 3 aggregate buckets of 10 minute is returned intervalUnit = minute intervalValue = 10
- Example 7: to and from date adjusted to pre-computed aggregate boundary* Following request is made from = 2020-10-10T02:10:00Z to = 2020-10-10T09:10:00Z intervalUnit = hour intervalValue = 1 Rule 7 is applied since aggregate is queried for 1 hour and dates are not aligned to Hour boundary, from and to dates are adjusted to Hour boundary from = 2020-10-10T02:00:00Z to = 2020-10-10T10:00:00Z
- Example 8: to, from, intervalUnit and intervalValue asking for 4 hour aggregate* Following request is made from = 2020-10-10T00:00:00Z to = 2020-10-11T00:00:00Z intervalUnit = hour intervalValue = 4 Since pre-computed aggregate exists for every HOUR, Hourly aggregates will be combined and a response bucket every 4 hours will be returned
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Import the RestClientConfig and UserToken from mindsphere_core module from mindsphere_core import RestClientConfig from mindsphere_core import UserToken # Import the MindsphereError from mindsphere_core.exceptions module from mindsphere_core.exceptions import MindsphereError # Import the AggregatesClient from mindconnect module from iottsaggregates.clients.aggregates_client import AggregatesClient # Create the TimeSeriesOperationsClient object using the RestClientConfig and UserToken objects aggregatesClient = AggregatesClient(rest_client_config = config, mindsphere_credentials = credentials) try: # Create the request object retrieveAggregatesRequest = RetrieveAggregatesRequest() retrieveAggregatesRequest.asset_id = "5908ae5c5e4f4e18b0be58cd21ee675f" retrieveAggregatesRequest.aspect_name = "test_2020_11_11" # Initiate the API call response = aggregatesClient.retrieve_aggregates(retrieveAggregatesRequest) except MindsphereError as err: # Exception Handling
Any questions left?
Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.