Sunday, July 26, 2009

Contractual record

A self respecting geek father wouldn't be a complete person unless he scrambled to write some Python to help him keep track of the duration and time between contractions. I just worked this manually from the command-line but you could totally turn this into an application with graphs and charts and people would buy it.
import time
timings = []

def start():
timings.append([time.time()])
if len(timings) > 1:
diff = timings[-1][0] - timings[-2][0]
print "Since last: %s (%.2f seconds)" % (howlong(diff), diff)

def stop():
s = timings[-1]
s.append(time.time())
print "Duration: %.2f seconds" % (s[1] - s[0],)

def howlong(t):
v = (t // 60), t - ((t // 60) * 60)
return '%d minutes %.2f seconds' % v

2 comments:

Ms. X said...

Sell that shit.

Kevin said...

It should be so simple.