Skip to main content

Module stats

Module stats 

Source

Functions§

clear_event_log
Delete the persistent events.jsonl log (the “Clear history” button on Insights). In-session counters are unaffected. Emits stats:cleared so the renderer can refresh.
export_stats_csv
Serialise every persisted event as a CSV string. The renderer hands the result to a Blob → download for “Export CSV” on Insights.
get_break_stats
In-session counters (taken / skipped / postponed). Reset on every scheduler start.
get_current_break
Snapshot of the in-flight break event, or None between breaks. Used by the overlay on cold-mount so it can re-render the right state if the window was reloaded mid-break.
get_idle_secs
Seconds since the last keyboard/mouse input. Used by the overlay to drive the typing-pause feature: while the user is mid-keystroke the countdown is paused.
get_screen_time
Today’s accumulated screen time + the last-reminder marker. Rolls over to a fresh day if local midnight has passed since the last call.
get_stats_digest
Aggregate the persistent event log into a digest for the Insights tab. range is "week" (default) or "month". Reads events.jsonl every call — small enough to be cheap, large enough that the renderer should debounce range toggles.
reset_and_snapshot_break_stats 🔒
Atomically replace the scheduler’s in-session counters with their default and return the snapshot the emit should ship. Extracted as a separate helper so the lock-then-snapshot ordering can be tested against a real concurrent writer.
reset_and_snapshot_break_stats_inner 🔒
Pure-ish helper: zero the cell under the supplied mutex and return a snapshot of the post-reset value, both atomic to outside writers. Tested in isolation because Scheduler is not constructible in unit tests (it spawns camera/video monitor threads at boot).
reset_break_stats
Zero out the in-session counters and emit stats:changed. The persistent event log under events.jsonl is untouched — clear_event_log does that.