what
This commit is contained in:
1 parent
4201a3cbb1
commit
0cd543a21a
10 files changed
+1457
-256
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""Sinks for pipeline output handling."""
|
||||
|
||||
from pipeline.sinks.alerts import FileAlertStore
|
||||
from pipeline.sinks.database import DatabaseSink
|
||||
from pipeline.sinks.database import DatabaseSink, DatabaseSmartEventSink
|
||||
from pipeline.sinks.display import WindowDisplaySink
|
||||
from pipeline.sinks.events import SmartEventSink
|
||||
from pipeline.sinks.metrics import MetricsSink
|
||||
@@ -10,6 +10,7 @@ from pipeline.sinks.video import VideoFileStore
|
||||
|
||||
__all__ = [
|
||||
"DatabaseSink",
|
||||
"DatabaseSmartEventSink",
|
||||
"FileAlertStore",
|
||||
"MetricsSink",
|
||||
"ScreenshotSink",
|
||||
|
||||
@@ -8,6 +8,7 @@ import cv2
|
||||
|
||||
from db.repository import Repository
|
||||
from pipeline.ops.drawing import draw_alert_banner, draw_detections
|
||||
from pipeline.sinks.events import SmartEventSink
|
||||
from pipeline.types import Frame
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -72,3 +73,52 @@ class DatabaseSink:
|
||||
|
||||
def close(self):
|
||||
pass # DB connection is managed by the repository
|
||||
|
||||
|
||||
class DatabaseSmartEventSink(SmartEventSink):
|
||||
"""Records event clips and stores clip path in DB as alert evidence."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
db_repo: Repository,
|
||||
fps: float,
|
||||
user_id: int = 1,
|
||||
camera_source: str = "Pipeline",
|
||||
output_dir: str = "static/events",
|
||||
pre_event_seconds: float = 2,
|
||||
post_event_seconds: float = 3,
|
||||
):
|
||||
super().__init__(
|
||||
output_dir=output_dir,
|
||||
fps=fps,
|
||||
pre_event_seconds=pre_event_seconds,
|
||||
post_event_seconds=post_event_seconds,
|
||||
)
|
||||
self.db_repo = db_repo
|
||||
self.user_id = user_id
|
||||
self.camera_source = camera_source
|
||||
|
||||
def _trigger_event(self, trigger_frame: Frame):
|
||||
was_recording = self.recording
|
||||
super()._trigger_event(trigger_frame)
|
||||
|
||||
# Save one DB row per newly started event clip
|
||||
if was_recording or not self.recording or self.current_event_id is None:
|
||||
return
|
||||
|
||||
ticket = trigger_frame.ticket
|
||||
if not ticket:
|
||||
return
|
||||
|
||||
filename = f"event_{self.current_event_id}.mp4"
|
||||
web_path = f"/static/events/{filename}"
|
||||
try:
|
||||
self.db_repo.save_detection(
|
||||
user_id=self.user_id,
|
||||
image_path=web_path,
|
||||
confidence=ticket.confidence,
|
||||
camera_source=self.camera_source,
|
||||
)
|
||||
logger.info("Saved event alert to DB: %s", web_path)
|
||||
except Exception as e:
|
||||
logger.error("Failed to save event alert to DB: %s", e)
|
||||
Reference in new issue
Block a user