How to calculate daily message count for devices?

How to set up a calculator using the flespi analytics engine to aggregate device messages by day and count the total number of messages.

One of the common tasks is to calculate the number of messages reported by devices per day, week, or month to understand which devices contribute the most to your channel performance or to the growing volume of your storage bill.

This task is easy to solve with flespi calculators.

In the calculator configuration, you specify the datetime selector and select the correct split interval - the basis on which to calculate the device messages stats. For example, to have daily per-device message stats, you will specify "split by day" in this field:

https://cdn.flespi.io/file/66751FCF0000F761361336FE1CD3A8E0040905B91D598B13

To calculate the total message count per interval, you add a simple counter of type='expression' with expression='1' and method='summary' to add up all messages for the day. In order to understand the device from which this interval is, you also add a counter of type='parameter' with name='ident' (you can add also 'device.id' or 'device.name' counters if identification by ID or name is preferable):

https://cdn.flespi.io/file/66765D0B0000F76026CC9C54B2AEC5A6D4AE24044A73BCC0

You may also add more counters if interested in some additional daily statistics for the device - for example, you may add a counter to calculate daily mileage, average speed, fuel consumption, and so on - everything depending on your needs and data available in device messages. You can enrich device messages with traffic volume by using webhooks that will repost connection statistics into device messages and after that add a counter to calculate per-device daily traffic.

Once you create the calculator, assign devices to it, wait a bit until all intervals are calculated and synchronized, and after that, you may access calculated daily statistics. You can access the latest daily statistics for the current day for each device from its CALCS tab by clicking on the black small rectangle on the timeline visible on the calculator's card:

https://cdn.flespi.io/file/66765EF50000F7617581FD8ACC7B1EBE7F56386D2D571F99

Alternatively, if you want to analyze devices in batch and compare which devices contribute the most to your channel performance (for example, if it is periodically blocked by message frequency), you can use ApiBox to show and sort the output of the REST API call result. You can do this by opening the next link, just do not forget to authorize into ApiBox by clicking login in the top-right corner and specify the correct ID for your calculator. In the link, we configured API call parameters to retrieve 'ident' and 'messages_count' fields for all 'last' intervals from 'all' devices assigned to the calculator. You just need to specify a calculator ID. Click on the 'eye' button to run the API call and you will receive the following output:

{
  "result": [
    {
      "ident": "<ident1>",
      "messages_count": 188
    },
    {
      "ident": "<ident2>",
      "messages_count": 215
    },
    …
  ]
}

After that, you may click on the table sign in the right-bottom corner of the popup window with the output of the REST API call result to switch to the table view:

https://cdn.flespi.io/file/667661B50000F761D496583EDD6489B41AE28F5A6A53D573

And click now on the 'messages_count' column header to order by the most frequently reporting devices:

https://cdn.flespi.io/file/667662100000F7609C09183E26F6E250C60BE0E474417EF7

Now you can export this table in CSV format to load into a spreadsheet of your choice, if desired.

P.S. You can easily aggregate intervals for multiple days or analyze different time range by specifying ‘all’ in the calc.device.intervals.selector instead of ‘last’ and timestamps of your choice in the ‘begin’ and ‘end’ fields inside the REST API call ‘data’ section.


See also
Restore your accidentally deleted items within a 30-day period.