4 Replies Latest reply on Jul 27, 2018 10:50 PM by JacobAWeber

    Convert Batch Time string into Float32 in hours for calculations in AF


      Hello everyone!

      We have a batch time tag on our fermenters called TFT ("total fermentation time") that is created by the process control system as a string in the format "dd:hh:mm:ss". I am interested in converting this value into a float32 value in seconds that can be used directly for calculations over the time course of the run. So for example, we want to convert a TFT string value of "1:12:30:15" (which is 1 day, 12 hours, 30 minutes, 15 seconds) into a float32 value of 131,415 seconds. From there it would be very easy to convert to hours and perform productivity calculations. Does anyone have an idea of how to use a performance equation or analysis in Asset Framework to accomplish this?


        • Re: Convert Batch Time string into Float32 in hours for calculations in AF
          Rick Davin

          Hi Jacob,


          Very interesting question.  I tried my old tricks using Float but discovered a roadblock: Float("12:30:15") works but Float("1:12:30:15") does not.  Obviously it expects a time span less than a day, or more precisely less than 24 hours.  You can workaround it with more expressions to pull separate the number of days from the partial day:



          2018-07-27 15_44_10-Window.png


          Keep in mind this only works if your input string always contains days, even if its 0.  However, this really is a standard 24 hour day, so you will run into inaccuracies during a DST transition where the day may be 23 hours during Spring Forward or 25 hours during Fall Back.  This is not due to AF but rather a limitation of days in a time span string.


          In short, I pull the day value out and make it an integer with UOM of Day.  I then convert the remainder of the string to be a TimeSpan object, which I can then make a floating point number with UOM of seconds.  Then I can add the 2 together but I must be on the same UOM when doing that.


          Given the DST quirks inherent with your current setup, if at all possible I would recommend passing in the starting and ending time, so that you can skip all the string checks and just produce a time difference.  It would be a whole lot simpler and not give erroneous results during DST transitions.

          2 of 2 people found this helpful
          • Re: Convert Batch Time string into Float32 in hours for calculations in AF
            Steve Boyko

            Hi Jacob, I made an analysis that breaks your time string down into its separate parts and then converts each part into a number, and combines the results at the end.

            This is probably too complicated. Your best bet would be to use the ParseTime() function to convert your time string to a time value, then use the Hour(), Minute() and Second() functions to extract those portions and do the math at the end. You'd probably have to extract the day separately like I did above.

            1 of 1 people found this helpful