How to calculate total mileage and other aggregate metrics with calculators?

Aggregating counter values by period.

Say, you have a calculator that detects trips and has a counter that calculates mileage for each trip. The next thing you often want to do is calculate daily_mileage to know how much time you were driving since the beginning of each day, total_mileage for larger periods, etc.

We have an “accumulator” type counter for that purpose. This counter can accumulate value between intervals and store accumulated resulting value in each interval.

We created two “accumulator” counters in our “route” calculator:

  • total_mileage: configured as name=total_mileage, counter=mileage.

  • daily_mileage: configured as name=daily_mileage, counter=mileage, reset_interval=day.

add accumulator type counters to calculator

And in the device Toolbox tab we get pretty intervals where each trip contains information about total mileage and daily mileage as a parameter:

check aggregate measures in toolbox

See also
Using advanced intervals aggregation capabilities to solve non-trivial tasks with flespi calculators.
Adding information about BLE beacons, DTC codes or visited geofences to the calculator's interval JSON?