How amanchauhan2005/purplee_hackathon works
Purpose and Runtime Topology
RetailIQ is a CPU-only, multi-camera retail analytics pipeline. It converts five CCTV streams into deduplicated visitor journeys and store KPIs, then serves live business telemetry and operational health views. Docker Compose runs a long-lived API service, a detector process, Prometheus, and Grafana. Core deployment files: docker-compose.yml, Dockerfile, run_all.py.
Detector Orchestration and Video Input
run_all.py launches one processing thread per camera. Each pipeline consumes bundled sample clips or mounted production files, preserving per-camera processing while coordinating through shared cross-camera identity state. Primary inputs are data/sample/CAM_1.mp4 through data/sample/CAM_5.mp4; the per-stream implementation is tracker/video_processor.py.
Vision, Tracking, and Identity Boundary
For each frame, the processor uses YOLOv8 person detection and ByteTrack-style local tracking, then passes track observations to cross-camera Re-ID. Re-ID performs spatial-temporal handoff plus HSV appearance comparison to assign a store-wide identity and prevent duplicated counts across overlapping feeds. Model assets and identity logic reside in tracker/yolov8n.pt, tracker/video_processor.py, and tracker/reid.py.
Spatial Semantics and Journey Events
Camera-local polygon zones classify tracked people into store locations. Zone transitions are converted into domain events such as entry, exit, dwell, staff, product engagement, and billing-related activity. This is the key boundary from CV observations to business semantics. Relevant paths: tracker/zone_config.py, tracker/zones_CAM_1.json, tracker/state_machine.py. Calibration/homography code exists in tracker/calibrate_homography.py and tracker/homography.py, but the operational design uses configured camera zones rather than a required shared floor-plane calibration.
Event Ingestion and In-Memory Store
The detector posts normalized events to the FastAPI service. api/main.py is the service entry point and owns event ingestion, the in-memory single source of truth, KPI derivation, WebSocket fan-out, and business endpoints including /metrics, /funnel, and /state. Supporting event and comparison concerns are separated in api/events.py, api/event_log.py, and api/compare.py. There is no persistence boundary: process memory is the authoritative current-store state.
Live Dashboard and Client Flow
The API serves a static browser dashboard that opens a WebSocket to receive live state/KPI updates. The dashboard is presentation-only; business metrics originate in the API’s state store rather than being recomputed client-side. Main client assets: dashboard/index.html, dashboard/app.js, dashboard/compare.html.
Operations and External Interfaces
FastAPI/Uvicorn exposes health, system/resource, Prometheus, REST, and WebSocket interfaces. Docker health checks gate detector startup on API readiness. Prometheus scrapes API metrics, while provisioned Grafana visualizes golden signals and alert rules detect latency, errors, CPU pressure, and stale ingestion. Infrastructure paths: docker-compose.yml, monitoring/prometheus.yml, monitoring/alerts.yml, monitoring/grafana/dashboards/retailiq-golden-signals.json.
Main entry points: main.py FastAPI service · docker-compose.yml Docker Compose · prometheus.yml Prometheus · run_all.py Multi-camera runner
Components 18
Detector pipeline
One processing thread runs per camera stream.
- Camera video streams · Five sample or mounted CCTV feeds.
data/sample/CAM_1.mp4 - Multi-camera runner · Launches one processing thread per camera.
run_all.py - Per-stream processor · Processes frames and submits normalized events.
tracker/video_processor.py - YOLO person detection
tracker/yolov8n.pt - Local track association · ByteTrack-style tracking within each camera.
tracker/video_processor.py - Cross-camera Re-ID · Uses handoff timing and HSV appearance to assign store-wide identities.
tracker/reid.py - Camera zone classification · Classifies tracks against configured polygon zones.
tracker/zone_config.py - Camera zone definitions
tracker/zones_CAM_1.json - Journey event state machine · Converts zone transitions into retail journey events.
tracker/state_machine.py
API and live state
FastAPI owns the authoritative in-memory store state.
- FastAPI service · Exposes ingestion, REST, health, metrics, and WebSocket interfaces.
api/main.py - Event normalization
api/events.py - In-memory store state · Current-store state has no persistence boundary.
api/event_log.py - KPI and comparison derivation · Derives live KPIs, funnels, state, and comparisons.
api/compare.py - Live browser dashboard · Presentation-only client receiving API updates.
dashboard/app.js
Observability
- Prometheus · Scrapes API metrics.
monitoring/prometheus.yml - Grafana dashboards · Displays golden signals and alerts.
monitoring/grafana/dashboards/retailiq-golden-signals.json - Alert rules · Detect latency, errors, CPU pressure, and stale ingestion.
monitoring/alerts.yml
Other components
- Docker Compose · Starts API, detector, Prometheus, and Grafana services.
docker-compose.yml
Connections 21
- Docker Compose → FastAPI service: runs
- Docker Compose → Multi-camera runner: runs after API health
- Docker Compose → Prometheus: runs
- Docker Compose → Grafana dashboards: runs
- Camera video streams → Multi-camera runner: camera feeds
- Multi-camera runner → Per-stream processor: one thread per camera
- YOLO person detection → Per-stream processor: detects people
- Per-stream processor → Local track association: detections
- Local track association → Cross-camera Re-ID: track observations
- Cross-camera Re-ID → Camera zone classification: store-wide identity
- Camera zone definitions → Camera zone classification: polygon zones
- Camera zone classification → Journey event state machine: zone transitions
- Journey event state machine → FastAPI service: normalized events
- FastAPI service → Event normalization: ingests
- Event normalization → In-memory store state: updates
- In-memory store state → KPI and comparison derivation: current state
- KPI and comparison derivation → FastAPI service: REST and live state
- FastAPI service → Live browser dashboard: serves static app and WebSocket updates
- FastAPI service → Prometheus: exposes /metrics
- Prometheus → Grafana dashboards: metrics
- Alert rules → Prometheus: evaluated by