• 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 calculate an accumulating or running total on a point.

    Scripting general Discussion
    2
    5
    2.0k
    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.
    • raylatbasixR
      raylatbasix
      last edited by raylatbasix

      I'm guessing this must be obvious to others, but for the life of me, I cannot find a way to calculate a running total.
      I have an analog point logged once a minute, and just want to create a separate meta script point to simply add each 1 minute sampled analog value to a running total. Basically a totalizer that just accumulates.

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

        Hi raylatbasix,

        I would solve that using the ago(periodType, quantity) function. ago() will return the value that existed before the time. The differences with the pointValueBefore(time) is ago returns 0 should there be no alue before it (but that won't affect this)

        The other part of the puzzle is that Meta points are always in their own contexts with the meta point's variable name (by default, "my")

        So, update event: "Start of minute" script body: return my.value + p.ago(MINUTE);

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

          If you wished to accumulate all values instead of just the logged averages, you could more simply have your script body be

          return my.value + p.value;

          The update event would still be start of minute to get an instant instead of the average. Or you could do a context update accumulator, but presumably there is a reason you're only wanting to accumulate the minute average, or I am misunderstanding.

          1 Reply Last reply Reply Quote 1
          • raylatbasixR
            raylatbasix
            last edited by

            Hi Phil,
            Thank you, that took care of it. I had everything right, but the meta points "my" variable. I was trying to declare my own variable, and it was not working.

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

              Glad to hear it!

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