Using statistics object to get sum of max values
-
Is there a way of using the statistics object to get the sum of the maximum value or the last value per rollupinterval for the from/to period ?
-
You're asking about in scripts, yes?
Currently, no, you have to write the loop that queries your roll up periods and the compute as you wish off the values. The wrappers to get statistics in scripts are quite old. You've got me thinking about bringing the queries available through the API into scripts, though.
-
Hi Phillip,
In this vein I added a
PointValueQuery
object into scripting environments. It will enable you to do this task like,//Sum the max value from the data, rolled up into 1 days periods // With no quantizing the rollup period! If you want it to start at // the 0th second of the day you need to set the start time as such. var now = new Date().getTime(); var then = now - 86400000*20; total = 0; var callback = function(val) { total += val; }; //Query point with ID=1, could use p.getDataPointWrapper().getId() // for a context point var dataPointIds = [1]; //Twenty days of 1-day-maximum rollup, using ALL the whole statistics object is passed to the callback PointValueQuery.rollupQuery(dataPointIds, then, now, callback, MAXIMUM, 1, DAY); //print(total); return total;
There is also just a query() method for getting a stream of raw values in time order from some number of data points. This utility will be available in the next Core release. Here's the git issue: https://github.com/infiniteautomation/ma-core-public/issues/1234