Skip to content

Commit

Permalink
Change return type to a list #DATA-3446
Browse files Browse the repository at this point in the history
  • Loading branch information
katiepeters committed Dec 17, 2024
1 parent eb93448 commit fb4307f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
39 changes: 21 additions & 18 deletions lib/src/app/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ class DataClient {

/// Obtain unified tabular data and metadata from the specified data source.
///
/// Returns a stream of data points.
/// Returns a list of data points.
///
/// For more information, see [Data Client API](https://docs.viam.com/appendix/apis/data-client/).
Stream<TabularDataPoint> exportTabularData(
Future<List<TabularDataPoint>> exportTabularData(
String partId,
String resourceName,
String resourceSubtype,
String methodName,
DateTime? startTime,
DateTime? endTime,
) {
) async {
final interval = CaptureInterval();
if (startTime != null) {
interval.start = Timestamp.fromDateTime(startTime);
Expand All @@ -191,21 +191,24 @@ class DataClient {
..methodName = methodName
..interval = interval;

return _dataClient.exportTabularData(request).map((response) => TabularDataPoint(
partId: response.partId,
resourceName: response.resourceName,
resourceSubtype: response.resourceSubtype,
methodName: response.methodName,
timeCaptured: response.timeCaptured.toDateTime(),
organizationId: response.organizationId,
locationId: response.locationId,
robotName: response.robotName,
robotId: response.robotId,
partName: response.partName,
methodParameters: response.methodParameters.toMap(),
tags: response.tags,
payload: response.payload.toMap(),
));
return _dataClient
.exportTabularData(request)
.map((response) => TabularDataPoint(
partId: response.partId,
resourceName: response.resourceName,
resourceSubtype: response.resourceSubtype,
methodName: response.methodName,
timeCaptured: response.timeCaptured.toDateTime(),
organizationId: response.organizationId,
locationId: response.locationId,
robotName: response.robotName,
robotId: response.robotId,
partName: response.partName,
methodParameters: response.methodParameters.toMap(),
tags: response.tags,
payload: response.payload.toMap(),
))
.toList();
}

/// Delete tabular data older than a provided number of days from an organization.
Expand Down
4 changes: 2 additions & 2 deletions test/unit_test/app/data_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ void main() {
),
]));

final response = dataClient.exportTabularData('partId1', 'resourceName1', 'resourceSubtype1', 'methodName', null, null);
final response = await dataClient.exportTabularData('partId1', 'resourceName1', 'resourceSubtype1', 'methodName', null, null);
var index = 0;
await for (final point in response) {
for (final point in response) {
expect(point.partId, equals(data[index].partId));
expect(point.resourceName, equals(data[index].resourceName));
expect(point.resourceSubtype, equals(data[index].resourceSubtype));
Expand Down

0 comments on commit fb4307f

Please sign in to comment.