Mango JavaScript : Standard deviation

Hi ;
i would like to calculate the Standard deviation (Statistic function) and look back for 10 minute of data set.
How do i make it ? Any guidance would be appreciated.
thanks 
Hi kietisak pringsuwan, welcome to the forum
There's a decision to be made about whether your values are discrete samples or whether they need to be weighted by the time the value was held. If all values were held for the same amount of time, (like if you are polling on a fixed rate) then you shouldn't have to worry about that. This post assumes you're interested in discrete statistics.
You can find JavaScript standard deviation functions online elsewhere. They're going to take an array of numbers, usually, so you need to get the values and put them into an appropriate data structure:
var stdDevInput = [] var values = p.pointValuesSince(CONTEXT.getTimestamp()  600000); //10 * 60 * 1000 == CONTEXT.millisInPast(MINUTE, 10) for(var k = 0; k < values.length; k+=1) { stdDevInput.push( values[k].doubleValue ); } var stdDev = calculateStdDev( stdDevInput );
or slightly more efficiently,
var stdDevInput = [] PoitnValueQuery.query( [ p.getDataPointWrapper().getId() ], CONTEXT.getTimestamp()  600000, CONTEXT.getTimestamp(), false, function( value, index ) { stdDevInput.push( value.doubleValue ); }); var stdDev = calculateStdDev( stdDevInput );
This is assuming it's a numeric point. You could make this as a Meta point with a cron of
0 0/10 * * * ?
and then you could generate history for that point. You could modify the cron if you wanted one minute resolution on the previous ten minute standard deviation. You would probably want to define the function that calculates the standard deviation in a global script. 
Thanks phildunlap,
i am just new coming on this forum.
This is very helpful my question. i will try to do it.
Thank you again. 
Certainly! The one thing I forgot to say is that, in the script, "p" is the variable name I gave to the context point that is to be added to the meta point's context (the source point for the values).

Done very good solution
Thank you