Add published count for all labels in a zone

This commit is contained in:
Nick Mowen 2022-03-06 11:20:20 -07:00
parent 3e07d4eddb
commit 3f8278c6a6

View File

@ -894,6 +894,7 @@ class TrackedObjectProcessor(threading.Thread):
for label in set(self.zone_data[zone].keys()) | set(obj_counter.keys()): for label in set(self.zone_data[zone].keys()) | set(obj_counter.keys()):
# if we have previously published a count for this zone/label # if we have previously published a count for this zone/label
zone_label = self.zone_data[zone][label] zone_label = self.zone_data[zone][label]
all_labels_count = 0
if camera in zone_label: if camera in zone_label:
current_count = sum(zone_label.values()) current_count = sum(zone_label.values())
zone_label[camera] = ( zone_label[camera] = (
@ -906,6 +907,9 @@ class TrackedObjectProcessor(threading.Thread):
new_count, new_count,
retain=False, retain=False,
) )
# Set the count for the /zone/all topic.
all_labels_count += new_count
# if this is a new zone/label combo for this camera # if this is a new zone/label combo for this camera
else: else:
if label in obj_counter: if label in obj_counter:
@ -916,6 +920,18 @@ class TrackedObjectProcessor(threading.Thread):
retain=False, retain=False,
) )
# Set the count for the /zone/all topic.
all_labels_count += obj_counter[label]
# Publish count of all objects for this zone.
# TODO may need to check and only publish if
# value has changed from previous publish count??
self.client.publish(
f"{self.topic_prefix}/{zone}/all",
all_labels_count,
retain=False,
)
# cleanup event finished queue # cleanup event finished queue
while not self.event_processed_queue.empty(): while not self.event_processed_queue.empty():
event_id, camera = self.event_processed_queue.get() event_id, camera = self.event_processed_queue.get()