New Aggregation Methods for Message Counter in Calculators
We've enhanced the calculator counter of type "message" with two powerful aggregation methods:
- aggregate - combines multiple messages into a single value with summated fields
- aggregate_by_field - groups messages based on the first field, then aggregates them into single values per group
These new methods are particularly useful for analyzing and summarizing device data by specific identifiers. For example, you can now easily track driver activity statistics:
{
"type": "message",
"name": "driver_stats",
"method": "aggregate_by_field",
"fields": [
"driver.id",
{
"name": "drive_time",
"expression": "position.speed > 0 ? (timestamp - previous(\"timestamp\")) : 0",
"aggregate": "summary"
},
{
"name": "distance",
"expression": "mileage()",
"aggregate": "summary"
},
{
"name": "trips_count",
"expression": "position.speed > 0 && previous(\"position.speed\") == 0 ? 1 : 0",
"aggregate": "summary"
}
],
"validate_message": "exists('driver.id')"
}
This configuration will:
- Group all messages by driver ID
- Calculate total driving time for each driver
- Sum up the distance traveled by each driver
- Count the number of trips initiated by each driver
The resulting interval JSON will contain an array of objects, each representing a unique driver with their activity metrics:
{
"driver_stats": [
{"driver.id": "D12345", "drive_time": 14520, "distance": 187.5, "trips_count": 5},
{"driver.id": "D67890", "drive_time": 9360, "distance": 112.8, "trips_count": 3}
]
}
This enhancement makes it much easier to create meaningful summaries of data grouped by specific identifiers without requiring complex post-processing.