Recently I successfully implemented the basic statistical calculations (min/max/average) by creating a Meta data source, scripting the data-point and then publishing via Modbus.
I have had some difficulty putting together a script for calculating the standard deviation. The system returns a black question mark diamond icon as a data point place holder, and continues to fill the historical values table unlike when there is a bad/no data source. I am not sure whether the error icon is indicative of NaN, out of range, etc (new to mango).
I tested the script incrementally and only towards the end of the calculation does this error occur, maybe a problem with the division & square root being to small?
If anyone could provide clarification on this error icon, or point me towards the right documentation section that would be very helpful!
Thanks!
Script is below:
var average = p6167.past(MINUTE, 5).average; //Get Average
var valueArray = p6167.last(300); //Get Last 300 Points(5 min)
var Power_StdDev = 0; //reset std devation
for (var i=0; i<300; i++){ //loop through points
var value_i = valueArray.get(i).value; //get array(i) value
var DiffSquared = (value_i - average)^2; //take the diff & square
var sumDiffSquared = DiffSquared + sumDiffSquared; //sum of squares
var sumDiffSQuotient = sumDiffSquared/299; // divide by n-1
Power_StdDev = Math.sqrt(sumDiffSQuotient); // set std to calculated value
}
return Power_StdDev; // return to numeric meta data point