Query Utilities¶
Classes and utilities for working with TempoIQ’s query interface.
Query Builder¶
-
class
tempoiq.protocol.query.builder.
QueryBuilder
(client, object_type)[source]¶ Class to build queries. All instance methods in this class return the instance itself. This allows you to construct queries fluently, by chaining method calls.
-
aggregate
(function)[source]¶ Aggregate the data in the query with the specified aggregation function
-
convert_timezone
(tz)[source]¶ Convert the result’s data points to the specified time zone.
Parameters: tz (String) – Time zone
-
delete
(**kwargs)[source]¶ Execute an API call to delete the objects that are a result of this query. Currently only supported for deleting entire devices. equivalent to passing this QueryBuilder to
tempoiq.client.Client.delete_device()
-
filter
(selector)[source]¶ Filter the query based on the provided selector. The argument may be a
ScalarSelector
or the result of combining several selectors withor_()
orand_()
.Parameters: selector –
-
interpolate
(function, period, start=None, end=None)[source]¶ Interpolate the sensor data
Parameters: - function (String) – Interpolation function (“zoh” or “linear”)
- period (String) – Time period to interpolate
-
multi_rollup
(functions, period, start=None)[source]¶ Apply multiple rollups to the same sensor data.
Parameters: - functions (list) – list of rollup functions to apply
- period (String) – Time period of the rollups
-
read
(**kwargs)[source]¶ Make the API call to the TempoIQ backend for this query.
Parameters: - start (DateTime) – required when reading sensor data. Start of time range to read.
- end (DateTime) – required when reading sensor data. End of time range to read.
-
rollup
(function, period, start=None)[source]¶ Apply a rollup function to the query.
Parameters: - function (String) – The rollup function to apply
- period (String) – The time period of the rollup
- start (DateTime) – (optional) A timestamp to use as the start of
the first rollup period. Default is the same as the start of the read.
-
Query Functions¶
Selectors¶
-
class
tempoiq.protocol.query.selection.
ScalarSelector
(selection_type, key, value)[source]¶ A condition to filter on. The recommended way to construct a ScalarSelector is with the
==
operator on a selectable field, e.g:selector = (Device.attributes['model'] == "v1") selector2 = (Sensor.key == "humidity")
-
tempoiq.protocol.query.selection.
and_
(selectors)[source]¶ Returns a selector that’s the AND of all provided selectors.
Parameters: selectors (List of ScalarSelector
) –
-
tempoiq.protocol.query.selection.
or_
(selectors)[source]¶ Returns a selector that’s the OR of all provided selectors.
Parameters: selectors (List of ScalarSelector
) –