[Solved]TickScript help ( finding mean and stddev of sum)

Hello everyone,

In the influx DB i have a field called ‘value’. I want to calculate the mean & stddev of sums ( of value ) from last n windows.

For example, lets say individual sum of value in last 3 hours is:
1 hour -> 20
2 hour -> 30
3 hour -> 40

So mean will be 45.

In the next window it should take the next three hours, find the individual sum and take the mean.
For example, lets say sum of value in last 3 hours is:
1 hour -> 30
2 hour -> 40
3 hour -> 60

So mean will be 75.

I was thinking i can do something like this:

    |query('''SELECT sum(value) FROM "db"."autogen".measurement''')
        .groupBy(time(1h), 't1', 't2')`

But the above tickscript is finding total sum of last n hours not n sums of 1h each.

Please let me know if there is cleaner way to get this kind of nested aggregation.


This works fine, but i had to use stream instead of batch node.

var frequency = 15m 
var window_size = 2h

 var baseline = stream
     .groupBy('t1', 't2')

var baseMean = baseline 

var baseStddev = baseline 
1 Like