Implement sending typical sleep to the watch#194
Open
aveao wants to merge 6 commits into
Open
Conversation
Adds the four-field data class and file-private constants (history weeks, min-history threshold, min-session-seconds filter, seconds-per-day) that the upcoming typical-sleep writer will use. No behavior change yet.
Adds the helper signature, empty-input fast path, and test fixtures (session, nightSleepMulti, nightSleep) that subsequent tests will use. Subsequent commits fill in the per-weekday reducer test-by-test.
Implements buildWeekdaySleepTypicalsFromData: filters sessions ≥30min, partitions by weekday, computes arithmetic-mean durations and circular-mean bedtime/wake (so 23:00+01:00 averages to ~00:00, not noon). Weekdays below the 2-day minimum-history threshold are omitted. Adds the secondsOfDay and circularMeanSecondsOfDay helpers. Tests cover: empty input, below-threshold skip, two-day basic case, nap-only filtering, the critical circular-mean midnight-wrap case, per-weekday independence, split-sleep last-session-wake, and mixed-validity within a single day.
Wires computeAllWeekdayTypicalSleep into updateHealthStatsInDatabase so the four typical_* fields of each <weekday>_sleepData blob (which have been hardcoded to 0u since the writer was first added) now carry real values: arithmetic-mean total/deep sleep durations and circular-mean bedtime/wake, computed over the user's past 7 weeks of same-weekday history. This populates the firmware fields read by health_db_get_typical_value (blob_db/health_db.c) and consumed by the sleep summary card (apps/system/health/data.c) and the activity_insights sleep notification path.
The existing daily 6-day loop deliberately skips today (incomplete current-day daily fields shouldn't overwrite the watch's accelerometer-tracked values), but the firmware reads `<today's weekday>_sleepData` typicals on the sleep summary card. Without this extra write the typicals for today's weekday stay stale for a day after the new typical-sleep code starts running. After the daily loop, add a typicals-only blob for today's weekday with last_processed_timestamp=0. Firmware's prv_notify_health_listeners gates the in-memory daily-metric update on a valid timestamp and bails out, so daily fields=0 don't corrupt today's tracked values, but health_db_insert still stores the blob — making the typicals readable via health_db_get_typical_value. This brings sleep typicals in line with the step typicals, which already cover all 7 weekdays via their separate per-weekday loop.
Mirrors the typical-steps debug section added on fix/typical-steps, showing the four values the watch reads from each <weekday>_sleepData blob's typical tail: duration / deep duration / bedtime → wakeup. Weekdays below the 2-day minimum-history threshold show "--". WeekdaySleepTypicals visibility bumped from internal to public so the new HealthDebugStats field can expose it across modules. The data class is just four Ints and was always going to be reachable by the debug dialog by design.
Contributor
Author
|
Rebased, should be ready to review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #78
Draft as this builds on #192, that should be merged first