Calculators are pure functions in the codebase. They run on device data only; nothing is
sent to a server for mileage or prediction.
Per-fill mileage
- Sort fuel entries for a vehicle by odometer.
- For each pair of consecutive entries, take the odometer difference.
- Divide that distance by the volume or energy added at the later fill.
- Show that value on the earlier fill; the newest fill has no finished segment yet.
mileage = (odometer[i] − odometer[i−1]) / volume[i]
Recency-weighted efficiency
- Build the list of valid adjacent mileage pairs.
- Apply an exponentially weighted moving average (EWMA).
- Recent tanks influence the average more than old ones.
EWMA = α · mileage[t] + (1 − α) · EWMA[t−1]
α = 2 / (window + 1), default window = 5
Next fill prediction
- Estimate fuel or energy in the tank after the last fill.
- Full fill sets level to capacity; partial fills add volume up to capacity.
- Subtract reserve once so prediction targets your reserve zone.
- Subtract distance driven since the last fill using the latest odometer point.
- Projected date uses average distance per day over the last 30 days of points.
usable = capacity − reserve
remaining = usable × EWMA_mileage − distance_since_fill
Tank capacity learning
- Take consecutive full-tank fills.
- Volume added at the second fill approximates how much was used.
- Use the median of those volumes as the suggestion.
- Confidence rises with more full-tank pairs; apply manually if you want.
capacity ≈ median(volume added between full fills)
Trip cost
- Read recent mileage (EWMA) and the last rate you paid.
- Energy needed is planned distance divided by mileage.
- Cost is energy times rate, rounded to two decimal places.
energy = distance / mileage
cost = round(energy × rate, 2)
Nearby pumps
- Request device location permission and a single location fix.
- Query OpenStreetMap Overpass for amenity=fuel within 7 km.
- Sort by haversine distance.
- Open the system maps app for navigation; FuelLog does not embed a map engine.
Overpass around:7000 · sort by haversine metres