• 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

    Daily Average of a Data Point

    User help
    2
    7
    2.1k
    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.
    • M
      mihairosu
      last edited by

      Forgive my ignorance of Javascript, but can anyone give me a script example for how to get an average of a data point for each day (with a meta data point)?

      I'm looking to turn Outdoor Temperature Readings to Average Daily Outdoor Temperatures.

      I appreciate it!

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

        Hi Mihai,

        I would use a Meta Point with cron on pattern 3 0 0 * * ? which will execute on the third second of every day, then, use Mango's built in book-ending statistics function, previous(), to compute that. So,

        return p.previous(DAY).average;
        
        1 Reply Last reply Reply Quote 0
        • M
          mihairosu
          last edited by

          Why are you recommending 3 0 0 * * ? and not 3 0 0 * * * as the cron pattern?

          From my little research the ? will be substituted with the value of when it first started, which would mean it would only run in the year 2016. Am I wrong?

          Otherwise I'll give this a test!

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

            You may be correct for some implementations, but we use the CronExpression from Serotonin Timer, which from my brief reading treats ? and * more or less the same. This seems to make sense to me, since the built-in patterns will use ? in the sixth position.

            I think the sixth position is "Day Of Week" and can be specified 0-6 or SUN-SAT and the seventh position, one that can be omitted, is the year.

            1 Reply Last reply Reply Quote 0
            • M
              mihairosu
              last edited by

              You are correct about the cron pattern. I did make one change though, in that I would like to do it right before the day ends.

              The reason is that if the previous day is calculated on the following day the data value is entered on the calculated day. Then the average daily temperature would always be a day off.

              In any case, my main reason for wanting to do this is to also get the History. However, when I run the "Generate History" I get data points every 7 seconds, which is the rate of actual outdoor temperature sensing.

              So how can I also go back in history and get the daily average temperature entered in the data point?

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

                You will want to use past() then to avoid the time alignment performed by previous(). Consider,

                57 59 23 * * ?

                return p.past(MINUTE, 1440).average
                

                To have the history generation only use the cron, you need to uncheck the context update box for the variable.

                1 Reply Last reply Reply Quote 0
                • M
                  mihairosu
                  last edited by

                  That made it work.

                  I double checked the values, by manually averaging some points in Excel and they are very close.

                  I also attached a pretty picture as more proof =D

                  .Thank you Phil.

                  0_1462290296776_avg.png

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