tabularDataCaptureUpload method

Future<String> tabularDataCaptureUpload(
  1. List<Map<String, dynamic>> tabularData,
  2. String partId, {
  3. String? componentType,
  4. String? componentName,
  5. String? methodName,
  6. Map<String, Any>? methodParameters,
  7. List<(DateTime, DateTime)>? dataRequestTimes,
  8. Iterable<String> tags = const [],
})

Upload tabular sensor data to Viam's Data Manager

Returns the data's file ID.

_viam = await Viam.withApiKey(
     dotenv.env['API_KEY_ID'] ?? '',
     dotenv.env['API_KEY'] ?? ''
 );

 try {
   // Define tabular data
   final List<Map<String, dynamic>> tabularData;
   tabularData = [{
     'readings': {
       "altitude_m": 50.2,
       "coordinate": {
         "latitude": 40.5,
         "longitude": -72.98
      }
     }
   }];

  // Define date request times
  final List<(DateTime, DateTime)> timeSpan = [(DateTime(2025, 1, 23, 11), DateTime(2025, 1, 23, 11, 0, 3))];

  // Upload captured tabular data
  final fileId = await dataClient.tabularDataCaptureUpload(
    tabularData,
    "<YOUR-PART-ID>",
    componentType: "rdk:component:movement_sensor",
    componentName: "movement_sensor-1",
    methodName: "Position",
    dataRequestTimes: timeSpan,
    tags: ["tag_1", "tag_2"]
  );
   print('Successfully uploaded captured tabular data: $fileId');
 } catch (e) {
   print('Error uploading captured tabular data: $e');
 }

For more information, see Data Client API.

Implementation

Future<String> tabularDataCaptureUpload(List<Map<String, dynamic>> tabularData, String partId,
    {String? componentType,
    String? componentName,
    String? methodName,
    Map<String, Any>? methodParameters,
    List<(DateTime, DateTime)>? dataRequestTimes,
    Iterable<String> tags = const []}) async {
  if (dataRequestTimes != null && dataRequestTimes.length != tabularData.length) {
    throw Exception('dataRequestTimes and tabularData lengths must be equal');
  }
  final sensorContents = <SensorData>[];
  for (final (idx, data) in tabularData.indexed) {
    final s = data.toStruct();
    final sensorMetadata = SensorMetadata();
    if (dataRequestTimes != null) {
      sensorMetadata.timeRequested = Timestamp.fromDateTime(dataRequestTimes[idx].$1);
      sensorMetadata.timeReceived = Timestamp.fromDateTime(dataRequestTimes[idx].$2);
    }
    final sensorData = SensorData()
      ..struct = s
      ..metadata = sensorMetadata;
    sensorContents.add(sensorData);
  }

  final metadata = UploadMetadata()
    ..partId = partId
    ..componentType = componentType ?? ''
    ..componentName = componentName ?? ''
    ..methodName = methodName ?? ''
    ..type = DataType.DATA_TYPE_TABULAR_SENSOR
    ..tags.addAll(tags);
  if (methodParameters != null) metadata.methodParameters.addAll(methodParameters);

  final request = DataCaptureUploadRequest()
    ..metadata = metadata
    ..sensorContents.addAll(sensorContents);
  final response = await _dataSyncClient.dataCaptureUpload(request);
  return response.fileId;
}