Skip to content
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-fix] Next -> ReadImage. #1471

Merged
merged 6 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions services/datamanager/datacapture/data_capture_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// FileExt defines the file extension for Viam data capture files.
const (
FileExt = ".capture"
next = "Next"
readImage = "ReadImage"
nextPointCloud = "NextPointCloud"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func BuildCaptureMetadata(compType resource.SubtypeName, compName, compModel, me
return nil, err
}

dataType := getDataType(string(compType), method)
dataType := getDataType(method)
return &v1.DataCaptureMetadata{
ComponentType: string(compType),
ComponentName: compName,
Expand Down Expand Up @@ -112,9 +112,9 @@ func getFileTimestampName() string {

// TODO DATA-246: Implement this in some more robust, programmatic way.
// TODO: support GetImage. This is why image stuff isn't working.
func getDataType(_, methodName string) v1.DataType {
func getDataType(methodName string) v1.DataType {
switch methodName {
case nextPointCloud, next:
case nextPointCloud, readImage:
return v1.DataType_DATA_TYPE_BINARY_SENSOR
default:
return v1.DataType_DATA_TYPE_TABULAR_SENSOR
Expand All @@ -133,7 +133,7 @@ func GetFileExt(dataType v1.DataType, methodName string, parameters map[string]s
if methodName == nextPointCloud {
return ".pcd"
}
if methodName == next {
if methodName == readImage {
// TODO: Add explicit file extensions for all mime types.
switch parameters["mime_type"] {
case utils.MimeTypeJPEG:
Expand Down
41 changes: 21 additions & 20 deletions services/datamanager/datacapture/data_capture_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestBuildCaptureMetadata(t *testing.T) {
componentType: "camera",
componentName: "cam1",
componentModel: "webcam",
method: "Next",
method: readImage,
additionalParams: map[string]string{"mime_type": utils.MimeTypeJPEG},
dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR,
fileExtension: ".jpeg",
Expand All @@ -50,7 +50,7 @@ func TestBuildCaptureMetadata(t *testing.T) {
componentType: "camera",
componentName: "cam1",
componentModel: "velodyne",
method: "Next",
method: readImage,
additionalParams: map[string]string{"mime_type": utils.MimeTypePCD},
dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR,
fileExtension: ".pcd",
Expand All @@ -61,7 +61,7 @@ func TestBuildCaptureMetadata(t *testing.T) {
componentType: "camera",
componentName: "cam1",
componentModel: "velodyne",
method: "NextPointCloud",
method: nextPointCloud,
additionalParams: make(map[string]string),
dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR,
fileExtension: ".pcd",
Expand All @@ -70,24 +70,25 @@ func TestBuildCaptureMetadata(t *testing.T) {
}

for _, tc := range tests {
t.Log(tc.name)
actualMetadata, err := BuildCaptureMetadata(
tc.componentType, tc.componentName, tc.componentModel, tc.method, tc.additionalParams, tc.tags)
test.That(t, err, test.ShouldEqual, nil)
t.Run(tc.name, func(t *testing.T) {
actualMetadata, err := BuildCaptureMetadata(
tc.componentType, tc.componentName, tc.componentModel, tc.method, tc.additionalParams, tc.tags)
test.That(t, err, test.ShouldEqual, nil)

methodParams, err := protoutils.ConvertStringMapToAnyPBMap(tc.additionalParams)
test.That(t, err, test.ShouldEqual, nil)
methodParams, err := protoutils.ConvertStringMapToAnyPBMap(tc.additionalParams)
test.That(t, err, test.ShouldEqual, nil)

expectedMetadata := v1.DataCaptureMetadata{
ComponentType: string(tc.componentType),
ComponentName: tc.componentName,
ComponentModel: tc.componentModel,
MethodName: tc.method,
Type: tc.dataType,
MethodParameters: methodParams,
FileExtension: tc.fileExtension,
Tags: tc.tags,
}
test.That(t, actualMetadata.String(), test.ShouldEqual, expectedMetadata.String())
expectedMetadata := v1.DataCaptureMetadata{
ComponentType: string(tc.componentType),
ComponentName: tc.componentName,
ComponentModel: tc.componentModel,
MethodName: tc.method,
Type: tc.dataType,
MethodParameters: methodParams,
FileExtension: tc.fileExtension,
Tags: tc.tags,
}
test.That(t, actualMetadata.String(), test.ShouldEqual, expectedMetadata.String())
})
}
}