Fix battery estimate anchoring on a stale, multi-cycle-old peak (#99)#109
Merged
Merged
Conversation
…br#99) A WHOOP MG that tops up short of full every day never trips the near-full anchor (rule 1), so the discharge fit fell back to scanning the SoC buffer's global max — which, across many partial-top-up cycles, can sit several days back. The endpoints-only fit then nets across every undetected intermediate top-up in between, diluting the actual recent drain rate into something far flatter than reality (reported "9% = ~3 days" when the true recent drain was closer to 6h left). Bound the max search to at most the last two charge-step cycles so it stays anchored to how the strap is being used right now. Buffers with 0 or 1 charge-steps search from the start exactly as before, so ryanbr#8 and #919 are unaffected — verified against all existing fixtures plus a new multi-cycle regression test. Ported the same fix to the Kotlin twin to keep both platforms behaviour-identical. Co-Authored-By: Claude Sonnet 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.
Summary
dischargeFitWindowto at most the last two charge-step cycles, so it stays anchored to how the strap is being used right now. Buffers with 0 or 1 charge-steps search from the start exactly as before, so CI: release workflow bumps version (patch/minor/major) in source before releasing #8 and #919 are unaffected.android/.../BatteryEstimator.kt) to keep both platforms behaviour-identical, per the file's existing convention.Test plan
swift testinPackages/StrandAnalytics— all 954 tests pass, including the newtestOldPeakDoesNotFlattenARecentFastDrainregression case and all pre-existing fixtures (CI: release workflow bumps version (patch/minor/major) in source before releasing #8, #919, #713).xcodebuild build -scheme Strand -destination 'platform=macOS'succeeds with no new warnings/errors../gradlew testDebugUnitTestin this environment (no JDK installed) — worth a CI check before merge.🤖 Generated with Claude Code