• 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

    Meta point/ECMA script help

    Scheduled Pinned Locked Moved User help
    6 Posts 2 Posters 1.7k Views 1 Watching
    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.
    • jeremyhJ Offline
      jeremyh
      last edited by

      Hi,

      Quick/simple question, I hope.

      I have a data point which is a lifetime kWh counter. It does not reset to 0 or run backwards. It is an energy meter and I wish to record the total kWh consumed per day, updating every hour or so.

      I would like to create a meta data point which, when updated, shows the 'daily progress' of that counter.
      In other words, I want to subtract the latest reading from the first reading today (or last one yesterday).

      If I use this method:

      return p214.value - p214.ago(DAY);
      

      Then I get the consumption over the last 24 hours, which is not what I want.

      Any ideas?

      Cheers

      (Bonus second question - once the daily delta is calculated, only one record needs to be retained for that day - the last one. What would be the best way to accomplish that?)

      1 Reply Last reply Reply Quote 0
      • jeremyhJ Offline
        jeremyh
        last edited by

        OK, I think I have gotten it working using this:

        return (p214.value)-(p214.prev(DAY).lastValue);
        
        

        For some reason, value.prev(DAY) returns as NaN, when I think it should do the same thing.

        1 Reply Last reply Reply Quote 0
        • JoelHaggarJ Offline
          JoelHaggar
          last edited by

          Hi Jeremy,

          This is a pretty common use-case for Mango.

          To calculate a daily total you can use the exact script that you posted except only run it on the last second of the day with a cron patter like this: 0 59 23 * * ?

          To have a daily accumulation that starts as 0 every day and counts up you could use a script like this, which could run on context update:

          return (p.value - p.previous(DAY) .maximumValue)
          

          You could then set the above Meta Data Point to log on a 1 day interval the maximum value and I think this will accomplish what you want.

          I would recommend reading in the help popup for Meta Data Points about the difference between .ago and .previous as this might help explain it a bit further.

          Hope that helps.

          Joel.

          1 Reply Last reply Reply Quote 0
          • jeremyhJ Offline
            jeremyh
            last edited by

            Snap!
            Got it just as you were writing that post I think Joel. Thanks for the reply though.

            I've set it to run hourly, which for the time being is an acceptable tradeoff between logging loads of redundant points, and having the information available on the current day.

            Would it be possible to use the Scripting data source to delete all the points for the current or previous day, bar the last one?

            1 Reply Last reply Reply Quote 0
            • JoelHaggarJ Offline
              JoelHaggar
              last edited by

              I don't think the scripting data source could be used to delete past logged values but that's an interesting idea.

              I think it should work fine to just log the max once per day even if you are updating every hour. You could increase the default cache size for the point to 24 so then it will keep 24 hours of history in the cache so you can still chart it for that day.

              Joel.

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