-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data-3395: Add GetLatestTabularData #793
base: main
Are you sure you want to change the base?
Changes from 5 commits
4ba4d82
d6b1d80
edcb84e
fb08219
2b0ebdc
7381d18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ | |
Filter, | ||
GetDatabaseConnectionRequest, | ||
GetDatabaseConnectionResponse, | ||
GetLatestTabularDataRequest, | ||
GetLatestTabularDataResponse, | ||
Order, | ||
RemoveBinaryDataFromDatasetByIDsRequest, | ||
RemoveBoundingBoxFromImageByIDRequest, | ||
|
@@ -306,6 +308,39 @@ async def tabular_data_by_mql(self, organization_id: str, mql_binary: List[bytes | |
response: TabularDataByMQLResponse = await self._data_client.TabularDataByMQL(request, metadata=self._metadata) | ||
return [bson.decode(bson_bytes) for bson_bytes in response.raw_data] | ||
|
||
async def get_latest_tabular_data(self, part_id: str, resource_name: str, resource_subtype: str, method_name: str) -> Tuple[ Optional[datetime], Optional[datetime], Dict[str, ValueTypes]]: | ||
"""Gets the most recent tabular data captured from the specified data source, as long as it was synced within the last year. | ||
|
||
:: | ||
|
||
time_captured, time_synced, payload = await data_client.get_latest_tabular_data( | ||
part_id="<PART-ID>", | ||
resource_name="<RESOURCE-NAME>", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add resource_subtype? |
||
method_name="<METHOD-NAME>" | ||
) | ||
|
||
|
||
Args: | ||
part_id (str): The ID of the part that owns the data. | ||
resource_name (str): The name of the requested resource that captured the data. | ||
resource_subtype (str): The subtype of the requested resource that captured the data. | ||
method_name (str): The data capture method name. | ||
|
||
Returns: | ||
Tuple[Dict[str, ValueTypes], Optional[datetime], Optional[datetime]: A tuple containing the following: | ||
Optional[datetime]: The time captured, | ||
Optional[datetime]: The time synced, | ||
Dict[str, ValueTypes]: The latest tabular data captured from the specified data source. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rearrange these return types to match the order they are returned in the tuple |
||
For more information, see `Data Client API <https://docs.viam.com/appendix/apis/data-client/>`_. | ||
""" | ||
|
||
request = GetLatestTabularDataRequest(part_id=part_id, resource_name=resource_name, resource_subtype=resource_subtype, method_name=method_name) | ||
response: GetLatestTabularDataResponse = await self._data_client.GetLatestTabularData(request, metadata=self._metadata) | ||
if not response.payload: | ||
return None, None, {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we get an empty GetLatestTabularDataResponse (aka data hasn't been synced yet for the data source) could we return None for the whole return tuple? I don't like how only the time_captured and time_synced fields are optional and the payload isn't, since those are associated with the payload and should only be returned when the payload is also present. I'm not very familiar with python - so let me know if this is not super python-y! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes makes sense, i changed the entire tuple to be optional so we can return None |
||
return response.time_captured.ToDatetime(), response.time_synced.ToDatetime(), struct_to_dict(response.payload) | ||
|
||
|
||
async def binary_data_by_filter( | ||
self, | ||
filter: Optional[Filter] = None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "0.34.0" | ||
|
||
API_VERSION = "v0.1.361" | ||
API_VERSION = "v0.1.366" | ||
SDK_VERSION = __version__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,8 @@ | |
DeleteTabularDataResponse, | ||
GetDatabaseConnectionRequest, | ||
GetDatabaseConnectionResponse, | ||
GetLatestTabularDataRequest, | ||
GetLatestTabularDataResponse, | ||
RemoveBinaryDataFromDatasetByIDsRequest, | ||
RemoveBinaryDataFromDatasetByIDsResponse, | ||
RemoveBoundingBoxFromImageByIDRequest, | ||
|
@@ -1001,6 +1003,18 @@ async def TabularDataByMQL(self, stream: Stream[TabularDataByMQLRequest, Tabular | |
assert request is not None | ||
await stream.send_message(TabularDataByMQLResponse(raw_data=[bson.encode(dict) for dict in self.tabular_query_response])) | ||
|
||
async def GetLatestTabularData(self, stream: Stream[GetLatestTabularDataRequest, GetLatestTabularDataResponse]) -> None: | ||
request = await stream.recv_message() | ||
assert request is not None | ||
self.part_id = request.part_id | ||
self.resource_name = request.resource_name | ||
self.resource_subtype = request.resource_subtype | ||
self.method_name = request.method_name | ||
timestamp = datetime_to_timestamp(datetime(2024, 12, 25)) | ||
data=dict_to_struct(self.tabular_response[0].data) | ||
await stream.send_message(GetLatestTabularDataResponse(payload=data, time_captured=timestamp, time_synced=timestamp)) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this is one too many new lines added |
||
|
||
class MockDataset(DatasetServiceBase): | ||
def __init__(self, create_response: str, datasets_response: Sequence[Dataset]): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since some of the return values are optional, I think they should be moved to be after the non-optional value in the tuple