mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 02:35:22 +03:00
Move tracked object logic to own function
This commit is contained in:
parent
f295305a06
commit
f23d133387
@ -3,7 +3,10 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from peewee import fn
|
from peewee import fn
|
||||||
|
|
||||||
@ -58,35 +61,11 @@ class EventProcessor(threading.Thread):
|
|||||||
self.events_in_process: Dict[str, Event] = {}
|
self.events_in_process: Dict[str, Event] = {}
|
||||||
self.stop_event = stop_event
|
self.stop_event = stop_event
|
||||||
|
|
||||||
def run(self) -> None:
|
def handle_object_detection(
|
||||||
# set an end_time on events without an end_time on startup
|
self, event_type: str, camera: str, event_data: dict[str, Any]
|
||||||
Event.update(end_time=Event.start_time + 30).where(
|
) -> None:
|
||||||
Event.end_time == None
|
"""handle tracked object event updates."""
|
||||||
).execute()
|
|
||||||
|
|
||||||
while not self.stop_event.is_set():
|
|
||||||
try:
|
|
||||||
event_type, camera, event_data = self.event_queue.get(timeout=1)
|
|
||||||
except queue.Empty:
|
|
||||||
continue
|
|
||||||
|
|
||||||
logger.debug(f"Event received: {event_type} {camera} {event_data['id']}")
|
|
||||||
|
|
||||||
self.timeline_queue.put(
|
|
||||||
(
|
|
||||||
camera,
|
|
||||||
TimelineSourceEnum.tracked_object,
|
|
||||||
event_type,
|
|
||||||
self.events_in_process.get(event_data["id"]),
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# if this is the first message, just store it and continue, its not time to insert it in the db
|
# if this is the first message, just store it and continue, its not time to insert it in the db
|
||||||
if event_type == "start":
|
|
||||||
self.events_in_process[event_data["id"]] = event_data
|
|
||||||
continue
|
|
||||||
|
|
||||||
if should_update_db(self.events_in_process[event_data["id"]], event_data):
|
if should_update_db(self.events_in_process[event_data["id"]], event_data):
|
||||||
camera_config = self.config.cameras[camera]
|
camera_config = self.config.cameras[camera]
|
||||||
event_config: EventsConfig = camera_config.record.events
|
event_config: EventsConfig = camera_config.record.events
|
||||||
@ -155,7 +134,7 @@ class EventProcessor(threading.Thread):
|
|||||||
"region": region,
|
"region": region,
|
||||||
"score": score,
|
"score": score,
|
||||||
"top_score": event_data["top_score"],
|
"top_score": event_data["top_score"],
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -174,6 +153,39 @@ class EventProcessor(threading.Thread):
|
|||||||
del self.events_in_process[event_data["id"]]
|
del self.events_in_process[event_data["id"]]
|
||||||
self.event_processed_queue.put((event_data["id"], camera))
|
self.event_processed_queue.put((event_data["id"], camera))
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
# set an end_time on events without an end_time on startup
|
||||||
|
Event.update(end_time=Event.start_time + 30).where(
|
||||||
|
Event.end_time == None
|
||||||
|
).execute()
|
||||||
|
|
||||||
|
while not self.stop_event.is_set():
|
||||||
|
try:
|
||||||
|
source_type, event_type, camera, event_data = self.event_queue.get(
|
||||||
|
timeout=1
|
||||||
|
)
|
||||||
|
except queue.Empty:
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.debug(f"Event received: {event_type} {camera} {event_data['id']}")
|
||||||
|
|
||||||
|
self.timeline_queue.put(
|
||||||
|
(
|
||||||
|
camera,
|
||||||
|
source_type,
|
||||||
|
event_type,
|
||||||
|
self.events_in_process.get(event_data["id"]),
|
||||||
|
event_data,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if source_type == TimelineSourceEnum.tracked_object:
|
||||||
|
if event_type == "start":
|
||||||
|
self.events_in_process[event_data["id"]] = event_data
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.handle_object_detection(event_type, camera, event_data)
|
||||||
|
|
||||||
# set an end_time on events without an end_time before exiting
|
# set an end_time on events without an end_time before exiting
|
||||||
Event.update(end_time=datetime.datetime.now().timestamp()).where(
|
Event.update(end_time=datetime.datetime.now().timestamp()).where(
|
||||||
Event.end_time == None
|
Event.end_time == None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user