From 29d3ea0bc483272cbf09fc80b09f8133358cd12d Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Fri, 30 Jan 2026 17:27:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=A0=E9=80=92=E7=A6=BB=E5=B2=97?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E5=88=B0=E5=91=8A=E8=AD=A6=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ResultReporter AlertInfo 添加 duration_minutes - main.py 使用 report_alert 替代 report_detection_alert - _store_alert 保存 duration_minutes --- core/result_reporter.py | 3 +++ main.py | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/result_reporter.py b/core/result_reporter.py index 210b7e0..d28ba72 100644 --- a/core/result_reporter.py +++ b/core/result_reporter.py @@ -37,6 +37,7 @@ class AlertInfo: message: Optional[str] = None screenshot: Optional[np.ndarray] = None timestamp: datetime = field(default_factory=datetime.now) + duration_minutes: Optional[float] = None def to_dict(self) -> Dict[str, Any]: """转换为字典""" @@ -50,6 +51,7 @@ class AlertInfo: "bbox": self.bbox, "message": self.message, "timestamp": self.timestamp.isoformat(), + "duration_minutes": self.duration_minutes, } @@ -211,6 +213,7 @@ class ResultReporter: image_path=image_path, status="pending", created_at=alert.timestamp, + duration_minutes=alert.duration_minutes, ) if self._db_manager: diff --git a/main.py b/main.py index 7b31491..b285049 100644 --- a/main.py +++ b/main.py @@ -311,18 +311,20 @@ class EdgeInferenceService: for alert in alerts: self._performance_stats["total_alerts_generated"] += 1 - self._reporter.report_detection_alert( + from core.result_reporter import AlertInfo + alert_info = AlertInfo( + alert_id=f"{roi_id}_{int(frame.timestamp.timestamp())}", camera_id=camera_id, roi_id=roi_id, alert_type=alert.get("alert_type", "detection"), - detection={ - "class_name": alert.get("message", "未知目标"), - "confidence": alert.get("confidence", 1.0), - "bbox": alert.get("bbox", []), - "message": alert.get("message", ""), - }, - screenshot=frame.image + target_class=alert.get("class", "unknown"), + confidence=alert.get("confidence", 1.0), + bbox=alert.get("bbox", []), + message=alert.get("message", ""), + timestamp=frame.timestamp, + duration_minutes=alert.get("duration_minutes"), ) + self._reporter.report_alert(alert_info, screenshot=frame.image) self._logger.log_alert( alert.get("alert_type", "detection"),