- 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.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from datetime import datetime
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from src.people_flow.models import QueueConfig, TrackObservation
|
|
from src.people_flow.queue_analytics import QueueWindowTracker
|
|
|
|
TZ = ZoneInfo("Asia/Shanghai")
|
|
|
|
|
|
def test_queue_window_tracker_builds_crowded_report():
|
|
tracker = QueueWindowTracker(
|
|
QueueConfig(
|
|
queue_time_threshold_seconds=300,
|
|
crowded_count_threshold=5,
|
|
normal_count_threshold=2,
|
|
pause_timeout_seconds=5,
|
|
),
|
|
pixel_area=(0, 0, 100, 100),
|
|
)
|
|
start = datetime(2026, 4, 15, 11, 0, tzinfo=TZ)
|
|
crowded_tracks = [
|
|
TrackObservation(
|
|
track_id=index, bbox=(0, 0, 10, 10), confidence=0.9, center=(10, 10)
|
|
)
|
|
for index in range(1, 7)
|
|
]
|
|
short_tracks = [
|
|
TrackObservation(
|
|
track_id=index, bbox=(0, 0, 10, 10), confidence=0.9, center=(10, 10)
|
|
)
|
|
for index in range(7, 9)
|
|
]
|
|
|
|
tracker.observe(crowded_tracks, start)
|
|
tracker.observe(crowded_tracks, start.replace(minute=6))
|
|
tracker.observe(crowded_tracks + short_tracks, start.replace(minute=27))
|
|
tracker.observe(short_tracks, start.replace(minute=30))
|
|
|
|
queue_metrics = tracker.build_queue_metrics(start, start.replace(minute=30))
|
|
|
|
assert queue_metrics["over_threshold_count"] == 6
|
|
assert queue_metrics["under_threshold_count"] == 2
|
|
assert queue_metrics["queue_level"] == "crowded"
|