Formula for calculating accumulation value of a data point in Meta point
-
I want to get an accumulated value of a data point when time goes by even though the data point is purged after a year. I suppose it can be done in meta points. For example, 0, 20, 20, 20. The result is 0, 20, 40, 60 in the data point's time stamp.
Thanks !
-
You can indeed to this with a meta point. Create a meta point, name it, and save it. Set the cron pattern to run when you want to aggregate the value, and after saving the empty meta point, add it to its own context. Now your script can simply be return [metapoint given context name].value + [other point].value and it will aggregate the second values at the interval specified by the cron job. Or, if you want to aggregate everything, set the meta point execution to context update.
-
Did you try it ? I tried it and it gave me weird results. p is a data point
1:00, 0
2:00, 0
3:00, 0.01
4:00, 0Results are :
2:00, 0.05
3:00, 0.08
4:00, 0.09I do not know why.
-
I have a solution for meta data initialization.
var t ;
t = p.value ;
return p.past(YEAR,1).sum + t ;My data only a month so one year is more than enough and then try to add to itself but I need data refresh for further test.
-
I would only run your initialization script once. After that modify your script to just get the new values. My script should work, but admittedly no I didn't try it (I don't know your configuration details very well).
Is the data at those times actually 0, or is your text renderer configured to make them appear zero? If your meta point is on context update, and your data point is noisy with values < .01, being noisy and not handled by the renderer, then I would expect your results. Aggregating values into a point is just a matter of a = a + b though, so I'm fairly certain the logic holds.
-
The data point is actual 0.
-
If I want to do "return a=a+b ;" and use context update. How can I make sure the context update only from "b" and not "a" or both ?
-
My conclusion is the meta point cannot calculate accumulation value in Mango.
-
I was mistaken: I thought there was a way to access which points had triggered the context update, but I see that I was incorrect.
To solve this, I would do the following:
Initialize:
- Create a meta point that is of type Numeric.
- Write a script, "return 0;" or use your method to initialize, return "p.past(YEAR,1).sum;"
- Run the script once or twice, so that the value of zero is recorded for the meta point. (use cron "0/1 * * * * ? *" to execute it every second it is enabled and record a value)
Configure:
- Add the point you wish to aggregate to the context, call "p"
- Add the meta point itself to the context, call "m"
- Write a script, "return m.value + p.past(MINUTE,1).sum;"
- Have the meta point run on a Cron pattern, perhaps "0 * * * * ? *" for every minute
- Enable the point.
If one minute is not good enough time resolution, you can modify it to be .past(SECOND, 15) and modify the Cron pattern to be "0/15 * * * * ? *"
So long as the number you choose in place of "15" is a factor of 60 (1,2,3,4,5,6,10,12,15,20,30,60) you can use it in both places and get uniform data.