0
# Timeseries Data
1
2
Advanced querying capabilities for timeseries data with batch operations, historical data access, raw and sampled data retrieval for comprehensive IoT analytics.
3
4
## Core Imports
5
6
```python
7
from iot_api_client.api import SeriesV2Api
8
from iot_api_client.models import (
9
BatchQueryRawRequestsMediaV1,
10
BatchQuerySampledRequestsMediaV1,
11
BatchLastValueRequestsMediaV1,
12
HistoricDataRequest,
13
ArduinoSeriesRawResponse,
14
ArduinoSeriesSampledResponse,
15
ArduinoSeriesRawLastValueResponse,
16
ArduinoSeriesResponse
17
)
18
```
19
20
## Capabilities
21
22
### Batch Raw Data Queries
23
24
Retrieve raw timeseries data for multiple properties in a single request.
25
26
```python { .api }
27
class SeriesV2Api:
28
def series_v2_batch_query_raw(self, batch_query_raw_requests_media_v1: BatchQueryRawRequestsMediaV1, x_organization: str = None) -> ArduinoSeriesRawResponse:
29
"""
30
Batch query raw timeseries data for multiple properties.
31
32
Args:
33
batch_query_raw_requests_media_v1: Batch query configuration for raw data
34
x_organization: Organization ID for organization-level access
35
36
Returns:
37
ArduinoSeriesRawResponse: Raw timeseries data response
38
"""
39
```
40
41
### Batch Sampled Data Queries
42
43
Retrieve aggregated/sampled timeseries data for multiple properties.
44
45
```python { .api }
46
class SeriesV2Api:
47
def series_v2_batch_query_sampling(self, batch_query_sampled_requests_media_v1: BatchQuerySampledRequestsMediaV1, x_organization: str = None) -> ArduinoSeriesSampledResponse:
48
"""
49
Batch query sampled timeseries data for multiple properties.
50
51
Args:
52
batch_query_sampled_requests_media_v1: Batch query configuration for sampled data
53
x_organization: Organization ID for organization-level access
54
55
Returns:
56
ArduinoSeriesSampledResponse: Sampled timeseries data response
57
"""
58
```
59
60
### Batch Last Value Queries
61
62
Get the most recent values for multiple properties efficiently.
63
64
```python { .api }
65
class SeriesV2Api:
66
def series_v2_batch_query_raw_last_value(self, batch_last_value_requests_media_v1: BatchLastValueRequestsMediaV1, x_organization: str = None) -> ArduinoSeriesRawLastValueResponse:
67
"""
68
Batch query for the last value of multiple properties.
69
70
Args:
71
batch_last_value_requests_media_v1: Batch last value query configuration
72
x_organization: Organization ID for organization-level access
73
74
Returns:
75
ArduinoSeriesRawLastValueResponse: Last values response
76
"""
77
```
78
79
### Historic Data Requests
80
81
Access archived historical data with advanced filtering options.
82
83
```python { .api }
84
class SeriesV2Api:
85
def series_v2_historic_data(self, historic_data_request: HistoricDataRequest, x_organization: str = None) -> ArduinoSeriesResponse:
86
"""
87
Request historic data for properties.
88
89
Args:
90
historic_data_request: Historic data request configuration
91
x_organization: Organization ID for organization-level access
92
93
Returns:
94
ArduinoSeriesResponse: Historic data response
95
"""
96
```
97
98
## Usage Examples
99
100
### Batch Query Raw Data
101
102
```python
103
from iot_api_client.models import (
104
BatchQueryRawRequestsMediaV1,
105
BatchQueryRawRequestMediaV1
106
)
107
from datetime import datetime, timedelta
108
109
# Query raw data for multiple properties
110
end_time = datetime.utcnow()
111
start_time = end_time - timedelta(hours=24)
112
113
raw_request = BatchQueryRawRequestMediaV1(
114
thing_id="thing-id",
115
property_id="temperature-property-id",
116
from_date=start_time.isoformat() + "Z",
117
to_date=end_time.isoformat() + "Z"
118
)
119
120
batch_request = BatchQueryRawRequestsMediaV1(
121
requests=[raw_request]
122
)
123
124
raw_response = series_api.series_v2_batch_query_raw(batch_request)
125
126
for series in raw_response.data:
127
print(f"Property: {series.property_id}")
128
for point in series.values:
129
print(f" Time: {point.timestamp}, Value: {point.value}")
130
```
131
132
### Batch Query Sampled Data
133
134
```python
135
from iot_api_client.models import (
136
BatchQuerySampledRequestsMediaV1,
137
BatchQuerySampledRequestMediaV1
138
)
139
140
# Query sampled data with 1-hour intervals
141
sampled_request = BatchQuerySampledRequestMediaV1(
142
thing_id="thing-id",
143
property_id="temperature-property-id",
144
from_date=start_time.isoformat() + "Z",
145
to_date=end_time.isoformat() + "Z",
146
interval=3600, # 1 hour in seconds
147
aggregation="AVG" # Average aggregation
148
)
149
150
batch_sampled_request = BatchQuerySampledRequestsMediaV1(
151
requests=[sampled_request]
152
)
153
154
sampled_response = series_api.series_v2_batch_query_sampling(batch_sampled_request)
155
156
for series in sampled_response.data:
157
print(f"Property: {series.property_id}")
158
for point in series.values:
159
print(f" Time: {point.timestamp}, Avg Value: {point.value}")
160
```
161
162
### Get Last Values
163
164
```python
165
from iot_api_client.models import (
166
BatchLastValueRequestsMediaV1,
167
BatchQueryRawLastValueRequestMediaV1
168
)
169
170
# Get last values for multiple properties
171
last_value_request = BatchQueryRawLastValueRequestMediaV1(
172
thing_id="thing-id",
173
property_ids=["temperature-id", "humidity-id", "pressure-id"]
174
)
175
176
batch_last_value_request = BatchLastValueRequestsMediaV1(
177
requests=[last_value_request]
178
)
179
180
last_values_response = series_api.series_v2_batch_query_raw_last_value(batch_last_value_request)
181
182
for series in last_values_response.data:
183
if series.last_value:
184
print(f"Property {series.property_id}: {series.last_value.value} at {series.last_value.timestamp}")
185
```
186
187
### Historic Data Query
188
189
```python
190
from iot_api_client.models import HistoricDataRequest
191
192
# Request historic data with specific criteria
193
historic_request = HistoricDataRequest(
194
thing_id="thing-id",
195
property_id="sensor-property-id",
196
from_date="2024-01-01T00:00:00Z",
197
to_date="2024-01-31T23:59:59Z",
198
sort="DESC",
199
interval=86400 # Daily aggregation
200
)
201
202
historic_response = series_api.series_v2_historic_data(historic_request)
203
204
print(f"Retrieved {len(historic_response.values)} data points")
205
for i, (timestamp, value) in enumerate(zip(historic_response.times, historic_response.values)):
206
print(f" {timestamp}: {value}")
207
```
208
209
## Types
210
211
```python { .api }
212
class BatchQueryRawRequestsMediaV1:
213
requests: List[BatchQueryRawRequestMediaV1]
214
215
class BatchQueryRawRequestMediaV1:
216
thing_id: str
217
property_id: str
218
from_date: str
219
to_date: str
220
sort: str # "ASC" or "DESC"
221
limit: int
222
223
class BatchQuerySampledRequestsMediaV1:
224
requests: List[BatchQuerySampledRequestMediaV1]
225
226
class BatchQuerySampledRequestMediaV1:
227
thing_id: str
228
property_id: str
229
from_date: str
230
to_date: str
231
interval: int
232
aggregation: str # "AVG", "MIN", "MAX", "SUM", "COUNT"
233
sort: str
234
235
class BatchLastValueRequestsMediaV1:
236
requests: List[BatchQueryRawLastValueRequestMediaV1]
237
238
class BatchQueryRawLastValueRequestMediaV1:
239
thing_id: str
240
property_ids: List[str]
241
242
class HistoricDataRequest:
243
thing_id: str
244
property_id: str
245
from_date: str
246
to_date: str
247
sort: str
248
interval: int
249
250
class ArduinoSeriesRawResponse:
251
count_values: int
252
data: List[BatchQueryRawResponseSeriesMediaV1]
253
from_date: str
254
interval: int
255
message: str
256
query: str
257
resp_version: int
258
series_limit: int
259
sort: str
260
status: str
261
to_date: str
262
263
class ArduinoSeriesSampledResponse:
264
count_values: int
265
data: List[ArduinoSeriesBatchSampled]
266
from_date: str
267
interval: int
268
message: str
269
query: str
270
resp_version: int
271
series_limit: int
272
sort: str
273
status: str
274
to_date: str
275
276
class ArduinoSeriesRawLastValueResponse:
277
data: List[ArduinoSeriesRawBatchLastvalue]
278
message: str
279
query: str
280
resp_version: int
281
status: str
282
283
class ArduinoSeriesResponse:
284
count_values: int
285
data: List[TimeseriesDataPoint]
286
from_date: datetime
287
interval: int
288
message: str
289
query: str
290
resp_version: int
291
series_limit: int
292
sort: str
293
status: str
294
times: List[str]
295
to_date: datetime
296
values: List[Any]
297
```