[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''')
        .period(3h)
        .every(1h)
        .groupBy(time(1h), 't1', 't2')`
    |mean('sum')

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.

Thanks

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

var frequency = 15m 
var window_size = 2h

 var baseline = stream
   |from()
     .measurement('mm')
     .groupBy('t1', 't2')
   |window()
       .period(frequency)
       .every(frequency)
   |sum('count')
   |window()
       .period(window_size)
       .every(frequency)

var baseMean = baseline 
					|mean('sum')
						.as('mean')

var baseStddev = baseline 
					|stddev('sum')
						.as('stddev')
1 Like