Skip to content

Commit

Permalink
Save labels metadata to JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe-Heffer-Shef committed Jun 14, 2024
1 parent 461b730 commit c592684
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions backend/btviewer/blueprints/label/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ def create():

# Load the selected image
photo_path = flask.request.args['path']
source = flask.request.args['source']
photo = Photo(photo_path)

# Get the label data from the request
source = flask.request.args['source']
version = flask.request.args['version']
labels = flask.request.json

# Create the labels
photo.add_labels(labels, source=source)
photo.add_labels(labels, source=source, version=version)

# Return a success response
return flask.Response(status=HTTPStatus.CREATED)
14 changes: 12 additions & 2 deletions backend/btviewer/blueprints/photo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,25 @@ def add_label(self, **kwargs):
"""
raise NotImplementedError

def add_labels(self, labels: list[dict], source: str):
def add_labels(self, labels: list[dict], source: str, version: str, indent: int = 2):
label_file_path = self.label_directory.joinpath(f'{source}.json')

# Make label directory
self.label_directory.mkdir(exist_ok=True)

# Build our labels metadata file contents
document = {
"provenance": {
"source": source,
"version": version,
"mode": "manual"
},
"tags": labels
}

# Save label file
with label_file_path.open('w') as file:
json.dump(labels, file)
json.dump(document, file, indent=indent)
app.logger.info("Labels saved to '%s'", file.name)

@property
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/SaveMarkers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function SaveMarkers(props) {
// eslint-disable-next-line no-unused-vars
const photo_path = '1970-01-01/set_A/device_1234/camera_1/20200101_094359.123456_000002.np';
const source = 'btviewer';
const url = `/api/labels/create?path=${photo_path}&source=${source}`;
const version = '0.0.0'
const url = `/api/labels/create?path=${photo_path}&source=${source}&version=${version}`;

fetch(url, {
method: 'post',
Expand Down

0 comments on commit c592684

Please sign in to comment.