Aggregates in InfluxDB

Hello,
i’m new on influxDB.
I want to store on InfluxDB raw given by a power absorption sensor and have the W/h graph.
There is some function for InfluxDB to make aggregates per hour?

Hello,
I am playing exactly the same game today and I come up with this in flux:

|> aggregateWindow(every: 5m, fn: max)

which aggregates my 1min measurements into 5min data based on the max value…

hope it helps,
cheers,
Tom

Wh calculation Is quietly more difficult because area given from time and Watts in the hour

How does your query look like?

Hello @marcolettieri,
You can use a task in InfluxDB to perform calculations and store the result in a new measurement every hour.
If you can share some example data and your expected output I can share the Flux that will help you achieve what you want. I just need more detail around what you’re trying to accomplish.

The Wh is the area given from the time and W.
The formula is:
Wh = Wh +( ((new sample timestamp - old sample timestamp)/ MILLIS_PER_HOUR) * new sample W)

I can do as you suggested @Anaisdg but i will lose all raw samples

Hello @marcolettieri,
I only suggested that because I thought that’s what you were interested in. However, it’s also worth nothing that writing a task to aggregate your data and storing the values in a new measurement doesn’t mean that you’ll lose your raw samples. You can have both!
Again it’s hard for me to give you a flux query without some input sample data which allows me to understand the shape of your data. For example I don’t know how you’re calculating Wh.
However, I would suggest using the difference() function:
https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/difference/
And then using the map function:
https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/map/
After selecting a bucket and a range and filtering your query might look like:

data = from(...)
           |> range(start: ....) 
           |> filter(....)
    
diffData = data 
|> difference() 

join(tables: {diffData: diffData, data: data}, on: ["_time", "_field"], method: "inner")
|> map(fn: (r) => ({ _value: r._value_diffData/r._MILLIS_PER_HOUR_data*r._value_data }))

You might also have to join your data.
https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/join/