• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Mango JavaScript : Standard deviation

    Scripting general Discussion
    2
    5
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kietisak pringsuwan
      last edited by kietisak pringsuwan

      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

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by phildunlap

        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.

        1 Reply Last reply Reply Quote 0
        • K
          kietisak pringsuwan
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            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).

            1 Reply Last reply Reply Quote 0
            • K
              kietisak pringsuwan
              last edited by

              Done very good solution
              Thank you

              1 Reply Last reply Reply Quote 0
              • First post
                Last post