Cleanup event metadata updater

This commit is contained in:
Nicolas Mowen 2025-06-06 08:42:09 -06:00
parent d6f2d55525
commit 87efebde19
8 changed files with 19 additions and 19 deletions

View File

@ -1094,7 +1094,7 @@ def set_sub_label(
new_score = None
request.app.event_metadata_updater.publish(
EventMetadataTypeEnum.sub_label, (event_id, new_sub_label, new_score)
(event_id, new_sub_label, new_score), EventMetadataTypeEnum.sub_label.value
)
return JSONResponse(
@ -1148,8 +1148,8 @@ def set_plate(
new_score = None
request.app.event_metadata_updater.publish(
EventMetadataTypeEnum.attribute,
(event_id, "recognized_license_plate", new_plate, new_score),
EventMetadataTypeEnum.attribute,
)
return JSONResponse(
@ -1232,8 +1232,8 @@ def regenerate_description(
if camera_config.genai.enabled or params.force:
request.app.event_metadata_updater.publish(
EventMetadataTypeEnum.regenerate_description,
(event.id, params.source, params.force),
EventMetadataTypeEnum.regenerate_description.value,
)
return JSONResponse(
@ -1390,7 +1390,6 @@ def create_event(
event_id = f"{now}-{rand_id}"
request.app.event_metadata_updater.publish(
EventMetadataTypeEnum.manual_event_create,
(
now,
camera_name,
@ -1403,6 +1402,7 @@ def create_event(
body.source_type,
body.draw,
),
EventMetadataTypeEnum.manual_event_create.value,
)
return JSONResponse(
@ -1426,7 +1426,7 @@ def end_event(request: Request, event_id: str, body: EventsEndBody):
try:
end_time = body.end_time or datetime.datetime.now().timestamp()
request.app.event_metadata_updater.publish(
EventMetadataTypeEnum.manual_event_end, (event_id, end_time)
(event_id, end_time), EventMetadataTypeEnum.manual_event_end.value
)
except Exception:
return JSONResponse(

View File

@ -28,8 +28,8 @@ class EventMetadataPublisher(Publisher):
def __init__(self) -> None:
super().__init__()
def publish(self, topic: EventMetadataTypeEnum, payload: Any) -> None:
super().publish(payload, topic.value)
def publish(self, payload: Any, sub_topic: str) -> None:
super().publish(payload, sub_topic)
class EventMetadataSubscriber(Subscriber):

View File

@ -1170,7 +1170,6 @@ class LicensePlateProcessingMixin:
event_id = f"{now}-{rand_id}"
self.event_metadata_publisher.publish(
EventMetadataTypeEnum.lpr_event_create,
(
now,
camera,
@ -1181,6 +1180,7 @@ class LicensePlateProcessingMixin:
None,
plate,
),
EventMetadataTypeEnum.lpr_event_create.value,
)
return event_id
@ -1518,7 +1518,7 @@ class LicensePlateProcessingMixin:
# If it's a known plate, publish to sub_label
if sub_label is not None:
self.sub_label_publisher.publish(
EventMetadataTypeEnum.sub_label, (id, sub_label, avg_confidence)
(id, sub_label, avg_confidence), EventMetadataTypeEnum.sub_label.value
)
# always publish to recognized_license_plate field
@ -1537,8 +1537,8 @@ class LicensePlateProcessingMixin:
),
)
self.sub_label_publisher.publish(
EventMetadataTypeEnum.attribute,
(id, "recognized_license_plate", top_plate, avg_confidence),
EventMetadataTypeEnum.attribute,
)
# save the best snapshot for dedicated lpr cams not using frigate+
@ -1552,8 +1552,8 @@ class LicensePlateProcessingMixin:
frame_bgr = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
_, encoded_img = cv2.imencode(".jpg", frame_bgr)
self.sub_label_publisher.publish(
EventMetadataTypeEnum.save_lpr_snapshot,
(base64.b64encode(encoded_img).decode("ASCII"), id, camera),
EventMetadataTypeEnum.save_lpr_snapshot.value,
)
if id not in self.detected_license_plates:

View File

@ -147,8 +147,8 @@ class BirdRealTimeProcessor(RealTimeProcessorApi):
return
self.sub_label_publisher.publish(
EventMetadataTypeEnum.sub_label,
(obj_data["id"], self.labelmap[best_id], score),
EventMetadataTypeEnum.sub_label.value,
)
self.detected_birds[obj_data["id"]] = score

View File

@ -294,16 +294,16 @@ class CustomObjectClassificationProcessor(RealTimeProcessorApi):
):
if sub_label != "none":
self.sub_label_publisher.publish(
EventMetadataTypeEnum.sub_label,
(obj_data["id"], sub_label, score),
EventMetadataTypeEnum.sub_label,
)
elif (
self.model_config.object_config.classification_type
== ObjectClassificationType.attribute
):
self.sub_label_publisher.publish(
EventMetadataTypeEnum.attribute,
(obj_data["id"], self.model_config.name, sub_label, score),
EventMetadataTypeEnum.attribute,
)
def handle_request(self, topic, request_data):

View File

@ -321,8 +321,8 @@ class FaceRealTimeProcessor(RealTimeProcessorApi):
if weighted_score >= self.face_config.recognition_threshold:
self.sub_label_publisher.publish(
EventMetadataTypeEnum.sub_label,
(id, weighted_sub_label, weighted_score),
EventMetadataTypeEnum.sub_label.value,
)
self.__update_metrics(datetime.datetime.now().timestamp() - start)

View File

@ -500,8 +500,8 @@ class EmbeddingMaintainer(threading.Thread):
to_remove.append(id)
for id in to_remove:
self.event_metadata_publisher.publish(
EventMetadataTypeEnum.manual_event_end,
(id, now),
EventMetadataTypeEnum.manual_event_end.value,
)
self.detected_license_plates.pop(id)

View File

@ -293,7 +293,6 @@ class AudioEventMaintainer(threading.Thread):
self.requestor.send_data(f"{self.camera_config.name}/audio/{label}", "ON")
self.event_metadata_publisher.publish(
EventMetadataTypeEnum.manual_event_create,
(
now,
self.camera_config.name,
@ -306,6 +305,7 @@ class AudioEventMaintainer(threading.Thread):
"audio",
{},
),
EventMetadataTypeEnum.manual_event_create.value,
)
self.detections[label] = {
"id": event_id,
@ -329,8 +329,8 @@ class AudioEventMaintainer(threading.Thread):
)
self.event_metadata_publisher.publish(
EventMetadataTypeEnum.manual_event_end,
(detection["id"], detection["last_detection"]),
EventMetadataTypeEnum.manual_event_end.value,
)
self.detections[detection["label"]] = None
@ -343,8 +343,8 @@ class AudioEventMaintainer(threading.Thread):
f"{self.camera_config.name}/audio/{label}", "OFF"
)
self.event_metadata_publisher.publish(
EventMetadataTypeEnum.manual_event_end,
(detection["id"], now),
EventMetadataTypeEnum.manual_event_end.value,
)
self.detections[label] = None