Automic Workload Automation

 View Only
  • 1.  Automic Script to convert seconds to HH:MM:SS format

    Posted Oct 09, 2013 01:10 PM
    This example converts the Statistics Duration which is returned in seconds to HH:MM:SS readable format but could be used for any situation where this type of conversion is required. :set &sss = GET_STATISIC_DETAIL(&UC_CAUSE_NR,DURATION) :define &f_hrs#,float :define &f_min#,float :define &s_hrs#,string :define &s_min#,string :define &u_hrs#,unsigned :define &u_min#,unsigned ! Hours :set &f_hrs# = DIV(&sss,3600) :set &s_hrs# = CONVERT(string,&f_hrs#) :set &pt# = STR_FIND(&s_hrs#,".") :set &pt# = SUB(&pt#,2) :set &u_hrs# = MID(&s_hrs#,2,&pt#) ! Minutes :set &xhrs# = MULT(&u_hrs#,3600) :set &tmp# = SUB(&sss,&xhrs#) :set &f_min# = DIV(&tmp#,60) :set &s_min# = CONVERT(string,&f_min#) :set &pt# = STR_FIND(&s_min#,".") :set &pt# = SUB(&pt#,2) :set &u_min# = MID(&s_min#,2,&pt#) ! Seconds :set &xmin# = MULT(&u_min#,60) :set &xhrmn# = ADD(&xhrs#,&xmin#) :set &sec# = SUB(&sss,&xhrmn#) ! Format results :set &s_hrs# = FORMAT(&s_hrs#,'00') :set &s_min# = FORMAT(&s_min#,'00') :set &sec# = FORMAT(&sec#,'00') :set &runtime# = &s_hrs#:&s_min#:&sec# :print Elapsed Time: &runtime#


  • 2.  Automic Script to convert seconds to HH:MM:SS format

    Posted Mar 06, 2014 04:59 AM
    Is the DIV-function above version 8 now correct? In version 8 was the result for div(1800,3600) 1 instead of 0. The DIV-function has an implicit rounding. Result of the following script.
    h=1:r=1800 sss=0000000000001800:div=0000000000000000:mod=0000000000001800
    This is really bad for calculating dynamic holidays by the easter formula.
    :set &sss# = 1800 :set &divisor# = 3600 :set &hrs# = div(&sss#,&divisor#) :set &rest# = mod(&sss#,&divisor#) :set &hrs# = format(&hrs#) :set &rest# = format(&rest#) :print "h=&hrs#:r=&rest#" :set &rest# = &sss# :set &mod# = 0 :set &div# = 0 :while &rest# > 0 :  if &rest# > &divisor# :    set &div# = add(&div#,1) :    set &rest# = sub(&rest#,&divisor#) :  else :    set &mod# = &rest# :    set &rest# = 0 :  endif :endwhile :print "sss=&sss#:div=&div#:mod=&mod#"


  • 3.  Automic Script to convert seconds to HH:MM:SS format

    Posted Mar 07, 2014 12:01 PM

    The implicit rounding is due to the implicit typing.  If no type is defined all variables are treated as strings - unsigned with truncated decimal values.  Use :DEFINE to explicitly define a type and you should get the expected results.

    :set &sss# = 1800
    :set &divisor# = 3600
    :define &f_hrs#,float
    :set &f_hrs# = div(&sss#,&divisor#)
    :set &rest# = mod(&sss#,&divisor#)
    :set &hrs# = format(&f_hrs#)
    :set &rest# = format(&rest#)
    :print "h=&hrs#:r=&rest#"
    Returns the following result:

    h=0:r=1800




  • 4.  Automic Script to convert seconds to HH:MM:SS format

    Posted Mar 09, 2014 12:57 PM

    Ok, in version 8 exists no variable types.

    The function DIV and MOD are in all other programming languages and in mathematics defined for integer arithmetic. When I use integer values then there is no rounding.

    The DIV-functions counts how many times the divisor exists in the dividend, so any rounding is definetly wrong.

    So 7 DIV 2 is 3 not 4 as in Version 8.

    Why must I declare the variable as float, when the function DIV and MOD are only defined for integer?

    Does your example give an other result if &f_hrs# is not defined as float?

    In mathematics is your example wrong because you divide through float.



  • 5.  Automic Script to convert seconds to HH:MM:SS format

    Posted Mar 11, 2014 12:17 PM

    DIV works fine with floats in version 9, and will return a floating point result, provided that the result variable is first declared as a float.



  • 6.  Automic Script to convert seconds to HH:MM:SS format

    Posted Mar 17, 2014 05:45 PM

    My, how timely.  We are stuck on V8 and have the requirement to use the statistic DURATION and display it in days, hours, minutes and seconds.  Here is what we came up with and it appears to satisfy our requirements.  While not terribly elegant it does appear to produce the desired results in all our test cases thus far.

    :SET &duration = GET_STATISTIC_DETAIL(,DURATION,THE_PROCESS_FLOW)
    :SET &seconds = &duration
    :IF &seconds GT 86400
    ! Days
    : SET &remainder = MOD(&seconds,86400)
    : SET &seconds = SUB(&seconds,&remainder)
    : SET &days = DIV(&seconds,86400)
    : SET &seconds = &remainder
    :ELSE
    : SET &days = 0
    : SET &remainder = &seconds 
    : ENDIF
    :IF &seconds GE 3600
    ! Hours
    : SET &remainder = MOD(&seconds,3600)
    : SET &seconds = SUB(&seconds,&remainder)
    : SET &hh = DIV(&seconds,3600)
    : SET &seconds = &remainder
    :ELSE
    : SET &hh = 0
    : SET &remainder = &seconds 
    : ENDIF
    :IF &remainder GT 59
    ! Minutes
    : SET &ss = MOD(&remainder,60)
    : SET &seconds = SUB(&remainder,&ss)
    : SET &mm = DIV(&seconds,60)
    :ELSE
    ! Just seconds, less than a minute 
    : SET &mm = 0
    : SET &ss = &remainder
    : ENDIF
    :SET &days = FORMAT(&days)
    :SET &hh = FORMAT(&hh,"00")
    :SET &mm = FORMAT(&mm,"00")
    :SET &ss = FORMAT(&ss,"00")
    :SET &seconds = FORMAT(&seconds)
    :PRINT "Duration is &days - &hh:&mm:&ss (&seconds seconds)

    Hope I haven't missed something (obvious or not)!