Disclosure: I'm the developer of ScooterLog, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the app's source code. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.
ScooterLog keeps a charge history and trip log for connected electric scooters. One screen answers three questions a rider actually asks:
- How far does the charge I have now go?
- At my usual daily distance, when do I need to plug in?
- Is today's charge enough for a ride of N km?
All three rest on one number: kilometres per 1% of battery for this scooter and this rider. The app has two independent ways to estimate it, and one day they disagreed badly. This post is about the rule that decides which one the planner believes, and the planner built on top.
Two ways to get km per 1%
From charge cycles. Between two charges, the odometer rises by some km and the battery falls by some percent. Average that over charge cycles and you get km per 1%. Cycles are long, so small reading errors wash out. But a cycle is only as good as its two ends. A charge you only half saw, a missed reading at the top, or a long idle drain in the middle can make one cycle say something silly.
From rides. Each reconstructed ride has a distance and a battery drop. Sum the km over all rides, sum the percent, divide:
def ride_km_per_pct(trips): """km per 1% from this scooter's own rides; None until about 15% has been ridden.""" ridden = [t for t in trips if t.get('pct_used') and t['pct_used'] > 0] pct_sum = sum(t['pct_used'] for t in ridden) return round(sum(t['km'] for t in ridden) / pct_sum, 2) if pct_sum >= 15 else None Two choices in those four lines:
- Sum then divide, never average per-ride ratios. A 2 km ride that used 1% and a 30 km ride that used 25% are not equally informative. Averaging ratios gives the short ride as much say as the long one, and the battery reading's 1% steps make short-ride ratios jumpy.
- A floor of 15% ridden. Below that, return
Noneand say nothing. One or two short rides cannot produce a number anyone should plan with.
The day they disagreed
A comment in the code records the case: two odd charge cycles once claimed 2.48 km per 1%, while 45 rides on the same scooter said 1.0. Shown as range, that is the difference between about 248 km and about 100 km on a full charge. A planner built on the first number would have told someone a ride was fine when it was not.
Neither source is always right. Cycles are better once there are enough of them; rides are better when the cycles are few or broken. So the code makes them check each other:
def trusted_averages(avg, trips): """The charge-cycle averages when there are >= 3 cycles that agree with the rides (within 35%); otherwise the same figures from the rides, marked source='rides'.""" ride = ride_km_per_pct(trips) if avg and avg.get('cycles', 0) >= 3 and (not ride or abs(avg['km_per_pct'] - ride) / ride <= 0.35): return dict(avg, source='cycles') if not ride: return dict(avg, source='cycles', provisional=True) if avg else None out = dict(avg or {}, source='rides', km_per_pct=ride, full_range_km=round(ride * 100), pct_per_km=round(1 / ride, 2)) if avg: out['cycle_km_per_pct'] = avg['km_per_pct'] return out Read it as a decision table:
| Cycles | Rides (>= 15% ridden) | Result |
|---|---|---|
| 3 or more, within 35% of rides | yes | cycles |
| 3 or more | not enough yet | cycles |
| fewer than 3, or off by more than 35% | yes | rides (cycle figure kept alongside) |
| some | not enough yet | cycles, marked provisional |
| none | not enough yet | nothing |
The details that matter:
- The result says where it came from (
source), and a weak result says so (provisional). The screen can show "based on your rides" or hold back a confident sentence, instead of every number looking equally sure. - The losing figure is kept. When rides win,
cycle_km_per_pctstays in the output. When someone asks "why does it say 100 km when it said 248 last week?", the two numbers are both there to look at. - 35% is loose on purpose. Riding mode, load and weather move the true figure. The check is meant to catch a broken estimate, not a normal week.
The forecast
With a trusted km per 1% and the latest battery reading, the server works out the rest:
FORECAST_RESERVE_PCT = 10 usable = max(0.0, soc_now - FORECAST_RESERVE_PCT) f = dict(soc=soc_now, km_per_pct=kmpp, km_left=round(usable * kmpp), reserve_pct=FORECAST_RESERVE_PCT) if avg_daily_km: f['days_left'] = round(usable * kmpp / avg_daily_km, 1) f['charge_by_ms'] = now + int(f['days_left'] * 86400000) - A fixed 10% reserve. "km left" means km before 10%, not before 0%. Nobody wants a plan that ends at an empty battery.
- Daily distance from the odometer, per IST day for the last 14 days (highest minus lowest reading that day), summed and divided by the days actually covered, clamped to between 1 and 14. A new user with three days of data is divided by three, not by fourteen.
- "Plug in by" is just
km_left / avg_daily_kmdays from now. If that is under a day, the screen says "Plug in today" instead of a date.
The sentence shown is plain: About 46 km left before a 10% reserve · At your 18 km a day, plug in by Friday · based on 0.9 km per 1%. (Numbers made up for the example.) The last part is there on purpose: the person sees the assumption, and can judge it.
"Can I make a ride of N km?"
The ride check runs in the browser, as the person types a distance:
const need = Math.ceil(d / f.km_per_pct), left = f.soc - need; if (left >= f.reserve_pct) ok(`You have enough: you'd arrive with about ${Math.round(left)}%.`); else if (need + f.reserve_pct <= 100) bad(`Charge to at least ${Math.min(100, need + f.reserve_pct)}% first (needs ~${need}%).`); else bad(`Too far for one charge: it needs about ${need}%.`); Three outcomes, each with something to do:
- Enough: say what you'd arrive with.
- Not enough now, but possible on one charge: say the percent to charge to (need plus reserve), not just "no".
- Not possible on one charge at all: say so, instead of telling someone to charge to 100% for a ride that a full charge cannot cover.
Math.ceil on the percent needed is deliberate. Rounding the cost up and the arrival down keeps every error on the cautious side.
What it does not know
The planner only knows what the scooter's cloud reports, and readings can lag by a few minutes. It has no idea about a headwind, a passenger, or a steep road on today's route. The forecast is a reasonable default for a usual day, built from the person's own riding, and it shows its working so they can overrule it.
Takeaways
- When you have two estimates of the same quantity, make them check each other, and keep the loser in the output.
- Sum then divide; don't average ratios from samples of very different size.
- Refuse to answer below a minimum amount of data, and label weak answers as weak.
- Build reserves and rounding into the plan so every error falls on the safe side.
- Show the assumption next to the answer.
ScooterLog is on Google Play. It is a log and planner: it does not control the scooter and is not a security service. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.
AI Disclosure: this article was drafted and published by an AI agent on the developer's behalf, from the app's source code.
