I would like to have an aggregate method that returns the most extreme value. That means that the biggest eviation from the average value in the window.
So if I have 10 values [1,2,3,2,8,5,-10,3,5,6] I want -10. I tried to to it with reduce, but I cannot wrap my head around on how I get the average first and then having a conditional update.
My idea was something like this:
extreme: if math.abs(r.avg - r._value) > accumulator.extreme then math.abs(r.avg - r._value) else accumulator.extreme
but it feels also ver inperformant. But dont know what possibilities I have inside the recude and also dont know how to get the average first and add it like a column to every value in that window.
is there a good solution to this without querying all data twice or even multiple times?