Add timer to cookbook

Case number:845813-992136
Topic:Game: Tools
Opened by:salish99
Opened on:Thursday, March 15, 2012 - 21:31
Last modified:Wednesday, March 28, 2012 - 20:53

Sometimes, I donot know how long a cookbook recipe will run.
It would be nice to have a timer: "This will run for hh:mm" or "This will run until 3am".
This, of course, may vary on input paramaters and processing power, so a live updating timer would be nice.
Without this, once a recipe runs, I cannot see if it will terminate the next minute or in a week.

(Thu, 03/15/2012 - 21:31  |  6 comments)

Joined: 06/17/2010

It can be done in lua v2 script.
Proper use of os.time can give you this ability :)

Joined: 02/11/2012
Groups: Geekdo

So, if I have a recipe not programmed in V2 script, it cannot be done.
If it is a V2 script, what do I add to it?
Just os.time
or should there be some more coding around it?


Joined: 09/20/2010
Groups: Go Science

Here is some code that I have added to V2 LUA recipes:

function report_time(start_clock,start_time,clock_msg,time_msg)
local seconds,minutes,hours,days
if clock_msg==nil then clock_msg="CPU time" end
if time_msg==nil then time_msg="Elapsed time" end


.... recipe code

then add
where you want the time to be printed.

This will print out like:

03/16/12 09:04:13
CPU time(00d:01h:19m:20s)
Elapsed time(00d:01h:19m:20s)

Note: in Windows the CPU time and Elapsed time are the same. I don't know if linux or OSX would display different values.

brow42's picture
User offline. Last seen 1 year 28 weeks ago. Offline
Joined: 09/19/2011
Groups: None

These are really cool ideas, and I'll add them to my scripts for sure. You can trick Lua into doing the math, as long as your script finishes in less than a year. :)

function difftime(start, finish)
if start > finish then start,finish = finish,start end
local t ='!*t',finish-start) -- seconds since Jan 1 1970 UTC
return t.sec, t.min, t.hour, t.yday-1

d = 1 + 60 * 2+ 60*60 * 3 + 60*60*24 * 4 -- 1 sec, 2 min, 3 hr, 4 day
sec,min,hour,day = difftime(0,d)
print(string.format('Days: %d, Hours: %d, Minutes: %d, Seconds: %d',day,hour,min,sec))

Joined: 02/11/2012
Groups: Geekdo

Nice programming, thanks.

jflat06's picture
User offline. Last seen 4 days 2 hours ago. Offline
Joined: 09/29/2010
Groups: Window Group
Status: Open » Closed

As this can be covered by the lua libraries, we'll let you all use those.


Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, Boehringer Ingelheim, RosettaCommons