The aggregation API lets you compute aggregated results on events, such as getting the count of all Events in a project, checking different descriptions of events in your project, etc.
Filters behave the same way as for the Filter events
endpoint.
In text properties, the values are aggregated in a case-insensitive manner.
aggregateFilter
works similarly to advancedFilter
but always applies to aggregate properties.
For instance, in an aggregation for the source
property, only the values (aka buckets) of the source
property can be filtered out.
This endpoint is meant for data analytics/exploration usage and is not suitable for high load data retrieval usage.
The Aggregates endpoint, as with all endpoints in the Events API, is subject to a request budget that applies
limits to both request rate and concurrency.
Please check Events resource description for more information.
Request aggregate to count the number of Events matching the filters. Default aggregate for the endpoint.
Response with a list of aggregation results.
The response for a bad request.
The response for too many requests (concurrency or rate throttling).
aggregate_type = client.events.aggregate(filter={"type": "failure"}) from cognite.client.data_classes.events import EventProperty type_count = client.events.aggregate_cardinality_properties(EventProperty.metadata) from cognite.client.data_classes.events import EventProperty type_count = client.events.aggregate_cardinality_values(EventProperty.type) from cognite.client.data_classes import filters from cognite.client.data_classes.events import EventProperty is_asset = filters.ContainsAny(EventProperty.asset_ids, 123) plain_text_author_count = client.events.aggregate_cardinality_values(EventProperty.type, advanced_filter=is_asset) count = client.events.aggregate_count() from cognite.client.data_classes import filters from cognite.client.data_classes.events import EventProperty is_workorder = filters.Equals(EventProperty.type, "workorder") workorder_count = client.events.aggregate_count(advanced_filter=is_workorder) from cognite.client.data_classes.events import EventProperty result = client.events.aggregate_unique_properties(EventProperty.metadata) print(result.unique) from cognite.client.data_classes.events import EventProperty result = client.events.aggregate_unique_values(property=EventProperty.type) print(result.unique) from cognite.client.data_classes import filters from cognite.client.data_classes.events import EventProperty from cognite.client.utils import timestamp_to_ms from datetime import datetime is_after_2020 = filters.Range(EventProperty.start_time, gte=timestamp_to_ms(datetime(2020, 1, 1))) result = client.events.aggregate_unique_values(EventProperty.type, advanced_filter=is_after_2020) print(result.unique) from cognite.client.data_classes.events import EventProperty from cognite.client.data_classes import aggregations agg = aggregations not_planned = agg.Not(agg.Prefix("planned")) is_after_2020 = filters.Range(EventProperty.start_time, gte=timestamp_to_ms(datetime(2020, 1, 1))) result = client.events.aggregate_unique_values(EventProperty.type, advanced_filter=is_after_2020, aggregate_filter=not_planned) print(result.unique)
{- "items": [
- {
- "count": 10
}
]
}