Timeseries Aggregations can be performed on the
dateTime field. So, you may group the records based upon the
dateTimefield and perform aggregations on them. Hypi object has the dateTime fields like
hypi_updated. You may use these fields for timeseries aggregations.
In this tutorial, we will work with the following schema to demonstrate how to use the
dateGranularity parameter to group numeric fields over time.
First is looking into the types that you want to aggregate.
For each type in our schema, we have two aggregations that we can perform on them. The first one is named "[our_type]" and the second one is named "[our_type]With". Check more about Aggregations here.
Looking at our schema, our aggregations will be
In this tutorial we will focus on using
actorRatingsWithsince it is the one that allows grouping data.
Now, let's get into some examples.
Let's retrieve the average
rating for each day for the actor with
hypi.id='actor1'. The aggregation looks like this.
Here we are using the
actorRatingsWith aggregation with the
groupBy parameter pointing at the field
hypi_created and passing the
dateGranularity: DAYS parameter to indicate that we want to group by the
hypi_created field and have the results grouped specifically by the days.
As for the data we want to be returned, we specify
avgand then the
groupValuesso we can know the value of the field we are grouping by -
Note that the groupValues field is a mandatory selection when using the dateGranularity parameter. This means it MUST be one of the fields you select. Otherwise you will receive an error.
The result will look like this.
As you can see, the
value field of the
groupValues, is displaying dates with different days and the average is calculated for that day.
Similarly we can use all the other aggregations:
Also, just as we did
DAYS for the
dateGranularity in this tutorial, you can use
SECONDS as for your needs.
In conclusion, aggregations using
dateGranularity boils down to:
- Using the right aggregation type - which is named "[your_type]With".
groupByto specify which field and
dateGranularityyou would like to group by. In our example
whereif you want to filter before calculating. (It is an ArcQL string. In our example -
- Adding the field that you want to aggregate. In our example
- Choosing what you want to calculate. In our example
groupValuesso you can see the value of the field that you grouped by in the result set.