exportTabularData method
Obtain unified tabular data and metadata from the specified data source.
Returns a list of unified tabular data and metadata.
_viam = await Viam.withApiKey(
dotenv.env['API_KEY_ID'] ?? '',
dotenv.env['API_KEY'] ?? ''
);
final dataClient = _viam.dataClient;
try {
// Define date request times
final startTime = DateTime(2025, 1, 23, 11);
final endTime = DateTime(2025, 1, 23, 11, 0, 3);
final tabularData = await dataClient.exportTabularData(
"<YOUR-PART-ID>",
"movement_sensor-1",
"rdk:component:movement_sensor",
"Position",
startTime,
endTime
);
for (var dataPoint in tabularData) {
print(dataPoint.partId);
print(dataPoint.resourceName);
print(dataPoint.methodName);
print(dataPoint.payload);
}
print('Successfully exported tabular data');
} catch (e) {
print('Error exporting tabular data: $e');
}
For more information, see Data Client API.
Implementation
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);
}
if (endTime != null) {
interval.end = Timestamp.fromDateTime(endTime);
}
final request = ExportTabularDataRequest()
..partId = partId
..resourceName = resourceName
..resourceSubtype = resourceSubtype
..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(),
))
.toList();
}