Skip to content

The cost of each trip, and the cost per 100 km #397

Description

@vcanuel

Each trip tells its energy, each charge its cost (the place's tariff, or the amount entered). Nothing tells what a trip cost, nor the cost per 100 km of a period.

The price of a trip's kWh

A trip's energy is the drop of the state of charge times the battery's capacity: an energy on the battery side. It is priced at the average price of the kWh that went into the battery: the cost of the vehicle's charges over the 30 days before the trip, divided by the energy they added (battery side too). A trip after a week of fast charging costs more than one after a week of charging at home, as it does on the bills.

  • Charges without a cost (no tariff at their place, nothing entered) stay out of the average; when none has a cost over the 30 days, the trip's cost is unknown (null), not zero.
  • A charge's cost is a range (min, max: ADR 0021 §4), so a trip's is too; shown as one amount when both bounds are close, as a range otherwise.
  • Computed at read time, nothing stored, as the charges' costs are: a new tariff version or an entered cost shows at the next request.

To do

  • Core: a pure function, the price per kWh over a window, and the cost of a trip from it, tested in table.
  • API: the cost on each trip (GET /vehicles/{id}/trips, a trip's detail), and in the statistics the driving cost of the period and the cost per 100 km.
  • Web: the cost on the trip's card and detail, the cost per 100 km in the statistics' tiles.
  • Documentation: how the cost of a trip is computed, and why it may be unknown.

Open questions

  • 30 days before the trip, or the charges of the period shown?
  • Range or single amount: from what gap is a range shown?

Activity

  1. added
    brand:any
    on Nov 14, 2026
  2. added theissue type on Nov 14, 2026
  3. vcanuel commented on Nov 14, 2026

    @vcanuel
    ContributorAuthor

    Decided on the mockup:

    • The price of a trip's kWh: the average over the vehicle's charges of the 30 days before the trip (not the period shown), so that a trip's cost does not change with the filter.
    • Trips list: the amount, and its cost per 100 km below it.
    • One amount when the bounds are within 10 % of each other, a range otherwise.
    • Statistics: two tiles beside the charges' cost: cost per 100 km and driving cost (what the period's trips used, at the price of their 30 days).
    • Trip detail: a Cost card beside Figures: the amount, the price per kWh, the number of charges it rests on, and a bar of where that energy was charged (by place, the rest as AC or DC elsewhere) with each one's price.
  4. vcanuel commented on Nov 14, 2026

    @vcanuel
    ContributorAuthor

    Decisions taken while implementing, beyond the mockup:

    • Plug-in hybrid: a trip keeps its cost, the electricity it used (the card says the fuel is not counted), but has no cost per 100 km, in the trip as in the statistics, as it has no consumption (WithoutConsumption).
    • History limit: the charges an account's history hides price nothing. A trip right after the limit may rest on fewer charges, or have no cost.
    • CSV: the trips' file gains the cost columns at its end (cost_currency, cost_min, cost_max, cost_per_100km_min, cost_per_100km_max, cost_price_per_kwh_min, cost_price_per_kwh_max, cost_charges), since the file holds the list's items flattened.
    • One amount within 10 %: the middle of the bounds, to the cent. The same rule applies to the price per kWh shown on the card.
    • Elsewhere: outside every place, a charge of unknown type (a reconstructed one) counts as AC, as its efficiency already assumes.
    • Left open: the Garage's cost per 100 km still divides the charges' cost by the distance. Moving it to the trips' cost is a separate question.
  5. vcanuel commented on Nov 14, 2026

    @vcanuel
    ContributorAuthor

    Settled: every cost per 100 km rests on the trips' cost now, in the same pull request. That covers the statistics' chart of the costs view, which led to the charges of its interval and now leads to its trips, and the Garage: each vehicle's tile, its comparison by month, and the account's average. A plug-in hybrid has none in the Garage either.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    brand:any

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions