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
A comprehensive guide on the key concepts and principles of the flespi analytics engine.
How to set up a calculator using the flespi analytics engine to aggregate device messages by day and count the total number of messages.