feat: 传递离岗时长到告警记录
- ResultReporter AlertInfo 添加 duration_minutes - main.py 使用 report_alert 替代 report_detection_alert - _store_alert 保存 duration_minutes
This commit is contained in:
@@ -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:
|
||||
|
||||
18
main.py
18
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"),
|
||||
|
||||
Reference in New Issue
Block a user