How to create a counter meta point
-
I have a datapoint that updates everytime a watthour is consumed. The value of this datapoint itself isn't relevant in this case, only the number of times it has been updated.
What I would like to do is to create a metapoint that will increment on every update so I have the total of consumed watthours. I can do that by putting the datapoint in the context so that the script will execute on an update.
If I want to increment the metapoint, I need to put the metapoint itself in the script context as well to to be able to access the current value. However that will trigger the script to be executed again when the script returns the incremented value, so that doesn't work.
Currently I use the count function from the statistics object returned by past() to get the job done, but that seems to iterate over all values everytime and thus takes a lot of work. That doesn't seem to be the right way.
-
http://mango.serotoninsoftware.com/forum/posts/list/334.page#1554 might answer your question
-
That will work if the updates are all "1". If you want to count updates for a point that does not necessary always have the value "1", you'd be stuck.
Would be it better if meta points excluded themselves from context update events? I can't think of a case where updating on its own update is not a mistake.
-
It never occurred to me that a meta point script would be run again after its own update.
-
Yeah. I've never had a point use itself with context update before. Just timed updates.
-
I think it would indeed be best if the meta point didn't update upon a change of itself.
I can think of other interesting uses if you can add the meta point value itself to the script context if it didn't update upon it's own change. You could for instance have metapoint m be an exponential smoothed version of data point p with smoothing factor x, like this: m(N) = x*p(N-1) + (1-x)*m(N-1)