3 Replies Latest reply on Feb 12, 2019 9:06 PM by TimCarmichael

    Any ideas on how to utilize time as a variable in a Pi Calculation?

    johnflaherty

      Hey everyone,

       

      I'm currently trying to make a Pi calculation to predict the end of day total water discharge at our plant using instantaneous flow rate, current total flow rate, and the amount of time left in the day.  Mathematically, I know what I am trying to do, and have gotten the formula to work in Excel, but I'm unsure of how to use "now" or "midnight" in a Pi formula.

       

      What I'm mathematically trying to do is:

       

      =(Instantaneous Flow Rate)*(Time Left Today)+(Current Total Discharge Volume)

       

      What's the best way to get the "Time Left Today" value?  Should I set up a different calculation that does that?  Are you able to manipulate time in a Pi Calculation?  Any kind of help would be greatly appreciated.

        • Re: Any ideas on how to utilize time as a variable in a Pi Calculation?
          kduffy

          Hi John,

           

          The way to reference the current time is '*', today at midnight is 't', and tomorrow at midnight is 't+1d'. Therefore, (time left today) would be 't+1d' - '*'.

           

          I've added this equation to a PI Calc dataset and trended it:

           

          And you can see that at midnight each day it spikes to 86400 (seconds), then slowly comes down to 0 for the next midnight:

           

          For your dataset, you can wrap this in a set of parentheses and multiple it by your flow rate value (adjusting the time units, of course, incase your flow rate is not in a volume/second), and then adding your current total. Something like this:

          'currentFlowRateTag'*('t+1d'-'*') + 'currentTotalTag'

           

          Kelsey

          2 of 2 people found this helpful
          • Re: Any ideas on how to utilize time as a variable in a Pi Calculation?
            tramachandran

            Time Expressions 't' and '*' denote midnight of today and current time respectively.

            If you are looking ahead then 't +1d' would be the upcoming midnight.

             

            Time left for today example:(There are also other ways to achieve the same result.)

            DaySec returns the number of seconds since midnight.

            86400 = 60*60*24 = Seconds in a day.

             

            You can apply any conversion on seconds to get the desired time units.

            2 of 2 people found this helpful
            • Re: Any ideas on how to utilize time as a variable in a Pi Calculation?
              TimCarmichael

              First, Kelsey's reply provides a visual demonstration of the principles of time manipulation.

              Second, Thyagarjan's example show the basics with an analysis.

              However, from having worked with system that are affected by daylight savings time or the return to standard time, I tend to stay away from 'magic numbers'; here 86400 is the number of seconds in MOST days - except when a time adjustment comes into play.

              To that extent, you would be better off using 't' for today and 't+1d' for the upcoming midnight.

              So: TimeLeft ==> ParseTime(Text('t+1d' - 't' - DaySec('*')))
                        't+1d' -'t' returns a timestamp; DaySec is a seconds value; create a text, then force it all to a timestamp
              SecondsLeft ==> Hour(TimeLeft) * 3600 + Minute(TimeLeft) * 60 + Second(TimeLeft)
                      this returns the number of seconds left in the day as a numeric value

              1 of 1 people found this helpful