fix(calibration): background daemon scheduling, historical reconciliation, and business-cycle charts #8
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!8
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/calibration-daemon-and-business-cycle-charts"
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?
Root Cause
check_and_run_auto_calibration_asyncwas only invoked insideget_live_occupancy_async()— an on-demand API handler triggered when a browser client hits/api/occupancy/live. If no user or kiosk was active between 03:30 and 04:30 AM, the calibration never executed. This is why Friday, Saturday, and Sunday had zero calibration logs.Fixes
1. Background Daemon Scheduling
Wired
check_and_run_auto_calibration_async()intobackground_monitor()loop (every 30 seconds), completely independent of incoming HTTP requests.2. Historical Calibration Reconciliation
New
reconcile_historical_calibrations_async()walks all past business cycles, detects missing calibration logs, and records audit entries. Runs on boot and exposed asPOST /api/analytics/calibration/reconcile.3. Business-Cycle Chart Windowing
Timeseries endpoints now use
daily_reset_time(e.g. 04:00 to 04:00) instead of midnight-to-midnight.4. New Repository Method
get_earliest_event_epoch_async()supports the reconciliation scan.Tests
85/85 pass including 3 new tests for reconciliation, quiet-window trigger, and API endpoint.
Code Review — Standards & Spec
Reviewed
git diff master...HEAD(commit6a032b0) against PR #8's stated fixes and the repo's domain docs. NoCODING_STANDARDS.mdexists, so Standards carried only the Fowler smell baseline.Standards (5 findings, all judgement calls)
guard_target - raw_netrecurs acrossoccupancy_service.pyandanalytics_service.py.AnalyticsServicetelemetry/history methods merely delegate to repos.Worst: duplicated calibration formula.
Spec (5 findings)
04:00–04:30selected the brand-new cycle instead of the completed cycle.counting_camerasexcluded/inactive filter used by calibration math.background_monitor()actually invokes the calibration check on its 30s cadence.reconcile_historical_calibrations_asyncrecords audit logs but never updatesoccupancy_config.baseline_offset.Full suite after fixes: 85 passed.
Corrections committed as
9154a89and pushed to this branch.