Simplified new configuration and metadata

This commit is contained in:
Joel Collins 2020-01-29 15:36:57 +00:00
parent 5d65c62001
commit 7458d278d8
10 changed files with 214 additions and 216 deletions

View file

@ -36,7 +36,7 @@ class CaptureAPI(View):
"bayer": fields.Boolean(
missing=False, description="Store raw bayer data in file"
),
"metadata": fields.Dict(missing={}, example={"Client": "SwaggerUI"}),
"annotations": fields.Dict(missing={}, example={"Client": "SwaggerUI"}),
"tags": fields.List(fields.String, missing=[], example=["docs"]),
"resize": fields.Dict(
missing=None, example={"width": 640, "height": 480}
@ -75,11 +75,10 @@ class CaptureAPI(View):
)
# Inject system metadata
output.put_metadata(microscope.metadata, system=True)
output.put_metadata({"instrument": microscope.metadata})
# Insert custom metadata
output.put_metadata(args.get("metadata"))
output.put_annotations(args.get("annotations"))
# Insert custom tags
output.put_tags(args.get("tags"))

View file

@ -39,10 +39,12 @@ class CaptureSchema(Schema):
"mimetype": "application/json",
**description_from_view(CaptureTags),
},
"metadata": {
"href": url_for(CaptureMetadata.endpoint, id=data.id, _external=True),
"annotations": {
"href": url_for(
CaptureAnnotations.endpoint, id=data.id, _external=True
),
"mimetype": "application/json",
**description_from_view(CaptureMetadata),
**description_from_view(CaptureAnnotations),
},
"download": {
"href": url_for(
@ -62,6 +64,9 @@ capture_schema = CaptureSchema()
capture_list_schema = CaptureSchema(many=True)
from pprint import pprint
@ThingProperty
@Tag("captures")
class CaptureList(View):
@ -197,10 +202,10 @@ class CaptureTags(View):
@Tag("captures")
class CaptureMetadata(View):
class CaptureAnnotations(View):
def get(self, id):
"""
Get metadata associated with a single image capture
Get annotations associated with a single image capture
"""
microscope = find_component("org.openflexure.microscope")
capture_obj = microscope.camera.image_from_id(id)
@ -208,7 +213,7 @@ class CaptureMetadata(View):
if not capture_obj:
return abort(404) # 404 Not Found
return jsonify(capture_obj.metadata)
return jsonify(capture_obj.annotations)
def put(self, id):
"""
@ -226,7 +231,6 @@ class CaptureMetadata(View):
if type(data_dict) != dict:
return abort(400)
# TODO: Allow putting system metadata maybe?
capture_obj.put_metadata(data_dict)
capture_obj.put_annotations(data_dict)
return jsonify(capture_obj.metadata)
return jsonify(capture_obj.annotations)

View file

@ -78,7 +78,7 @@ class StatusProperty(View):
Show current read-only state of the microscope
"""
microscope = find_component("org.openflexure.microscope")
return jsonify(microscope.status)
return jsonify(microscope.state)
@Tag("properties")
@ -92,7 +92,35 @@ class NestedStatusProperty(View):
keys = route.split("/")
try:
value = get_by_path(microscope.status, keys)
value = get_by_path(microscope.state, keys)
except KeyError:
return abort(404)
return jsonify(value)
@ThingProperty
class ConfigurationProperty(View):
def get(self):
"""
Show current read-only state of the microscope
"""
microscope = find_component("org.openflexure.microscope")
return jsonify(microscope.configuration)
@Tag("properties")
class NestedConfigurationProperty(View):
@doc_response(404, description="Configuration key cannot be found")
def get(self, route):
"""
Show a nested section of the current microscope state
"""
microscope = find_component("org.openflexure.microscope")
keys = route.split("/")
try:
value = get_by_path(microscope.configuration, keys)
except KeyError:
return abort(404)