feat: Live Mall Occupancy Tracking, People Counting Analytics & Operator View Carousel #3
No reviewers
Labels
No labels
blocked
bug
enhancement
high-priority
low-priority
needs-info
needs-triage
ready-for-agent
ready-for-human
referenced
research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gabogg/hikcentral!3
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/people-counting-and-occupancy-tracking"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
This PR implements Live Mall Occupancy Tracking, People Counting Cameras Analytics, and the Operator View Horizontal Carousel.
Key Enhancements & Features
1. Operator View Horizontal Carousel & Auto-Scroll Navigation
deltaY > 20-> next slide,deltaY < -20-> previous slide) with a 450ms animation lock to prevent skipped slides from rapid mouse wheel flings.2. Statistical Mall Occupancy & Passenger Flow Engine
Estimated Occupancy = max(0, Total In - Total Out + Baseline Offset)
3. People Counting Analytics & Multi-Timespan View
Jornada Comercial,Hoy (24 Horas),Última Hora,Últimas 4 Horas,Últimas 12 Horas, andÚltimas 24 Horas.4. Admin Management Tab
5. Persistence & Automated Testing
occupancy_config,counting_cameras,people_counting_eventswith indexed timestamp queries.tests/test_occupancy.py(42/42 passing unit, integration, and RBAC tests).🚀 Feature Update & Scope Alignment (Commit
e8a5f18)Following the latest requirements review, the following enhancements, refactors, and precision metrics have been implemented and pushed to this PR branch:
1. 📐 Strict 2-Column Equal-Width (50% / 50%) Uniform Layout
grid grid-cols-2 gap-3).2. 🎯 Statistical Error Margins (
\pm E) Across All Telemetryerror_margin_percent(default 2.5%), dynamically calculating margins via:$$ ext{Margin} = \max\left(1, ext{round}\left( ext{Count} imes rac{ ext{error_margin_percent}}{100}
ight)
ight) \quad ( ext{0 if Count} = 0)
8,000 ±200 dentro12,450 ±3114,450 ±1113. 📅 Day-Specific Schedules & Dedicated Holiday Calendar
occupancy_daily_schedule.holiday_open_time&holiday_close_time, e.g. 10:00 - 18:00).YYYY-MM-DD), holiday name/description (e.g. Carnaval, Navidad), open/closed flags, and custom hour overrides.🟢 En Jornada (Lunes: 08:00 - 21:00)vs🌙 Fuera de Horario (Lunes: 08:00 - 21:00).🎉 Feriado: Navidad (Cerrado)or🎉 En Jornada (Feriado: Independencia 10:00 - 18:00).4. 🌐 Autonomous Local Tracking & Initial HikCentral Seeding
/artemis/api/aiapplication/v1/people/resourceGroupRealTimeCount) across 9 mall groups (CENTRAL SANTO TOME,PLAZA ALUMINIO,PLAZA MERU, etc.) to optionally seed initial baseline headcount.5. 🧹 Scope Refactoring: Complete Removal of Space Capacity Limits
6. 🧪 Verification & Test Suite Status
tests/test_occupancy.py: Day-specific schedule evaluation, holiday precedence, error margin math, camera heuristics, and RBAC endpoints.tests/test_api.py,tests/test_domain.py,tests/test_crypto.py,tests/test_concurrency.py,tests/test_resilience.py,tests/test_docs.py,tests/test_xss_sanitization.py.🛡️ Adversary & Codebase Design Review: Live Occupancy Tracking, People Counting & Operator Carousel
PR: #3 (feat/people-counting-and-occupancy-tracking)
Review Scope: Standards & Fowler Code Smells, Spec Alignment, Security & RBAC, Concurrency & SQLite WAL Performance, Mathematical Formulations, and Frontend Ergonomics.
Automated Test Suite Execution: 43 passed, 1 warning in 67.33s (100% pass rate).
📐 Standards & Architectural Seams
1. Seam Discipline & Module Depth (Score: A+)
OccupancyRepository(app/db/occupancy_repository.py): Cleanly encapsulates persistence across 5 relational tables (occupancy_config,occupancy_daily_schedule,occupancy_holidays,counting_cameras,people_counting_events) with SQLite WAL mode non-blocking async execution.OccupancyManager(app/services/occupancy_service.py): Deep module encapsulating calendar schedule resolution, holiday lookups, statistical tolerance error margins, 15-minute rolling flow rate computations, and camera heuristics.app/controllers/occupancy_controller.py): Strict HTTP transport adapter relying entirely on FastAPI Dependency Injection (Depends(get_occupancy_manager)).2. Smell Baseline Assessment
OccupancyLiveResponse,DayScheduleItem,TimespanPreset,flow_rate_per_min,error_margin_percent).str, Enum(TimespanPreset,DirectionType).OccupancyManager, while persistence mechanics reside inOccupancyRepository.🎯 Spec Alignment & Feature Verification
max(0, Total In - Total Out + Baseline Offset)with dynamic tolerance calculation (±round(count * margin_pct / 100)).flow_rate_per_min = round(net_15m / 15.0, 2)).Jornada Comercial,Hoy,Última Hora,4H,12H,24H) with ranked top ingress/egress percentage bars.🚨 Security, Concurrency & Edge-Case Analysis
POST /config,POST /schedule,POST /holidays,POST /reset,POST /sync-cameras,POST /simulate-traffic) strictly requirerequire_admin.GET /live,GET /overview,GET /cameras) allow operator credentials (require_auth).escapeHtml()is rigorously applied across all dynamically rendered elements inapp/static/js/app.js(camera_name,zone_name,day_name,holiday_date,holiday_name, time strings).idx_counting_events_epochandidx_counting_events_camguarantee O(log N) aggregation performance over large event logs.webhook_controller.py:L39-45, when event type131588carries bothenterNum > 0andexitNum > 0, it triggers two sequentialrecord_counting_event_asynccalls and two WebSocket broadcasts. This is functionally accurate, but combining them into a batch or single broadcast can be considered under very high webhook frequencies.🏁 Recommendation
Verdict: APPROVE (Ready to Merge)
The implementation conforms to all architectural standards, respects domain boundaries, provides robust security safeguards, and passes all 43 automated unit, integration, and RBAC tests.
🔄 Continuous Ingestion & Dedicated Counting Discovery Update (Commits
6ebf4e8->8c80dac)This update details the backend telemetry synchronization pipeline, test isolation architecture, and genuine passenger flow group discovery:
1. 🎯 Precision Discovery of 14 Dedicated Passenger Flow Cameras
/artemis/api/resource/v1/cameras), bringing in all 113 surveillance units.sync_cameras_from_artemis_asyncto directly query HikCentral's Passenger Flow Resource Groups (/artemis/api/aiapplication/v1/people/advance/resourceGroupList), extracting the 14 genuine passenger flow counting cameras mapped to their 9 official mall zones:[1930] SALIDA CENTRAL SANTO TOME 3,[1936] ENTRADA CONTADORA[589] P ALUMINIO AV GUAYANA,[804] P ALUMINIO AV AMERICA[765] P. DE MERU AV GUAYANA,[771] P. DE MERU AV AMERICA[750] P. ACERO AV AMERICA,[810] PLAZA ACERO AV GUAYANA[756] P. SANTO TOME IV C. CHURUM MERU,[793] P. SANTO TOME IV AV GUAYNA[777] P. ORINOCO AV GUAYANA[787] P. CARONI AV GUAYANA[1622] LOBBY TITANIO[1781] MYKONOS2. ⚡ Continuous Background Ingestion Engine & Delta Tracking
background_monitor()queriesPOST /artemis/api/aiapplication/v1/people/resourceGroupRealTimeCountevery 3 seconds.people_counting_events.occupancy_updatewith full metrics over WebSocket.3. 🧪 Isolated Test Fixture Architecture (
tests/conftest.py)test_hikcentral.db).data/hikcentral.db).4. 📊 Current Live Telemetry Status
1,251 ±31 dentro2,006 ±50755 ±19+1,251🚫 Counting Camera Exclusion Capability Added (Commit
8c0ad29)Operators and administrators can now selectively exclude individual people-counting cameras (e.g., due to miscalibration, physical relocation, or hardware issues), mirroring the existing door exclusion system:
1. 🎛️ User Interface & Controls
Activa(emerald) vsExcluida(rose with strikethrough).[Excluir]/[Incluir]) to instantly toggle exclusion.2. 🧮 Mathematical & Aggregation Integrity
3. 🔒 API & Automated Test Coverage
POST /api/occupancy/cameras/excludewith payload{"camera_index_code": "...", "exclude": true/false}(Admin RBAC enforced).test_camera_exclusion_workflowandtest_camera_exclusion_api_rbacintests/test_occupancy.py.🚀 Passenger Flow Architecture, Ingestion Engine & Camera Management Update
This update details the technical architecture, data flow, telemetry ingestion mechanics, and camera exclusion capabilities for the People Counting and Occupancy Tracking module.
1. 🏗️ Telemetry Ingestion & Synchronization Flow
2. 🧮 Mathematical & Aggregation Formulations
Estimated Facility Occupancy:
Non-Linear Optical Error Margin:
15-Minute Instantaneous Flow Rate:
3. 🛡️ Resource Group Topology & Best Practices
4. 🧪 Automated Testing & Diagnostics
🛡️ Two-Axis Code Review: Live Mall Occupancy, Passenger Flow & Operator Carousel
PR: #3 (feat/people-counting-and-occupancy-tracking)
Fixed Point:
master(80846d3) ...HEAD(2f40c11)Commits: 12 commits (
ce0ff5d...2f40c11)Automated Test Suite: 45 passed, 1 warning in 24.53s (100% green).
📐 Standards
1. Documented Repo Standards Compliance
app/controllers/occupancy_controller.pyapp/services/occupancy_service.pyapp/db/occupancy_repository.py/config,/schedule,/holidays,/reset,/cameras/exclude,/sync-cameras,/simulate-traffic) enforcerequire_admin.escapeHtml()is strictly applied across all interpolated DOM strings inapp.js.aiosqlitewith SQLite WAL mode without blocking the FastAPI event loop.2. Fowler Smell Baseline Assessment
CountingCameraItem,OccupancyLiveResponse,DayScheduleItem,TimespanPreset).TimespanPreset) and camera directions (DirectionType).OccupancyManager, while persistence mechanics reside inOccupancyRepository.🎯 Spec
1. Feature & Requirement Verification
max(0, Total In - Total Out + Baseline Offset)with dynamic optical error margins (\pm ext{Margin}\%) calculated accurately./artemis/api/aiapplication/v1/people/resourceGroupRealTimeCount) polling every 3s with monotonic delta safety and real-time WebSocket broadcast.tests/conftest.py, preventing test state pollution.check_hikcentral_live.py).2. Scope Creep & Implementation Errors
🏁 Summary & Verdict
🔄 Live Zone Renaming & Camera Inventory Dynamic Synchronization (Commit
39aa8be)This update dynamically synchronizes HikCentral Passenger Flow Resource Group changes and zone renamings into the local database and UI:
Automatic Upstream Zone Synchronization:
GAMA 2,GAMA 6,GAMA 8,GAMA 10,GAMA 10.5,GAMA 12,GAMA 15,GAMA 16,LOBBY TITANIO,MYKONOS,PLAZA CARONI,PLAZA ORINOCO) are immediately applied to active cameras.Obsolete Camera Deactivation:
is_active = 0) and omitted from active camera lists and ranking cards.Data & Exclusion State Preservation:
today_in,today_out) and exclusion flags (is_excluded).