Skip to content

feat: show the range on a full battery, the distance per charge and the usual charge in statistics - #779

Open
arthur-lzrs wants to merge 1 commit into
joszz:mainfrom
arthur-lzrs:feat/charge-range-insights
Open

arthur-lzrs wants to merge 1 commit into
joszz:mainfrom
arthur-lzrs:feat/charge-range-insights

Conversation

@arthur-lzrs

Copy link
Copy Markdown
Contributor

Summary

The charge history lists every charge with its odometer and battery levels, and what was driven since the one before. Nothing added those up into the figures a driver asks about: how far does my car really go on a full battery? how far between charges? from what level to what level do I usually charge?

Three new insight cards on the Statistics page, from the charges of the selected period:

  • Range on a full battery (BEV only): the kilometres between one charge and the next per percent of battery used between them, times 100. It is what the car does at the way it is driven, which is worth setting beside the range the car estimates. A plug-in hybrid does not get it, as its kilometres include petrol.
  • Distance per charge: the distance usually driven from one charge to the next (the middle value over the period's charges). A plug-in hybrid's includes petrol kilometres, and its info says so.
  • Typical charge: the average level the period's finished charges started from and ended at, for example 42% → 80%.

Each needs at least three charges, so none is shown on a car that has not charged that often in the period. Each has an info text that says how it is worked out.

How it works

  • utils/chargeStatistics.ts has the logic: chargePairs pairs each charge with the next (distance from the odometers, battery used from the levels), and the three figures are computed from the pairs. The pairs are built from the same figures the charge history's sincePreviousCharge reads from the same sessions (the odometer and the battery levels of each charge).
  • Not fooled by a charge nobody saw. The sessions come from the charging state the gateway reported, and the gateway reads a parked car rarely, so a charge can be missing from the list. Two pairs then merge into one with a long distance and little battery used. For the range, pairs under 10 km or 10 points are left out as too short to read, and a pair more than twice off the middle kilometres-per-percent is left out; the figure is the sum of what is kept over the sum of battery used, so a long stretch counts for more than a short one. For the distance per charge the middle value is used, which one long pair does not move, and a hop under 5 km is taken for a split charge.
  • It uses the charge-sessions endpoint the charge history already reads: one more request when the Statistics page loads, only for a car that can plug in. If that request fails the rest of the page shows as before.
  • The cards are appended to the insight list, so a layout saved before this keeps its order and gets them last, hidden or shown as it likes (they are in the page's edit mode like the others). No backend change, no stored-settings change.
  • README.md has the three rows in the insight table.

Type of Change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Dependency update
  • Other

Related Issues

None.

How it was tested

  • Unit tests for every function in chargeStatistics (pairing in any order, a charge still going, missing levels, a level that went up, a pair that went backwards; the middle value with an unseen charge; the range with outliers, short pairs and too few; the habit).
  • StatisticsView tests: what the page asks for and of which cars, the three cards on a BEV and two on a plug-in hybrid, none with too few charges, and the page still showing when the charges cannot be read.
  • Demo mode in the browser: the ZS EV shows 351.8 km on a full battery, 148.0 km per charge and 42% → 80%; the HS plug-in hybrid shows the last two.
  • Not yet on a real car: the real car I use has not charged three times since I began recording, so these have only been seen on demo data.

Notes for review

  • Translations: the text in nl, es and pt-PT is my own draft, so a native check is welcome.
  • The thresholds (MIN_PAIRS, the 10 km / 10 points, the factor of two, the 5 km hop) are constants at the top of chargeStatistics.ts, easy to tune.
  • The figures describe the charges the app saw. A charge it did not see is handled as described above, but a period with few charges is still a small sample, which is why three is the minimum.

Checklist

  • Tests added or updated
  • Checks pass: pnpm check in frontend/ (frontend only: the .NET side is untouched, so dotnet test and dotnet format were not run)
  • Commit messages follow Conventional Commits (feat: ..., fix(frontend): ...)
  • If trips changed (ITripRepository): done in the demo too, with a step in TripRepositoryContractTests (not applicable)
  • If the API changed: the rewritten documentation/openapi.json is committed (not applicable, the API did not change)
  • New fields or features have demo data in src/GarageStack.Data/Demo/ (the demo's charge history already has what the cards read)
  • No secrets or personal data committed, and no real VIN or licence plate in test data
  • Responsive on mobile, down to 320 px wide (the cards are the existing insight cards)
  • Every new UI text is an i18n key, in every file in frontend/src/locales/
  • If unraid/garagestack.xml changed: synced to joszz/unraid-community-apps after merge (not applicable, it did not change)

🤖 Generated with Claude Code

…he usual charge in statistics

The charge history already lists each charge with its odometer and battery levels, and what was
driven since the one before. Nothing added those up into the figures a driver asks: how far does
the car really go on a full battery, how far between charges, and from what level to what level
does it usually charge.

Three insight cards on the Statistics page, from the charges of the period (the charge-sessions
the page for the charge history already reads, one more request for a car that can plug in):

- Range on a full battery (BEV only, as a hybrid's kilometres include petrol): the kilometres
  between two charges per percent of battery used between them, added up over the pairs, times 100.
  Pairs under 10 km or 10 points are too short to read, and a pair more than twice off the middle
  kilometres-per-percent is left out: a charge no poll caught between two reported ones makes a
  pair that spans two charges, with the battery having gained in the middle.
- Distance per charge: the middle value of the distances between charges, so that same unseen
  charge, which makes one long pair, does not pull it up. A hop under 5 km is a split charge.
- Typical charge: the average level the finished charges started from and ended at.

Each needs at least three charges, and none is shown without. The logic is in
utils/chargeStatistics, the cards are in the existing insight list (appended, so a layout saved
before keeps its order and gets them last), and each has an info text saying how it is worked out,
in every locale. A charge list that cannot be read leaves the rest of the page as it was.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant