Repository navigation
fix(import): store wearable and Mi Band efficiency as a 0-1 fraction - #2941
Open
matthiasthomas wants to merge 1 commit into
Open
matthiasthomas wants to merge 1 commit into
matthiasthomas wants to merge 1 commit into
Conversation
dailyMetric.efficiency and sleepSession.efficiency hold the 0-1 fraction the native pipeline writes, and the WHOOP CSV and Oura cloud importers convert to it. The Oura-export, Fitbit, Garmin and Mi Band importers still wrote a percentage. Rest clamps efficiency to 0-1, so an imported night scored a perfect efficiency component: 1.6 points too high at 92%, carried into Charge through its sleep-quality term. Both platforms now convert at the write boundary, as the WHOOP importer does, and compute the fallback as a fraction. Parsed values stay verbatim. The demo seeders write the same scale. Two readers printed the raw column: the Mi Band card, and Today's Rest caption when a night has an efficiency but no duration. They now read a fraction, and a percentage from a night stored before this change. Rows already stored are not migrated or re-scored here; re-importing the export rewrites them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 this PR does
dailyMetric.efficiencyandsleepSession.efficiencyhold the 0–1 fraction the native pipeline writes, and the WHOOP CSV and Oura cloud importers convert to it (#376). The Oura-export, Fitbit, Garmin and Mi Band importers still wrote a percentage.Effect: Rest clamps efficiency to 0–1, so an imported night scored a perfect efficiency component: 1.6 points too high at 92%. Charge takes Rest as its sleep-quality term. In practice this reaches scored nights mainly through Oura and Garmin exports, because scoring needs HRV.
Fix: both platforms convert at the write boundary, as the WHOOP importer does, and compute the asleep ÷ in-bed fallback as a fraction. Parsed values stay verbatim. The demo seeders write the same scale.
Readers: two places printed the raw column and would have shown "1%": the Mi Band card, and Today's Rest caption when a night has an efficiency but no duration. Both now read a fraction, and a percentage from a night stored before this change. The other readers I checked already accept both scales.
Not included: rows already stored are not migrated or re-scored. Re-importing the export rewrites them. A repeat of the
> 1.5heal would need a new GRDB and Room version, so it is left to a separate decision.Type of change
How it was tested
ImportedEfficiencyUnitTests(Swift) andImportedEfficiencyUnitTest(Kotlin) run the same synthetic Oura and Fitbit exports through each importer's store step and expect the same literals, including a Rest value that no longer saturates. They also cover the Mi Band helpers, and on Apple the Mi Band card.StrandTests(macOS): 2,273 tests. The only failures are the two timezone tests fix(dates): show day-keyed dates on their own day in every time zone #2723 fixes; they also fail without this change.NOOPiOSbuilds.testFullDebugUnitTest: 6,642 tests, 2 failures, both inRecoveryDriversTest, which also fail locally on the unmodified base.Checklist
swift testinPackages/<name>): n/a, no package touchedandroid/: all but the 2RecoveryDriversTestfailures aboveStrandDesigntokens: n/a, no styling changedocs/CONTRIBUTING.mdStrand.xcodeproj/) or any secrets/keystoresRelated issues
Refs #376
🤖 Generated with Claude Code