This functionnality was introduced in ThingIn 2.7.0.
Using /find/aggregate/, it is possible to compute aggregate values on a set of avatar's properties.
This endpoint functions similarly to /avatars/find/. A "regular" ThingIn query is expected. To compute aggregate values, the query must make use of one or more operator in the following list (the list might be upgraded in future versions):
$max
-> compute the maximum of a property over a set of avatars
$min
-> compute the minimum of a property over a set of avatars
$sum
-> compute the sum of a property over a set of avatars
$avg
-> compute the average of a property over a set of avatars
In addition, the following operators will be required when creating an aggregation query:
$alias
-> Required. Sets an alias/name for the aggregate result
$property
-> Required. Sets the property on which the aggregation is computed
The example query below shows a complete use case for the different operator
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/max/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b",
"$max": {
"$property": "http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance",
"$alias": "monMaxA"
},
"$avg": {
"$property": "http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance",
"$alias": "monAvgA"
}
},
{
"$alias": "b",
"$max": {
"$property": "http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance",
"$alias": "monMaxB"
}
}
],
"view": {}
}
An aggregation is computed within a subquery, along with the avatars on which it should be computed.
For example in the previous query, the first subquery, which filters a set of avatars named "a" ($alias
), includes 2 aggregations:
$max
operator. To define how it is performed, the operator is followed by an object. This object requires the two operators $alias
and $property
.$avg
operator, and thus computes an average, on the same set of avatars.In both cases, the same property is used to compute both the maximum and the average ("http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance"
).
The next subquery, relies on the alias b
, that was first defined using an object property filter in the first subquery. Such avatars can also be used to compute aggregate values, using the same syntax.
Following is an example result of this query:
{
"count": 3,
"size": 3,
"items": [
{
"name": "myMaxA",
"value": 100.0,
"property": "http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance",
"function": "maximum"
},
{
"name": "myAvgA",
"value": 75.0,
"property": "http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance",
"function": "average"
},
{
"name": "myMaxB",
"value": 70.0,
"property": "http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance",
"function": "maximum"
}
],
"page_size": -1,
"index": 0,
"hidden": 0
}
The resulting payload only includes aggregate values if any was computed successfully. It does not return avatars.
Each item in the result payload corresponds to an aggregate JSON object, composed its name or alias (defined by the user with the $alias
operator), the property on which it was computed (defined by the user with the $property
operator), the aggregate value, and the function used which is the readable name for the operator.
TBD (this functionnality is in our 2022 roadmap)