Refactor store dwell alert management API and dwell engine

- Updated argument parsing in manage_api.py to include new threshold parameters.
- Enhanced _config_payload to include thresholds and webhook configurations.
- Modified _build_summary to track queue metrics and adjust alert reporting.
- Refactored DwellEngine to utilize queue thresholds for alerting and reporting.
- Added queue metrics calculations and status change tracking in dwell_engine.py.
- Updated notifier.py to support posting JSON events to webhooks.
- Adjusted example configuration to reflect new threshold parameters.
- Enhanced Docker entrypoint script for better process management.
- Updated tests to cover new queue metrics and thresholds.
- Improved ManagedServiceDetail and ManagedServices Vue components to display queue metrics.
This commit is contained in:
2026-05-09 11:35:55 +08:00
parent be5014c582
commit ea618fd674
26 changed files with 1605 additions and 117 deletions

View File

@@ -20,7 +20,9 @@ class CountingConfig:
line_mode: str = "normalized"
crossing_tolerance: float = 12.0
def to_pixel_line(self, width: int, height: int) -> tuple[float, float, float, float]:
def to_pixel_line(
self, width: int, height: int
) -> tuple[float, float, float, float]:
x1, y1, x2, y2 = self.line
if self.line_mode == "pixel":
return x1, y1, x2, y2
@@ -58,6 +60,33 @@ class RtspConfig:
output_subdir: str = "rtsp_stream"
@dataclass
class QueueConfig:
enabled: bool = True
area: tuple[float, float, float, float] = (0.0, 0.0, 1.0, 1.0)
area_mode: str = "normalized"
queue_time_threshold_seconds: int = 300
crowded_count_threshold: int = 5
normal_count_threshold: int = 2
pause_timeout_seconds: int = 5
source_id: str = "people_flow_queue"
def to_pixel_area(
self, width: int, height: int
) -> tuple[float, float, float, float]:
x1, y1, x2, y2 = self.area
if self.area_mode == "pixel":
return x1, y1, x2, y2
return x1 * width, y1 * height, x2 * width, y2 * height
@dataclass
class WebhookConfig:
url: str = ""
timeout_seconds: float = 5.0
event_log_path: str = "outputs/rtsp_stream/webhook_events.jsonl"
@dataclass
class RuntimeConfig:
rtsp_url: str = "rtsp://user:password@camera-ip:554/h264/ch1/main/av_stream"
@@ -71,6 +100,8 @@ class AppConfig:
attributes: AttributeConfig = field(default_factory=AttributeConfig)
output: OutputConfig = field(default_factory=OutputConfig)
rtsp: RtspConfig = field(default_factory=RtspConfig)
queue: QueueConfig = field(default_factory=QueueConfig)
webhook: WebhookConfig = field(default_factory=WebhookConfig)
runtime: RuntimeConfig = field(default_factory=RuntimeConfig)
config_path: Path | None = None