Spaces:
Sleeping
Sleeping
Deploy Store Intelligence API + dashboard with multi-store config, camera visuals audit, event pipeline exits, and WebSocket isolation fix
78d4e18 |
Download DESIGN.md from SandeepChakka/store-intelligence: direct link, hf CLI and curl.
- Browser
- Download file 4.55 kB
-
https://huggingface.co/spaces/SandeepChakka/store-intelligence/resolve/main/DESIGN.md
- Command line
-
hf download hf://spaces/SandeepChakka/store-intelligence/DESIGN.md
-
curl -L -o DESIGN.md https://huggingface.co/spaces/SandeepChakka/store-intelligence/resolve/main/DESIGN.md
4.55 kB
DESIGN — Store Intelligence System
This document describes the architectural specifications, event semantics, and design choices of the Store Intelligence System.
Architecture Overview
The system is designed to process multiple retail stores dynamically. No store IDs, camera mappings, or layout coordinate polygons are hardcoded in the codebase. All details are discovered and loaded from store-specific configuration files.
CCTV Footage (Store 1, Store 2 sibling folders)
→ discover_all.py → configs/generated/{store_id}/camera_profile.json
configs/generated/{store_id}/store_layout.json
→ run_pipeline.py --store-id {store_id} (YOLOv8n + ByteTrack + Re-ID)
→ data/events/{store_id}/output.jsonl
→ uvicorn bootstrap → Ingest output.jsonl + POS transactions
→ GET API & WebSocket endpoints (metrics, funnel, heatmap, anomalies)
→ React dashboard (with multi-store dropdown selector)
Data-Driven Configuration Model
All settings and configurations are grouped by store ID inside configs/generated/{store_id}/:
camera_profile.json: Lists available camera feeds, roles (entry,billing,main_floor), resolution, fps, and reasoning.store_layout.json: Outlines store metadata, open hours, active zones, camera-to-zone mappings, and normalized coordinate ROIs (role_polygons) per camera role.pos_transactions_derived.csv: Contains aggregated sales transactions used to calculate conversion rates.
Structured Event Stream
The pipeline processes each camera feed and produces an event stream matching the canonical schema.
Event Catalogue
ENTRY: Emitted when a visitor crosses the entrance threshold in the inbound direction. Starts a session.EXIT: Emitted when a visitor crosses the entrance threshold in the outbound direction. Closes the active session.ZONE_ENTER: Emitted when a visitor enters a zone polygon.ZONE_EXIT: Emitted when a visitor leaves a zone polygon (either by entering another zone, moving to an unmonitored space, or exiting the store).ZONE_DWELL: Emitted periodically every 30 seconds of continuous dwell time in a zone.BILLING_QUEUE_JOIN: Emitted when a visitor enters the cash counter queue (while queue depth > 0).BILLING_QUEUE_ABANDON: Emitted when a visitor exits the cash counter queue area without checking out. If they subsequently complete a purchase, this abandonment is pruned by the backend during POS correlation.REENTRY: Emitted when a previously seen visitor returns to the store after a prior exit.
Session Lifecycle and Re-Entry Handling
Visitor session boundaries are managed statefully in the database:
- Session Reopening: If a visitor leaves and re-enters, the pipeline emits a
REENTRYevent. The ingestion layer intercepts this event and re-opens their most recent session (by clearingended_at) instead of spawning a new session. This prevents inflating unique visitor counts and ensures the funnel accurately reports conversion. - Staff Exclusion: Staff tracks are identified via high persistence across multiple clips and high speed movement. They are flagged as
is_staff=Trueand filtered out of all customer metrics.
Database Schema (SQLite)
events: Ingested raw event stream (deduplicated byevent_idusingON CONFLICT DO NOTHING).sessions: visitor sessions containing start/end timestamps, zone visit flags, and conversion status.transactions: POS sales invoices correlated by time-window + store ID.anomalies: Operational anomalies (e.g.BILLING_QUEUE_SPIKE,CONVERSION_DROP,DEAD_ZONE,STALE_FEED).
AI-Assisted Design Decisions
- Camera Billing Heuristic Override: Heuristics based on edge density misclassified Store 1's
CAM 5as main_floor. An explicit visual override map was introduced to correctly classifyCAM 5asBILLING_CAMERAandCAM 2asMAIN_FLOOR_CAMERA. - Schema Adapter/Normalizer: The ingestion layer includes a dynamic adaptor that parses legacy schemas (such as
sample_eventsbe42122.jsonlwithid_tokenandevent_timestamp) on the fly, transforming them intoStoreEventrecords during ingestion. - Queue Abandonment Deletion: Since the pipeline cannot inspect POS records offline, it emits a
BILLING_QUEUE_ABANDONcandidate when a track exits the checkout queue. The backend deletes this event if POS correlation matches a transaction within the conversion window.