Repository navigation
Accuracy check: compare the ring with another device via Health Connect - #30
Merged
Merged
Conversation
Compare the ring against a trusted device's Health Connect records for a few days, pause the export meanwhile, report bias vs noise per metric, and offer read-time corrections only where the bias is consistent.
… ring changes Corrections stay out of Health Connect but feed baseline, zones and calorie estimates via adjusted copies. The export pause covers only the types the reference writes. Adds the Health Sync bridge caveats (origin label, echo risk, lag) and what happens when the user changes rings.
Settings → Accuracy check asks for its own Health Connect read permissions (steps, distance, active calories, HR, resting HR, sleep, SpO2, HRV) and scans the last 7 days. Per source app and type it shows record/sample counts, median cadence, median delivery delay (lastModifiedTime - endTime, i.e. a bridge's sync lag), Metadata.device, and sleep stage types. Health Sync is labelled as a bridge, and an echo check flags a source whose HR matches the ring's own to the second and beat (a two-way bridge sending PulseLoop's export back). Copy summary gives counts and timings, no readings. Nothing is stored; no check runs yet. The export's reconcile already filters to its own write set, so these grants don't register as export grants (pinned in ReferenceSurveyTest). The rationale screen now describes both read paths.
…nnect exports A check is started from a source card in Settings -> Accuracy check, runs 3/5/7/14 days, and ends on time (one-shot worker plus a 6-hourly backstop and a report-ready notification), early by hand, or the moment a different ring is paired (AccuracyRingWatcher; ring data carries no device id, so it can't be split later). While it runs, the export holds back only the record types the reference writes (ExportUnit: steps, distance and active calories separately), by data time: a held-back record is dropped from the pass and its watermark still advances past it, like a never-exportable row. So the default resume choice, Skip these days, needs nothing but closing the window, and a window record updated later (a re-synced night) stays held back. Export them too drops the exclusion and rewinds the affected watermarks to where holding back began (rewindWatermarks: never forward, never past a new-only user's consent), under the export's pass mutex. The pause set grows when the reference starts writing a type mid-check, from that type's first record. Room v36: accuracy_checks, accuracy_paused_units, accuracy_check_days, accuracy_corrections, and activity_daily.estimatedActiveCaloriesAdjusted for Phase 4; migration SQL checked against Room's generated schema. All of it rides the archive, since it holds the export exclusions.
…port it AccuracyScorer reads the reference's records for the check window (origin-filtered, foreground) and reduces them to per-day aggregates in accuracy_check_days; the reference's readings are never stored. Compared: steps, distance, active calories (whole local days inside the window, skipping days either device clearly wasn't worn); time asleep, fell-asleep and woke-up times, and minute-by-minute stage agreement per waking day; heart rate paired sample by sample, split at rest (asleep, or a quiet 15-min bucket) vs active (a busy bucket or a workout), with the pairing window widened for a sparse reference like a bridge app; resting HR and HRV per night; SpO2 paired within five minutes. A day is scored once the reference has delivered past its end, or 24 h after it, so a bridge's sync lag doesn't read as the ring overcounting. AccuracyComparison.summarize separates bias from noise: Agrees, Consist- ently high/low (average outside the band, >=80% of days the same way, day-to-day wobble smaller than the bias; only these offer a correction) or Inconsistent. Bands are editable per metric and verdicts recompute from the stored rows. The report lists metrics outside their band worst first, warns when the reference's HR echoes the ring's own, and says 'differs from <reference>', not 'is wrong by'.
A metric the report calls consistently high or low offers its fitted correction (steps and distance: a scale factor; heart rate at rest and when active, resting HR, SpO2 and time asleep: an offset), adjustable with a slider before it's saved. Inconsistent metrics offer none, and sleep timing, stages, HRV and calories stay report-only. Corrections never touch stored rows (the ring re-sends its history anyway) and never reach Health Connect; they're applied in the ViewModels, so Today, Vitals and its detail charts, Sleep, Activity and the widgets built from the same state all show the same figures, each screen with an 'Adjusted by your accuracy check' caption. A single heart rate sample is split rest/active at Flex-HR, the calorie estimator's own threshold. Derived figures follow: the HR zones sit on the baseline plus the at-rest offset (an offset moves a percentile by itself, so nothing is recomputed), and the calorie estimator writes a corrected copy beside the raw one (estimatedActiveCaloriesAdjusted); the app shows the copy, Health Connect still gets the raw column. Changing a correction re-runs 90 days of estimates without bumping updatedAt, so the export doesn't re-read them. A steps correction supersedes the phone step calibration rather than stacking on it. Corrections belong to one ring (keyed by BLE address): a different ring starts with none, the old ring's come back if it's re-paired, and a correction fitted 90+ days ago or on other firmware is flagged for a fresh check.
Share on the report sends the verdicts and headline differences with the ring's model and firmware, for issue reports; aggregates only, no day values or readings, for the same reason the diagnostics export has none. docs/accuracy-check-plan.md gains an As built section recording where the code differs from the plan (held-back exports filtered by data time rather than by holding the watermark; no charts in the report; onset/wake report-only; Flex-HR split for heart-rate corrections; what stays raw). AGENTS.md gets the rules most likely to be undone by a later cleanup.
… workout The two gaps left by Phase 4. Widgets: the steps and sleep tiles read raw rows while the heart-rate and SpO2 tiles (via VitalsViewModel.buildState) were corrected; all of them now use the same corrections, and each corrected tile adds '· adjusted' to its header. The payloads carry an adjusted flag that defaults to false, so snapshots written before it still decode. Coach: the context builders, the summary and notification contexts and the data tools read steps, distance, sleep, heart rate and SpO2 through the corrections, and the data-quality notes tell it which figures are adjusted, so it neither presents them as raw readings nor corrects them again. Live workout: the bpm readout and its zone are corrected and labelled on the record screen, as are a finished workout's displayed HR and SpO2 stats. What the workout stores stays raw: Health Connect and Strava get it.
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.
Adds Settings → Accuracy check. You wear the ring and a device you trust (e.g. a Huawei watch through Health Sync) for a few days. PulseLoop reads that device's Health Connect records, reports where the ring agrees or falls short, and can correct a consistent bias. Design and "As built" notes are in
docs/accuracy-check-plan.md, and the rules most likely to be undone later are in a newAGENTS.mdsection.What's in it, by phase
Testing
./gradlew :app:testDebugUnitTest: 1,752 tests ran and 3 failed. The 3 failures (ResponsesHttpTest,MealJournalTest) also fail on the base commit and are unrelated to this change.Generated by Claude Code