Overview
The statistics aggregation node allows you to filter on a set of items, in the same exact way as any other AQS Root Node. The result of a statistics aggregation is an attribute. It is one single attribute only when no grouping is applied, otherwise it is many attributes, one per group.
API users utilising the following AQS statistics endpoint will need to ensure they use StatisticsAggregation instead of MathAggregation (deprecated), which will continue returning the same results, as it did with MathAggregation. Any existing integrations using the AQS statistics code will need to be updated to use StatisticsAggregation AQS item.
Operation types
The operation is run on the specified attribute of all the items that match the AQS query. A statistics aggregation root node thus needs to know which entity to act on (in the same way as the other root nodes), the attribute to consider and the operation to execute.
The response model AqsStatisticsAggregationWebResponse
only returns paginated results instead of duplicating information, for example, result
and the groups
properties (previously marked as Obsolete
) will be removed as part of this change.
StatisticsAggregation supports the following aggregation types:
- Sum: Only number attributes
- Average: Only number attributes
- Count: No attribute can be passed, it will fail if any attribute is specified
- Max: Number, Date, Time and DateTime attributes
- Min: Number, Date, Time and DateTime attributes
- StandardDeviationPopulation: Only number attributes
- StandardDeviationSample: Only number attributes
- BoundingBox: Only geometry attributes
This node supports GeoJson Aggregation. You can aggregate on GeoJson geometry attributes, not only Number and DateTime.
The following examples illustrate the use of each of the operations types:
The following is an example to find the Min value for the heights (where set) of trees in the Live collection.
{
"type": "StatisticsAggregation", // "The root node type"
"properties": {
"dodiCode": "designInterfaces_trees",
"attributeCode": "attributes_treesHeight",
"collectionCode": "Live",
"aggregationType": "Min",
},
"children": [
{
"type": "Exists",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_treesHeight" // only aggregate where the height is set
}
}
]
}
]
}
Sum all the heights (where set) of all the trees in the live collection.
{
"type": "StatisticsAggregation", // "The root node type"
"properties": {
"dodiCode": "designInterfaces_trees",
"attributeCode": "attributes_treesHeight",
"collectionCode": "Live",
"aggregationType": "Sum",
},
"children": [
{
"type": "Exists",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_treesHeight" // only aggregate where the height is set
}
]
}
]
}
Average the heights (where set) of all the trees in the live collection
{
"type": "StatisticsAggregation", // "The root node type"
"properties": {
"dodiCode": "designInterfaces_trees",
"attributeCode": "attributes_treesHeight",
"collectionCode": "Live",
"aggregationType": "Average",
},
"children": [
{
"type": "Exists",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_treesHeight" // only aggregate where the height is set
}
]
}
]
}
Count the heights (where set) of all the trees in the live collection
{
"type": "StatisticsAggregation", // "The root node type"
"properties": {
"dodiCode": "designInterfaces_trees",
"collectionCode": "Live",
"aggregationType": "Count",
},
"children": [
{
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_treesHeight" // only aggregate where the height is set
}
]
}
]
}
Find the Max value for the heights (where set) of trees in the Live collection
{
"type": "StatisticsAggregation", // "The root node type"
"properties": {
"dodiCode": "designInterfaces_trees",
"attributeCode": "attributes_treesHeight",
"collectionCode": "Live",
"aggregationType": "Max",
},
"children": [
{
"type": "Exists",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_treesHeight" // only aggregate where the height is set
}
]
}
]
}
For example, you can get a bounding box of all job items in a certain design by aggregating on their geometry attribute using BoundingBox type.
{
"type": "StatisticsAggregation",
"properties": {
"dodiCode": "designs_exampleJobs",
"attributeCode": "attributes_itemsGeometry",
"aggregationType": "BoundingBox",
"collectionCode": "Live"
}
}
{
"page": 1,
"pageSize": 20,
"results": [
{
"value":{
"attributeCode": "attributes_fake",
"value": {
"type": "Polygon",
"coordinates": [
[
[
-2.821426391601562,
52.34876318198809
],
[
-2.821426391601562,
53.51475612845124
],
[
-1.4941406250000093,
53.51475612845124
],
[
-1.4941406250000093,
52.34876318198809
],
[
-2.821426391601562,
52.34876318198809
]
]
]
}
}
}
]
}
Grouping of statistics results
In addition to the above new operation types, you can now group statistics results using groupBy
property tag.
For example, to get the information about the total cost of job work items per job you can execute a Sum aggregation on designInterfaces_jobWorkItems
using the attribute attributes_jobWorkItemsEstimatedCost
and group the results per the parent job attribute attributes_jobsJobWorkItems
.
{
"type": "StatisticsAggregation",
"properties": {
"dodiCode": "designInterfaces_jobWorkItems",
"attributeCode": "attributes_jobWorkItemsEstimatedCost",
"aggregationType": "Sum",
"groupBy": "attributes_jobsJobWorkItems",
"collectionCode": "Live"
}
}
{
"page": 1,
"pageSize": 20,
"results": [
{
"key": "5c8d57d6ff5c1311d451d663",
"value": {
"attributeCode": "attributes_fake",
"value": 11
}
},
{
"key": "5c8bf378ff5c1305544f07f1",
"value": {
"attributeCode": "attributes_fake",
"value": 0
}
},
{
"key": "5cc6b5f5ff5c130cd4b3be32",
"value": {
"attributeCode": "attributes_fake",
"value": 358.62
}
}
...
]
}
This will return the job item id as a result key with a value representing a sum of all of its job work item estimated costs.