Page 1 of 1
Running average/sum questions
Posted: Tue Dec 18, 2012 4:09 am
by Quentin
Hi, this is really basic but the answer eludes me - I want to make a module that creates a running average and a total sum- I have an integer value and a trigger for each time I want to collect a value to include in the sum and running average. I guess essentially I need to perform x=x+n each time the trigger goes.. Sorry if I am missing something obvious..
Thanks
Quentin
Re: Running average/sum questions
Posted: Tue Dec 18, 2012 7:13 am
by nix
How's this?->

- sum_average.png (38.89 KiB) Viewed 14645 times
Hope it works for you 8D
Re: Running average/sum questions
Posted: Tue Dec 18, 2012 6:45 pm
by Quentin
Thanks for the example, my problem that I don't want to build a huge array, just want to accumulate the sum of the values over a long period of time, sorry I realized after I posted that I should have explained this detail. Thanks again for the response..
Quentin
Re: Running average/sum questions
Posted: Tue Dec 18, 2012 7:29 pm
by trogluddite
Hi Quentin,
This example should do what you want without eating up unnecessary memory...
Re: Running average/sum questions
Posted: Tue Dec 18, 2012 8:51 pm
by Quentin
Thanks so much, that is exactly what I was in the process of trying to piece together in ruby- I am new to ruby so it's slow going for me- so your timing could not be better with that example..
Quentin