feat(analytics): list selectable statistics periods #82

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

Route

GET /api/statistics/periods?granularity=day|week|month&limit=…

Returns the closed periods a presenter can pick, newest first, for the deck's period selector.

Response sketch

[{"granularity": "week", "start": "2026-09-14", "end": "2026-09-21", "label": "MON 14 – SUN 20 SEP 2026",
   "business_days": 7, "covered_days": 7, "gap_estimated_days": 1, "min_data_trust": 0.91, "partial": false}]

Notes

  • Period boundaries and what counts as selectable come from #81; this route is where those rules live.
  • Needed by every deck view (the selector button in the top bar).

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)

  • Returns every closed period with some data, newest first. partial is true when covered_days < business_days; the label shows it ("4 of 7 days").
  • Bad-data periods (gap estimates, low Data Trust, excluded cycles) are included with their quality fields so the picker can mark them; never filtered out.
  • Week label: date range plus the ISO week number as a separate field (iso_week).
  • Week and month lists are independent; no week-to-month mapping.
## Route `GET /api/statistics/periods?granularity=day|week|month&limit=…` Returns the closed periods a presenter can pick, newest first, for the deck's period selector. ## Response sketch ```json [{"granularity": "week", "start": "2026-09-14", "end": "2026-09-21", "label": "MON 14 – SUN 20 SEP 2026", "business_days": 7, "covered_days": 7, "gap_estimated_days": 1, "min_data_trust": 0.91, "partial": false}] ``` ## Notes - Period boundaries and what counts as selectable come from #81; this route is where those rules live. - Needed by every deck view (the selector button in the top bar). ## 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) - Returns every closed period with some data, newest first. `partial` is true when `covered_days < business_days`; the label shows it ("4 of 7 days"). - Bad-data periods (gap estimates, low Data Trust, excluded cycles) are included with their quality fields so the picker can mark them; never filtered out. - Week label: date range plus the ISO week number as a separate field (`iso_week`). - Week and month lists are independent; no week-to-month mapping.
Author
Owner

Implemented by #89, merged into master as 3541af5 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 #89, merged into `master` as 3541af5 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#82
No description provided.