<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Standard Deviation Calculation - Meta Data Point Error]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">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).</p>
<p dir="auto">I tested the script incrementally and only towards the end of the calculation does this error occur, maybe a problem with the division &amp; square root being to small?</p>
<p dir="auto">If anyone could provide clarification on this error icon, or point me towards the right documentation section that would be very helpful!</p>
<p dir="auto">Thanks!</p>
<p dir="auto">Script is below:</p>
<pre><code>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&lt;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 &amp; 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
</code></pre>
]]></description><link>https://forum.mango-os.com/topic/4416/standard-deviation-calculation-meta-data-point-error</link><generator>RSS for Node</generator><lastBuildDate>Wed, 20 May 2026 00:32:03 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/4416.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Aug 2019 01:14:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Standard Deviation Calculation - Meta Data Point Error on Mon, 07 Oct 2019 00:36:32 GMT]]></title><description><![CDATA[<p dir="auto">Thanks guys, appreciate the help. Managed to get it all working, the error handling was definitely a good call.</p>
]]></description><link>https://forum.mango-os.com/post/23796</link><guid isPermaLink="true">https://forum.mango-os.com/post/23796</guid><dc:creator><![CDATA[HSAcontrols]]></dc:creator><pubDate>Mon, 07 Oct 2019 00:36:32 GMT</pubDate></item><item><title><![CDATA[Reply to Standard Deviation Calculation - Meta Data Point Error on Sat, 24 Aug 2019 01:11:20 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Phil, just thought I could give my ten cents whilst out and about.</p>
]]></description><link>https://forum.mango-os.com/post/23289</link><guid isPermaLink="true">https://forum.mango-os.com/post/23289</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Sat, 24 Aug 2019 01:11:20 GMT</pubDate></item><item><title><![CDATA[Reply to Standard Deviation Calculation - Meta Data Point Error on Fri, 23 Aug 2019 21:25:15 GMT]]></title><description><![CDATA[<p dir="auto">Good catches, Fox!</p>
<p dir="auto">Hi HSAcontrols, welcome to the forum!</p>
<p dir="auto">I think Fox may have set you on the right path for where the calculation may be going wrong. The only think I have to add is that the black question mark diamond is indeed a NaN value being rendered. I'd perhaps have to see a screenshot to be sure, but that's what it sounds like.</p>
<blockquote>
<p dir="auto">I tested the script incrementally and only towards the end of the calculation does this error occur, maybe a problem with the division &amp; square root being to small?</p>
</blockquote>
<p dir="auto">NaN is a very infectious value. If one of the point values you're looping over is NaN, then doing any mathematical operation on it or with it will also produce NaN. You could check with an <code>if(!isNaN(value_i)) {}</code> around the calculations for DiffSquared and sumDiffSquared</p>
]]></description><link>https://forum.mango-os.com/post/23287</link><guid isPermaLink="true">https://forum.mango-os.com/post/23287</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 23 Aug 2019 21:25:15 GMT</pubDate></item><item><title><![CDATA[Reply to Standard Deviation Calculation - Meta Data Point Error on Mon, 26 Aug 2019 07:39:22 GMT]]></title><description><![CDATA[<p dir="auto">Your power calculation is incorrect at first glance, use Math.pow(num,exp).<br />
The ^ I believe is treated as a bitwise exclusive OR.<br />
Also did the mango JavaScript provide any info as there is statistical analysis available.<br />
Look at the help icon and have a glance there.</p>
<p dir="auto">Also:</p>
<pre><code>var sumDiffSQuotient = sumDiffSquared/299;
Power_StdDev = Math.sqrt(sumDiffSQuotient);                  // set std to calculated value
    
</code></pre>
<p dir="auto">Take these outside of the loop!</p>
<pre><code>Var sumDiffSquared=0;
for...
{..}
var sumDiffSQuotient = sumDiffSquared/299;
Power_StdDev = Math.sqrt(sumDiffSQuotient);                  // set std to calculated value
    
</code></pre>
<p dir="auto">You reset their values every time your for loop runs, you may as well wait till after the loop since you're not adding those calculations inside the loop and only run them once.</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/23280</link><guid isPermaLink="true">https://forum.mango-os.com/post/23280</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Mon, 26 Aug 2019 07:39:22 GMT</pubDate></item></channel></rss>