forked from Github/frigate
Sub label api score (#7113)
* Support setting sub label scores via API * Update docs * Update docs * Formatting * Throw error when score is outside expected bounds * Fix / cleanup
This commit is contained in:
@@ -370,10 +370,9 @@ def set_sub_label(id):
|
||||
jsonify({"success": False, "message": "Event " + id + " not found"}), 404
|
||||
)
|
||||
|
||||
if request.json:
|
||||
new_sub_label = request.json.get("subLabel")
|
||||
else:
|
||||
new_sub_label = None
|
||||
json: dict[str, any] = request.get_json(silent=True) or {}
|
||||
new_sub_label = json.get("subLabel")
|
||||
new_score = json.get("subLabelScore")
|
||||
|
||||
if new_sub_label and len(new_sub_label) > 100:
|
||||
return make_response(
|
||||
@@ -387,6 +386,18 @@ def set_sub_label(id):
|
||||
400,
|
||||
)
|
||||
|
||||
if new_score is not None and (new_score > 1.0 or new_score < 0):
|
||||
return make_response(
|
||||
jsonify(
|
||||
{
|
||||
"success": False,
|
||||
"message": new_score
|
||||
+ " does not fit within the expected bounds 0 <= score <= 1.0",
|
||||
}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
if not event.end_time:
|
||||
tracked_obj: TrackedObject = (
|
||||
current_app.detected_frames_processor.camera_states[
|
||||
@@ -395,9 +406,15 @@ def set_sub_label(id):
|
||||
)
|
||||
|
||||
if tracked_obj:
|
||||
tracked_obj.obj_data["sub_label"] = new_sub_label
|
||||
tracked_obj.obj_data["sub_label"] = (new_sub_label, new_score)
|
||||
|
||||
event.sub_label = new_sub_label
|
||||
|
||||
if new_score:
|
||||
data = event.data
|
||||
data["sub_label_score"] = new_score
|
||||
event.data = data
|
||||
|
||||
event.save()
|
||||
return make_response(
|
||||
jsonify(
|
||||
|
||||
Reference in New Issue
Block a user