• 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

    How to implement a filter algorithm

    Mango Automation general Discussion
    2
    7
    3.3k
    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.
    • S
      sundeepgoel
      last edited by

      how can i implement a filtering algorithm to give me the median value from a set of sensor readings. i need this for some digital sensors which sometime give false readings - basically want to put all readings of say the last one minute in an array, sort it and then pick the median (middle value).

      is there an easy way to do this, any pointers will be appreciated...

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

        The best way to do this is with a meta point. Write the code necessary to get all your points into an array, here's some code I stole:

        var myArr = new Array();
        values.push(sens1.value)
        ...
        values.push(sensN.value)
         
        values.sort( function(a,b) {return a - b;} ); //works for our numeric values
         
        var half = Math.floor(values.length/2);
         
        if(values.length % 2)
           return values[half];
        else
           return (values[half-1] + values[half]) / 2.0;
        

        Hope that helps.

        1 Reply Last reply Reply Quote 0
        • S
          sundeepgoel
          last edited by

          @phildunlap said:

          The best way to do this is with a meta point. Write the code necessary to get all your points into an array, here's some code I stole:

          
          values.push(sens1.value)
          ...
          values.push(sensN.value)
          
          
          

          Hope that helps.

          Thanks for the quick response, a clarification please :-

          
          sens1.value 
          .... 
          sensN.value 
          
          

          wont this be value of n different points, i need to get the last n values of the same point into the array, how can i do that ?

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

            Oh, I apologize, I misunderstood your question.

            So 'sens' will be our point that we want the history of.

            values.push(sens.prev(MINUTE, 1).firstValue)
            values.push(sens.prev(MINUTE, 2).firstValue)
            values.push(sens.prev(MINUTE, 3).firstValue)
            ...
            values.push(sens.prev(MINUTE, n).firstValue)

            1 Reply Last reply Reply Quote 0
            • S
              sundeepgoel
              last edited by

              @phildunlap said:

              values.push(sens.prev(MINUTE, 1).firstValue)

              ...
              values.push(sens.prev(MINUTE, n).firstValue)

              thanks, this seems exactly what i need.

              one other request, where do i find documentation on what you have described above e.g. prev(MINUTE,1).firstvalue - what other functions etc are there which could be used ?

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

                Most of the available data is documented in the help question mark on the page. I went to the source code for the 'firstValue' attribute, which is not listed in the help document. The public repo can be seen at www.github.com/infiniteautomation

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