Automatically translate this page?

Interval counters — calculate interval messages

Interval counters are used to calculate specific parameters for each interval

Once the analytics engine has split device messages into intervals based on custom logic, it's time to calculate all messages within each interval and extract valuable information. This can be done with counters

A standard interval message is represented as a JSON object with a set of fields, where "begin", "end", and "duration" (also "id" for automated analytics mode) are always present and other fields appear only when a counter with such name is defined during the call:

  "begin": 1490347944,
  "end": 1490347948,
  "duration": 4,
"mileage": 190.2,
"work_hours": 0.12345,
"max_speed": 120,
"positions": [{"t":1490347944, "lat":53.0923, "lon":27.12}, {"t":1490347944, "lat":53.0923, "lon":27.12}, ...]

Here "mileage", "work_hours", "max_speed", and "positions" fields are defined by counters. Each counter configuration contains the "name" field specifying the name under which the counter will be placed into the interval's JSON.

flespi defines the following types of counters:

  • expression — the value of a counter is the result of expression evaluation for each message in the interval. Special "method" field defines how these results will be combined into one number: 
    • first — take value from the first countable message;
    • last — take value from the last countable message;
    • average — take an average value;
    • minimum — take a minimum countable value;
    • maximum — take a maximum countable value;
    • summary — add all countable values;
    • difference — take a sum of all differences between neighbor messages;
    • duration — evaluate the expression as boolean and count duration for all non-zero results;
  • dataset — the value of a counter (like "positions" in the sample above) is an array of objects which field names and values are defined by the schema. The values for the fields are also evaluated as an expression. Dataset counter is used when you need to access each message fields and present them in an interval usually in a compressed form, for example, to draw a movement track on the map or display certain inputs on a state chart.
  • route — dump "position.latitude" and "position.longitude" parameters for each message within the interval into Google-encoded polyline algorithm format. This is a compressed string-based coordinates format with plenty of libraries to decode it into latitude/longitude pairs.
  • datetime — print the user-formatted begin or end time according to specified timezone into the interval.

Each counter also contains a "validate_message" extra option, which may check whether message suitable for the counter and skip some messages. This can be used for example to skip all messages with high HDOP or low quantity of locked satellites.

If you need more counter types, please contact us.

Analytics system is being in active development at the moment and all REST API calls described here are subject to change. If you intend to use this functionality for commercial projects, please let us know so we can make sure to notify you before applying incompatible API changes

See also
How to calculate vehicle engine hours on a daily basis
Instructions on how to use flespi analytics engine to extract trips from raw device messages