|
36 | 36 | Filter, |
37 | 37 | GetDatabaseConnectionRequest, |
38 | 38 | GetDatabaseConnectionResponse, |
| 39 | + GetLatestTabularDataRequest, |
| 40 | + GetLatestTabularDataResponse, |
39 | 41 | Order, |
40 | 42 | RemoveBinaryDataFromDatasetByIDsRequest, |
41 | 43 | RemoveBoundingBoxFromImageByIDRequest, |
@@ -298,6 +300,40 @@ async def tabular_data_by_mql(self, organization_id: str, mql_binary: List[bytes |
298 | 300 | response: TabularDataByMQLResponse = await self._data_client.TabularDataByMQL(request, metadata=self._metadata) |
299 | 301 | return [bson.decode(bson_bytes) for bson_bytes in response.raw_data] |
300 | 302 |
|
| 303 | + async def get_latest_tabular_data(self, part_id: str, resource_name: str, resource_subtype: str, method_name: str) -> Optional[Tuple[datetime, datetime, Dict[str, ValueTypes]]]: |
| 304 | + """Gets the most recent tabular data captured from the specified data source, as long as it was synced within the last year. |
| 305 | +
|
| 306 | + :: |
| 307 | +
|
| 308 | + time_captured, time_synced, payload = await data_client.get_latest_tabular_data( |
| 309 | + part_id="<PART-ID>", |
| 310 | + resource_name="<RESOURCE-NAME>", |
| 311 | + resource_subtype="<RESOURCE-SUBTYPE>", |
| 312 | + method_name="<METHOD-NAME>" |
| 313 | + ) |
| 314 | +
|
| 315 | +
|
| 316 | + Args: |
| 317 | + part_id (str): The ID of the part that owns the data. |
| 318 | + resource_name (str): The name of the requested resource that captured the data. |
| 319 | + resource_subtype (str): The subtype of the requested resource that captured the data. |
| 320 | + method_name (str): The data capture method name. |
| 321 | +
|
| 322 | + Returns: |
| 323 | + Optional[Tuple[datetime, datetime, Dict[str, ValueTypes]]]: A return value of None means that data hasn't been synced yet for the data source |
| 324 | + or the most recently captured data was over a year ago, otherwise the returned tuple contains the following: |
| 325 | + datetime: The time captured, |
| 326 | + datetime: The time synced, |
| 327 | + Dict[str, ValueTypes]: The latest tabular data captured from the specified data source. |
| 328 | + For more information, see `Data Client API <https://docs.viam.com/appendix/apis/data-client/>`_. |
| 329 | + """ |
| 330 | + |
| 331 | + request = GetLatestTabularDataRequest(part_id=part_id, resource_name=resource_name, resource_subtype=resource_subtype, method_name=method_name) |
| 332 | + response: GetLatestTabularDataResponse = await self._data_client.GetLatestTabularData(request, metadata=self._metadata) |
| 333 | + if not response.payload: |
| 334 | + return None |
| 335 | + return response.time_captured.ToDatetime(), response.time_synced.ToDatetime(), struct_to_dict(response.payload) |
| 336 | + |
301 | 337 | async def binary_data_by_filter( |
302 | 338 | self, |
303 | 339 | filter: Optional[Filter] = None, |
|
0 commit comments