Repository navigation
feat(analytics): sleep-vs-wake HR contrast (Swift + Kotlin) - #1424
Merged
Merged
Conversation
Adds SleepHeartRateContrast, a pure engine that compares mean HR over an explicitly supplied primary-sleep window against a wake window, mirrored Swift/Kotlin. Reports sleepMinusWakeBpm, sleepReductionPercent, and per-window valid/total/coverage. Deliberately NOT a new RHR definition: the shipped floor RHR and the primary-session mean candidate (#1174/#1188, evidence #1169) are untouched, and it adds no third definition. Emits NO dipper/non-dipper/riser/risk/diagnostic label - descriptive wellness context only, matching NOOP's non-diagnostic boundary. Says "sleep vs wake", not "night vs day"; window selection is the caller's responsibility. Fixed-grid input contract: nil = unobserved, out-of-range (30..220 bpm) = invalid; missing/invalid epochs are never imputed and only lower coverage. The 30-valid-sample gate is parameterized (default mirrors the primary-session RHR experiment) and applied independently to each window. Idea from @jonbiro. Not yet surfaced - no consumer builds the windows yet.
ryanbr
added a commit
that referenced
this pull request
Aug 18, 2026
Build numbers only. MARKETING_VERSION / versionName stay 10.1.1 — the staging line is one above the latest release (v10.1.0) and holds there until 10.1.1 actually ships. versionCode 341 -> 342 and CURRENT_PROJECT_VERSION 223 -> 224, both +1 past the previous staging build so a sideloaded update installs in place rather than being refused as a downgrade. Picks up since the last testing build (f2271cd): backup build provenance (#1422), the CTL/ATL/TSB training-load engine (#1423) and its Trends card (#1425), sleep-vs-wake HR contrast (#1424), the v20 optical decoder + CRC gate (#895), the Sleep UI split (#1426), the WHOOP4 clock-correlation fix (#1427), the settings waist-row layout + copy fix (#1428), hourly Apple step import (#1429), Low refresh (#1430), and Power saving moving into More with a 35% ceiling (#1431).
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.
What
A pure, deterministic engine — mirrored Swift/Kotlin — that compares mean HR over an explicitly supplied primary-sleep window against mean HR over an explicitly supplied wake window. Reports
sleepMinusWakeBpm,sleepReductionPercent = 100·(W−S)/W, and per-window valid/total/coverage.Deliberately not a new RHR, not a dipping classifier
Contract
Fixed-grid epoch arrays:
nil= unobserved, out-of-[30,220]-bpm = invalid; missing/invalid epochs are never imputed and only lower coverage. Unweighted mean over valid epochs (a time-weighted mean only because the grid is fixed). The 30-valid-sample gate is parameterized (default mirrors the primary-session RHR experiment) and applied independently to each window;evaluatereturns nil unless both sides clear it.Tests / validation
testFullDebugUnitTest:SleepHeartRateContrastTest7/7 green locally (both reduction signs, independent gating, coverage math, range-edge inclusivity, fail-closed).StrandAnalyticsTests: same suite, validated byswift-packagesCI (StrandAnalytics needs macOS).Status
Complete + tested but not yet surfaced — nothing builds the fixed-grid wake/primary-sleep HR windows yet; that window-construction is deliberately out of scope. Idea from @jonbiro.