• 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

    Totalized Sum of a point

    Scripting general Discussion
    2
    8
    3.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.
    • J
      jason81
      last edited by

      I'm looking to get the totalized sum of data points. I currently have 10 modbus points that I totalize in the controller at 1 minute, 1 hour and 24 hours. Then they reset themselves based on their run-times. So I would like to use a Meta Data point for each that would display the total of the sum of each for as long as mango has be trending them for, or at least a year. Like an odometer reading of each of the data points.

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

        Hi Jason,

        A couple of questions,

        1. Is there totalizing logic built into the PLC? Some of them are performing an actual integration. If there is, it's probably most accurate to use its result, if it's not, it may be easiest to use the point itself and do it all in Mango.
        2. Do the totalizing registers you have only get read when they're at their total value, or do they get totalled and read together, and you're interested in making Mango total when the PLCs register goes from 12345 kWh --> 0 kWh (as an example).

        Regardless, the logic will be something like.... (my is the variable name default for the meta point itself)

        if(my.value === undefined) return 0;
        return my.value + point.value;
        

        An approximation for a first integral looks like....

        if(my.value == undefined) return 0;
        var lastValueTime = point.lastValue(1);
        return my.value + lastValueTime.value * (point.time - lastValueTime.time)/1000 //Integrating in seconds
        
        1 Reply Last reply Reply Quote 0
        • J
          jason81
          last edited by

          I had tried using this "return Input_1.previous(DAY).sum;" from some examples to others in the forums and realized it gets the sum of the day. How would I rewrite this to get sum for more then just the day?. I just want to use the analytics that mango has on each point to get the value from.

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

            The syntax for the history function is two arguments, PeriodType and Periods. So, point.past(DAY, 10).sum would be a 10 day sum. The problem with doing some query like this (especially if some logic were hacked in to always query to the same start time) is that it will require a lot of data reading as the data set gets bigger. Perhaps that's acceptable if you're only running it on a cron once per day, but you'll still want to do my.value + point.past(DAY).sum such that you don't have to query "point"s entire history.

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

              Also, if I'm misunderstanding and you're reading the totalized register, you can probably do something like...

              return my.value + totalizer.past(DAY).maximumValue;
              

              and execute it on a cron. If you know that it will have its maximum value at one time or another, you could schedule the cron around then and lower the time period from DAY to whenever will capture that maximumValue.

              1 Reply Last reply Reply Quote 0
              • J
                jason81
                last edited by

                so far this is working "return Input_1.past(MONTH,12).sum;" I run this every minute to give the client the running total in real-time. But based on your statement of using to much HP in mango to calculate this when the statistic get larger, will this be too much for a mangoES to do for 10 to 20 points?

                0_1467817910422_upload-a15904f3-a2f5-4444-b4a8-db968f257049

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

                  That would depend on the density of the data queried. I'm guessing with a point like "One Minute Total" you have data for every minute, so you're asking Mango to calculate statistics over 60*24*365 = 525600 point values every minute. It's not efficient, by any stretch of the word. Whether or not the ES can handle it will depend on other load factors as well, but summing all the data every minute is not the solution I would use.

                  1 Reply Last reply Reply Quote 0
                  • J
                    jason81
                    last edited by

                    Thanks Phil,

                    I will be doing the totalization within the controller as your correct in stating the accuracy will be better and the load on the mangoES will stay normal.

                    Thanks

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