Repository navigation
feat(analytics): per-car fill-up and charging totals, fill-up volume (part of #1532) - #1836
Merged
Merged
Conversation
… untyped as 87 (Regular)
OnlyOneByte
commented
Nov 27, 2026
OnlyOneByte
left a comment
Owner
Author
There was a problem hiding this comment.
Verdict: changes requested
Blocking
costinfillupsByVehicle/chargingByVehiclegoes out in minor units, not major units. File:backend/src/api/analytics/api-transform.ts:22-65(fuelStatsToApi).
buildTotalsByVehicle(backend/src/utils/analytics-charts.ts:376) adds uprow.expenseAmount, which is stored in minor units. Every other money field in the fuel stats response goes throughtoMajor(scale)infuelStatsToApi:gasPriceHistory[].pricePerVolumeat :47,fillupCostByVehicle[].avgCostat :48, and the charging averages. The two new arrays are spread through...dunchanged, so they skip that step.
The regenerated fixture shows it. Inbackend/src/utils/__tests__/__fixtures__/money-capture.jsonl, the USD/analytics/fuel-statsand/analytics/summarylines havefillupsByVehicle[0].cost = 134974for 36 fill-ups. On the same lines,fillupCostByVehicle[].avgCostis28.01, so the Camry total should be about1349.74. The JPY lines only look right because JPY's scale is 1.
The response feeds/analytics/fuel-stats,/analytics/summaryand the LLMfuelStatstool (backend/src/api/providers/domains/llm/tools.ts:166). For any 2-decimal currency, all three would report per-car spend 100x too high. PR 2b would render those numbers.
Fix: infuelStatsToApi, add
fillupsByVehicle: d.fillupsByVehicle.map((v) => ({ ...v, cost: c(v.cost) })), and the same forchargingByVehicle.
Then regenerate the capture withUPDATE_MONEY_CAPTURE=1. The USDcostvalues should come out in major units, and the JPY ones should not change.
It is worth adding afuelStatsToApiunit test with scale 100, so a later money field can't skip conversion without a test failing.
Non-blocking
- PR body: the fixture sentence is incomplete. The body says the capture "gains only the two new per-car arrays". The fixture diff also changes every
gasPriceHistory[].fuelTypefromRegularto87 (Regular)and addsgasPriceHistory[].volume. Both are expected from this PR, but the sentence should say so. I checked the rest structurally: nothing else in the capture changed. - The
87 (Regular)default is a guess, not what the form saves.backend/src/utils/analytics-charts.ts:334,356:FuelTypeFields.svelte:19-27lists87 (Regular)as one option. But the select is optional ("Select fuel type (optional)"), andexpense-payload.ts:24sendsundefinedwhen nothing is picked. So an untyped fill-up could also be diesel or premium. The old code made the same guess (Regular), and merging the two buckets is an improvement. Still, the PR body wording ("the grade the expense form saves") overstates it.
No production code matched on the old'Regular'label.fuel-overview.tsandFuelCharts.svelteusefuelTypeonly as an opaque key. The frontend tests that still use'Regular'only use it as fixture data, so they are unaffected. DEFAULT_GAS_FUEL_TYPEis exported but only used inside its own file (analytics-charts.ts:334). It could be a module-localconst, unless 2b needs it.buildTotalsByVehicleskips two filters thatbuildGasPriceHistoryapplies. It does not drop rows with a null date orexpenseAmount <= 0(analytics-charts.ts:364-384).fuelRowscomes from the range query, so null dates should not reach it. Still, a zero-cost fill-up counts towardcounthere but is missing fromgasPriceHistory. That is probably intended (a free fill-up is still a fill-up), but say so in the PR or add a test for it.- Tests:
maintenance-gasprice-builders.test.tscovers the new behaviour well: conversion, the include predicate, the null-volume exclusion and the count sort. The name tie-break in the sort (analytics-charts.ts:383) has no test. Moving the existing "drops rows ..." test into a newdescribe('buildGasPriceHistory filtering')block is churn this PR doesn't need.
Checked, no issue
- Data scoping: both new arrays are built from the same per-user
fuelRowsandvehicleNameMapthatfillupCostByVehiclealready uses, so they add no new data source. - Unit handling: fill-up volume uses
convert.volume, the same converterpricePerVolumeuses. Charging energy is left unconverted, asbuildChargingStatsalready does. - Frontend types (
frontend/src/lib/types/analytics.ts): the new fields are optional and match the backend shape. - Tests run:
maintenance-gasprice-builders,money-captureandno-code-commentsall pass on the PR head. No comments were added.
OnlyOneByte
commented
Nov 27, 2026
OnlyOneByte
left a comment
Owner
Author
There was a problem hiding this comment.
Verdict: approve
I re-reviewed the whole diff against origin/main at head c8aaa484, not just the new commit. Here is each earlier finding:
- Blocking: per-car
costin minor units. Fixed.backend/src/api/analytics/api-transform.ts:48-49now convertsfillupsByVehicle[].costandchargingByVehicle[].costwithc().api-transform.test.ts:112-151checks both at scale 100 (13500 -> 135, 3600 -> 36), checks thatcountandvolumeare unchanged, and checks thatgasPriceHistory[].volumepasses through. The regenerated capture now shows USD1349.74/548.69. Correction to my earlier review: the JPY lines had the same 100x error (134900), not "correct because scale 1", and they now read1349/551. I compared the capture field by field against main. Apart from the two new arrays, the only changes aregasPriceHistory[].volumeadded andRegular->87 (Regular), which matches the PR body. - PR body fixture sentence. Fixed. It now lists the arrays,
volumeand the relabel. 87 (Regular)is a guess. Addressed. The body now says the form's fuel type is optional and the default is a guess. It also says no code relied on the old label, which matches what I found.DEFAULT_GAS_FUEL_TYPEexported. Fixed. It is now module-local (analytics-charts.ts:334).- Zero-cost and undated rows. Addressed. The new test "a free or undated fill-up still counts toward its car, unlike the price history" pins this behaviour, and the body states it.
- Tests. Fixed. The
buildGasPriceHistorytests are back in their originaldescribeblock; against main this file is now +81/-3. A name tie-break test was added ("cars with the same count sort by name").
Still holds from the first pass
- Both new arrays are built from the same per-user
fuelRowsandvehicleNameMapalready used byfillupCostByVehicle, so there is no new data source. - Fill-up volume uses the same
convert.volumeaspricePerVolume. Charging energy stays raw, matchingbuildChargingStats. - The frontend type additions are optional and match the backend shape.
- The API change is additive and the diff adds no code comments.
Verification at c8aaa484
bun testonmaintenance-gasprice-builders,api-transform,summary-route,money-captureandno-code-comments: 38 passed, 0 failed.- Backend
tsc --noEmit: 0 errors.
No remaining findings.
OnlyOneByte
enabled auto-merge (squash)
November 27, 2026 02:08
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.
Part of #1532 (C3 analytics: Fuel & charging, PR 2a of 2: the data the PR 2b frontend needs)
What changed
Three additive changes to the fuel stats response, so the Fuel & charging tab can show a per-car Fill-ups table and a Charging table, and weight its price hero by volume. Nothing else in the response changes, and the frontend doesn't use the new fields yet; that's PR 2b.
buildGasPriceHistory)87 (Regular), the form's regular grade, instead of in a separateRegularbucket. It's still a guess, as before, but one car's regular fill-ups no longer split across two types, which could make the hero pick the wrong main fuel. No code relied on the oldRegularlabel.gasPriceHistory[].volumefillupsByVehicle,chargingByVehicle(buildTotalsByVehicle,api-transform.ts)isFillup/isChargeSessionpredicates. A free fill-up still counts toward its car, though the price history skips it.types/analytics.ts)The money capture fixture is regenerated. It gains the two per-car arrays (USD: $1,349.74 over 36 fill-ups for the Daily Driver) and
gasPriceHistory[].volume, and its untyped entries read87 (Regular). Nothing else changes.Tests
maintenance-gasprice-builders.test.ts:87 (Regular)one get the same type.api-transform.test.ts: at scale 100 both per-carcostfields convert from cents (13500 → 135) while count and volume stay, andgasPriceHistory[].volumeis untouched. It fails without theapi-transform.tschange.The builder tests fail on main (run against main's
analytics-charts.ts, with a stub export so the file loads) and pass here.Checks
bun testsuite, 4791 passed, 4 skipped, 0 failed; after the cost fix,src/utils,src/api/analyticsandsrc/api/providersagain, 0 failed.tscreports 0 errors.check:musl(Biome) has no errors; its one warning is in an untouched file.npm run type-checkon Node 22 from the real path, 0 errors.eslintis clean.No UI change, so there are no screenshots.