feat(analytics): per-entrance breakdown for a statistics period #86

Closed
opened 2026-09-24 23:23:41 +00:00 by gabogg · 1 comment
Owner

Route

GET /api/statistics/periods/{granularity}/{start}/entrances

One row per counted camera: visitors (IN), OUT, share of period visitors, and change vs the previous period; change vs the same period last year is added only when last year has data.

Used by

Entrance share graphs in all three periods.

Notes

  • Per-camera figures for a multi-camera group are estimates (ADR 0005, Camera Group States); the response must say so.
  • Cameras added or removed within the comparison window need a defined rule (compare only cameras present in both periods, or flag new ones).

Context

Part of the statistics deck redesign, draft RFC in #80 (docs/architecture/rfc-statistics-deck-display-model.md; mockup linked there). Period selection was decided in #81 (closed): a period is identified by granularity (day / week / month) and its first business day; see the glossary terms Complete Period and Partial Period. A year period is out of scope.

Shared constraints (all statistics-deck routes)

  • Periods are closed business periods in facility time (daily_reset_time boundaries, app/facility_time.py); an in-progress cycle is never returned.
  • Only counted cameras contribute (_COUNTED_CAMERA_JOIN / _COUNTED_CAMERA_FILTER); quarantined events never do.
  • Every period-level figure carries its data quality: gap-estimated days (ingestion anomaly ledger), Data Trust and Cycle Completeness for the cycles involved, so the deck can mark estimates.
  • Dwell means the open-window Mean Dwell (ADR 0006), not the retired definitions.
  • Access: any logged-in user, read-only (require_auth). Deck routes live in a separate /api/statistics/ router so admin-only /api/analytics/ routes can't leak into the deck.
  • Controllers stay thin; aggregation lives in analytics_service, SQL in repositories.

Triage decisions (2026-09-24)

  • Route: GET /api/statistics/periods/{granularity}/{start}/entrances.
  • Share always uses every counted camera in the current period.
  • Change figures only for cameras present in both periods; a camera new in this period is marked NEW with no change; a camera that disappeared is not listed.
## Route `GET /api/statistics/periods/{granularity}/{start}/entrances` One row per counted camera: visitors (IN), OUT, share of period visitors, and change vs the previous period; change vs the same period last year is added only when last year has data. ## Used by Entrance share graphs in all three periods. ## Notes - Per-camera figures for a multi-camera group are estimates (ADR 0005, Camera Group States); the response must say so. - Cameras added or removed within the comparison window need a defined rule (compare only cameras present in both periods, or flag new ones). ## Context Part of the statistics deck redesign, draft RFC in #80 (`docs/architecture/rfc-statistics-deck-display-model.md`; mockup linked there). Period selection was decided in #81 (closed): a period is identified by `granularity` (`day` / `week` / `month`) and its first business day; see the glossary terms **Complete Period** and **Partial Period**. A year period is out of scope. ## Shared constraints (all statistics-deck routes) - Periods are **closed** business periods in facility time (`daily_reset_time` boundaries, `app/facility_time.py`); an in-progress cycle is never returned. - Only **counted cameras** contribute (`_COUNTED_CAMERA_JOIN` / `_COUNTED_CAMERA_FILTER`); quarantined events never do. - Every period-level figure carries its data quality: gap-estimated days (ingestion anomaly ledger), **Data Trust** and **Cycle Completeness** for the cycles involved, so the deck can mark estimates. - Dwell means the open-window **Mean Dwell** (ADR 0006), not the retired definitions. - Access: any logged-in user, read-only (`require_auth`). Deck routes live in a separate `/api/statistics/` router so admin-only `/api/analytics/` routes can't leak into the deck. - Controllers stay thin; aggregation lives in `analytics_service`, SQL in repositories. ## Triage decisions (2026-09-24) - Route: `GET /api/statistics/periods/{granularity}/{start}/entrances`. - Share always uses every counted camera in the current period. - Change figures only for cameras present in both periods; a camera new in this period is marked `NEW` with no change; a camera that disappeared is not listed.
Author
Owner

Implemented by #92, merged into master as cf20ef2 after two review passes (Standards + Spec). Non-blocking follow-ups are tracked in #96–#100. Closing; this unblocks #80.

🤖 Generated with Claude Code

Implemented by #92, merged into `master` as cf20ef2 after two review passes (Standards + Spec). Non-blocking follow-ups are tracked in #96–#100. Closing; this unblocks #80. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gabogg/hikcentral#86
No description provided.