You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Health: capacity and full range are over-estimated when a charge session is first seen mid-way #114
chargeSessions() builds each session from the first and last charging samples the app observed. session(start, last) (HealthSummary.kt#L164-L173)`` then mixes two kinds of value:
startPercent = start.batteryLevel comes from the first observed sample;
energyAddedKwh = last.chargeEnergyAdded and milesAddedRated = last.chargeMilesAddedRated are what the car reports cumulatively since the session began.
The first observed sample is often not the start of the session: the app was opened or came into range mid-charge, the link dropped and reconnected, or the phone was away during a scheduled overnight charge. In all of those cases, the energy and miles from the unobserved part get divided by only the observed SOC swing.
Example: the car is plugged in at 20 %. The first sample is at 50 % with charge_energy_added = 22.5, the last at 80 % with 45.0. Today's code computes 45 kWh / 30 % = 150 kWh. fullRangeMiles (cumulative miles / 30 %) is inflated by the same factor, and so is the "backbone" capacity kwhPerMile × fullRangeMiles. Using deltas gives (45 − 22.5) / 30 % = 75 kWh.
HealthSummaryTest always starts a session at energyAddedKwh = 0f, so this path has no test.
Two smaller problems in the same file:
LEARNING_SESSIONS = 3 sits under the comment "The benchmark product needs about twenty sessions for a verdict; we do too." (L200-L201).`` The comment and the code disagree; one of them should change.
Sessions are split purely on chargingState == "Charging". A brief Starting or Stopped state therefore turns one plug-in into several "sessions" and inflates the count used by the learning gate.
Proposal
Use last − first deltas for energy and rated miles, or reject sessions whose first observed sample already has charge_energy_added > ε. Record the real session start when it can be observed.
Add tests for: a session first seen mid-charge, a session interrupted by a disconnect, and Starting/Stopped blips.
Move session segmentation into core/health next to the estimators; it is pure Kotlin.
Activity