Skip to content

Battery estimate: scale the sanity cap to current SoC — fixes "9% = 3 days" (#99)#118

Merged
ryanbr merged 1 commit into
mainfrom
fix-battery-estimate-low-soc
Jul 8, 2026
Merged

Battery estimate: scale the sanity cap to current SoC — fixes "9% = 3 days" (#99)#118
ryanbr merged 1 commit into
mainfrom
fix-battery-estimate-low-soc

Conversation

@ryanbr

@ryanbr ryanbr commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Fixes #99 — on a WHOOP MG, 9% battery showed "~3 days" remaining.

Cause

BatteryEstimator.estimate computes remaining = currentSoC ÷ discharge-rate, clamped only by a flat ratedHours × 1.5 — which ignores current SoC. A too-slow measured slope at low charge (idle/off-wrist spans, or sparse 5/MG SoC readings → a tiny %/h) extrapolated 9% to ~3 days = more than a full 12-day MG charge (ratedLifeHoursWhoop5 = 288). The flat cap (432h for an MG) never caught it. Discharge is also non-linear (faster near empty), which a straight-line fit misses exactly at low SoC.

Fix

Scale the sanity cap to the current SoC: ratedHours × 1.5 × (current/100). You can't realistically stretch the rated per-% runtime past ~1.5×, so this bounds the estimate to a physically-plausible fraction of the rated life. At 9% on an MG → ~1.6 days instead of 3+, while:

  • rated-fallback estimates are mathematically unchanged (a rated estimate is exactly ratedHours×(current/100), always ≤ the new cap);
  • healthy mid-range measured estimates are untouched (well under the cap).

Applied identically on both platforms (Swift + Kotlin twin).

Re-review + testing

Checked against all existing cases: only the one clamps… test changes (90% W4: 162 → 145.8h — its exact premise being refined), and the trace tests don't assert the clamp value. Added a new low-SoC test pinning the report (25%→9% slow drain → 38.88h, not ~56h). Android unit tests green locally; iOS is the byte-identical twin (same fixtures) — a testing build verifies the Swift compiles.

On royabby365's question (in-thread)

No new battery-diagnostic test needed — the existing Test Centre → Battery panel already exposes the SoC series, fitted slope, and slope source for self-diagnosis. This targeted clamp fixes the reported case without new UI.

Files: BatteryEstimator.swift/.kt (+ both test files).

… days" (#99)

The runtime estimate (currentSoC ÷ discharge-rate) was clamped only by a FLAT
`ratedHours × 1.5`, which ignored how much charge was actually left. So a too-slow
measured slope at low charge (idle/off-wrist spans, sparse 5/MG SoC readings)
extrapolated 9% to ~3 days — more than a full 12-day MG charge. Scale the cap to the
current SoC: `ratedHours × 1.5 × (current/100)`. At 9% on an MG that bounds to
~1.6 days instead of 3+, while healthy mid-range and rated-fallback estimates are
unchanged (a rated estimate = ratedHours×(current/100), always ≤ the new cap).

Both platforms (Swift + Kotlin twin). Tests: the existing clamp test updated
(90% W4 → 145.8h, was 162), plus a new low-SoC case (25%→9% slow drain → 38.88h,
not ~56h). Android unit tests green; iOS is the byte-identical twin.
@ryanbr ryanbr merged commit dfd0e81 into main Jul 8, 2026
4 checks passed
@royabby365

Copy link
Copy Markdown

Sweet!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Battery time remainder estimate

2 participants