Calculation duration of a task

Discuss RoboTask here
Post Reply
Bacilioc
Posts: 12
Joined: Wed Jan 25, 2012 7:22 pm
Location: Greece

Calculation duration of a task

Post by Bacilioc »

At the beginning of the task I set a variable as {STARTTIME}={Time} and end of a task variable as {ENDTIME}={Time}. Then through the Basic Evaluate calculates Expression DateDiff ("s", "{STARTTIME}", "{ENDTIME}") but the result is always 0 because {STARTTIME} during execution of the expression is equal to {ENDTIME}! I did the following trick: Create text file TimeSTART.txt with Text: {Time} Action1 Action2 ..... Actinon Create text file TimeEND.txt with Text: {Time} For TimeSTART.txt -> Variable: {STARTIME} End Loop For TimeEND.txt -> Variable: {ENDTIME} End Loop Basic Evaluate -> Expression: DateDiff ("s", "{STARTTIME}", "{ENDTIME}") There is another way of calculating the duration of a task?
Oleg
Site Admin
Posts: 3201
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Calculation duration of a task

Post by Oleg »

Probably you forgot to turn ON "Expand variable value" parameter at Set Variable action.
This is necessary if you want to calculate the expression immediately. Otherwise expressions {StartTime} and {EndTime} will be calculated only before BASIC evaluation. In this case both expressions will be the same.
Look at my example:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1931015449
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task1150"
Hide=INTEGER|0
ID=INTEGER|1517979398
LocalVariables=STRING|"starttime,endtime,diff"
LogOnAsUser=INTEGER|1
Name=STRING|"task duration"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""STARTTIME"" with value ""{Time}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"STARTTIME"
varvalue=STRING|"{Time}"

[Actions\Action2]
ActionID=STRING|"A_GENERAL_PAUSE"
Enabled=INTEGER|-1
Name=STRING|"Delay 3000 ms"
Params=FOLDER

[Actions\Action2\Params]
delay=STRING|"30"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""ENDTIME"" with value ""{Time}"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"1"
varname=STRING|"ENDTIME"
varvalue=STRING|"{Time}"

[Actions\Action4]
ActionID=STRING|"BASIC_EVALUATE"
Enabled=INTEGER|-1
Name=STRING|"Evaluate"
Params=FOLDER

[Actions\Action4\Params]
expression=STRING|"datediff(""s"",""{starttime}"", ""{endtime}"")"
variable=STRING|"DIFF"

[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Start time: {StartTime}"""
Params=FOLDER

[Actions\Action5\Params]
icon=STRING|"1"
msg0=STRING|"Start time: {StartTime}"
msg1=STRING|"EndTime: {EndTime}"
msg2=STRING|"Time diff: {diff}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"
tdawebdesign
Posts: 15
Joined: Wed May 24, 2006 9:06 pm
Location: Australia
Contact:

Calculation duration of a task

Post by tdawebdesign »

Hi Oleg,Im trying to achieve the same thing.  I need to know how many milli seconds it takes to execute the task.  How would I achieve that?My other question is that when I import your example I get and error on the expression action5.  Is there something I need to install to allow datediff and these functions to be recognised?ThanksTim
Post Reply