Meta point to return max value of multiple points over period
-
Hi
I have eight temperature points, and I'd like to make a meta point script that returns the highest recorded temperature that was recorded in the past 5 minutes amongst any of the eight points.
//return p367.past(MINUTE, 5).maximumValue;
Gets me the max value for one point, but:
//return max(p367.past(MINUTE, 5).maximumValue, p291.past(MINUTE, 5).maximumValue);
returns "Script error: ReferenceError: "max" is not defined in at line number 1 in at line number 1"
I have the sstGlobalScripts 1.4.5 module installed so I'm not sure why max() isn't available.
Any help appreciated. Thanks!
-
I've never done this but I would first try creating an array of the values and trying something like in this post: http://stackoverflow.com/questions/1379553/how-might-i-find-the-largest-number-contained-in-a-javascript-array
Let me know if you get that to work. If not we can do some experimenting on our side to come up with something that would work. Something to look forward to in version 2.6 is you can do a query for points and values in the script and I'm pretty sure you could query for the max value which would make this quite easy.
-
Joel, your link points to this thread!
-
Sorry about that. I've updated the post to use this link: http://stackoverflow.com/questions/1379553/how-might-i-find-the-largest-number-contained-in-a-javascript-array
-
Thanks Joel,
I got the meta point working with an array by using the the following (IB1 etc. are of course my script context points) :
var period = 5 return Math.max.apply(Math,[ IB1.prev(MINUTE, period).maximumValue, IB4.prev(MINUTE, period).maximumValue, IB7.prev(MINUTE, period).maximumValue, IB10.prev(MINUTE, period).maximumValue, IB13.prev(MINUTE, period).maximumValue, IB16.prev(MINUTE, period).maximumValue, IB19.prev(MINUTE, period).maximumValue, IB22.prev(MINUTE, period).maximumValue ]);
Here is an expanded version:
//this meta point returns the highest temperature recorded by any of the points over a one hour period. //over how many minutes? var period = 5; //get the maximum value for each point over the given period var IB1 = p367.past(MINUTE, period).maximumValue; var IB4 = p79.past(MINUTE, period).maximumValue; var IB7 = p342.past(MINUTE, period).maximumValue; var IB10 = p317.past(MINUTE, period).maximumValue; var IB13 = p342.past(MINUTE, period).maximumValue; var IB16 = p266.past(MINUTE, period).maximumValue; var IB19 = p241.past(MINUTE, period).maximumValue; var IB22 = p216.past(MINUTE, period).maximumValue; //load into array var array = [IB1, IB4, IB7, IB10, IB13, IB16, IB19, IB22]; //return largest return Math.max.apply(Math, array);
I set the meta point to update on cron and my cron expression is: **0 0/5 * 1/1 * ? * **
The meta point history generation seems to be very slow. Generating ~5 days worth took about 15 minutes.
I have also ended up with these odd spikes, I haven't yet figured out why that's happening:
-
Using 'prev' instead of 'past' didn't fix the spikes issue.
My guess would be that the spikes occur when a point in the array has not changed within that 5 minute window. However, I'm not sure why that is, as it should result in no value for that datapoint, which shouldn't affect the maximum. Instead it behaves like the point has a value of about 27.1.