la_mojo: one report database per hour (report_HH.db) #10

Merged
ClaudeAI merged 1 commits from feature/hourly-report-db into master 2 hours ago
ClaudeAI commented 2 hours ago
Collaborator

Summary

The report engine now keeps a separate report database for every local hour inside the day folder:

data/reports/YYYY/MM/DD/report_00.db ... report_23.db

The name comes from REPORT_DB_NAME_FMT ("report_%02d.db") in SQLite_dataBinder.h. Pictures and videos stay in the day folder, and the day statistics in stat.db are unchanged.

Sessions at the hour change

The same rule as at midnight, applied every hour:

  1. A session still open from the previous hour is closed, and its END event goes into the old hour's file. If a video with events is still recording, it waits for it first, at most REPORT_SWITCH_MAX_VIDEO_WAIT (90 s).
  2. Once the END event is written, the report switches to the new hour's file (in the next day's folder at midnight).
  3. The next event opens a new session in the new file.

So every hourly file contains complete sessions, and a long alarm appears as consecutive sessions.

Code

  • sqliteDBC::openHourReport() replaces openDayReport(). switchReportToCurrentHour() (renamed from switchReportToCurrentDay()) switches when the local day or hour changes. connect() opens the current hour's file at startup.
  • mojoKernel::handleReportPeriodChange() (was handleDayChange()) runs the close-then-switch sequence on every local hour change.
  • getLocalHour() helper added in basicFunctionality.

Action needed outside this repository

The web UI that displays reports (under /srv/www/...) is not in this repository. It must be updated to read all report_HH.db files in a day folder instead of report.db. Existing day folders keep their old report.db (no migration).

Testing

Test program built around the real sqliteDBC code, run under faketime (Asia/Jerusalem), with a second thread writing an event every 2 ms and ThreadSanitizer enabled:

  • 13:59:58 to 14:00: report_13.db and report_14.db in the same day folder. The session's START and END are in report_13.db, and the new session's START is in report_14.db. All 723 events stored.
  • 23:59:58 to 00:00: 26/report_23.db and 27/report_00.db, same session behavior. All 705 events stored.
  • Switch window: 7 events per run were written in the moment between the hour change and the switch, so they landed in the previous hour's file. This window is up to 1 s in the kernel.
  • ThreadSanitizer: no findings.
  • Build: compiles with the Debug86 flags with no new warnings. The full program was not run.

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## Summary The report engine now keeps a separate report database for every local hour inside the day folder: ``` data/reports/YYYY/MM/DD/report_00.db ... report_23.db ``` The name comes from `REPORT_DB_NAME_FMT` (`"report_%02d.db"`) in `SQLite_dataBinder.h`. Pictures and videos stay in the day folder, and the day statistics in `stat.db` are unchanged. ### Sessions at the hour change The same rule as at midnight, applied every hour: 1. A session still open from the previous hour is closed, and its END event goes into the old hour's file. If a video with events is still recording, it waits for it first, at most `REPORT_SWITCH_MAX_VIDEO_WAIT` (90 s). 2. Once the END event is written, the report switches to the new hour's file (in the next day's folder at midnight). 3. The next event opens a new session in the new file. So every hourly file contains complete sessions, and a long alarm appears as consecutive sessions. ### Code - **`sqliteDBC::openHourReport()`** replaces `openDayReport()`. `switchReportToCurrentHour()` (renamed from `switchReportToCurrentDay()`) switches when the local day or hour changes. `connect()` opens the current hour's file at startup. - **`mojoKernel::handleReportPeriodChange()`** (was `handleDayChange()`) runs the close-then-switch sequence on every local hour change. - **`getLocalHour()`** helper added in `basicFunctionality`. ## Action needed outside this repository **The web UI that displays reports (under `/srv/www/...`) is not in this repository.** It must be updated to read all `report_HH.db` files in a day folder instead of `report.db`. Existing day folders keep their old `report.db` (no migration). ## Testing Test program built around the real `sqliteDBC` code, run under `faketime` (Asia/Jerusalem), with a second thread writing an event every 2 ms and ThreadSanitizer enabled: - **13:59:58 to 14:00:** `report_13.db` and `report_14.db` in the same day folder. The session's START and END are in `report_13.db`, and the new session's START is in `report_14.db`. All 723 events stored. - **23:59:58 to 00:00:** `26/report_23.db` and `27/report_00.db`, same session behavior. All 705 events stored. - **Switch window:** 7 events per run were written in the moment between the hour change and the switch, so they landed in the previous hour's file. This window is up to 1 s in the kernel. - **ThreadSanitizer:** no findings. - **Build:** compiles with the `Debug86` flags with no new warnings. The full program was not run. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 1 commit 2 hours ago
c18b36a6a4
la_mojo: one report database per hour (report_HH.db)
Poster
Collaborator

The web UI side is in gagua/Mojo_Web: Reports: read hourly report_HH.db files (feature/hourly-report-db). Merge and deploy both together.

The web UI side is in gagua/Mojo_Web: Reports: read hourly report_HH.db files (feature/hourly-report-db). Merge and deploy both together.
ClaudeAI merged commit 70a333ab67 into master 2 hours ago
The pull request has been merged as 70a333ab67.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.