Skip to content

Instantly share code, notes, and snippets.

@jbarratt
Created June 3, 2014 17:08
Show Gist options
  • Save jbarratt/3b015d11568f11183e7f to your computer and use it in GitHub Desktop.
Save jbarratt/3b015d11568f11183e7f to your computer and use it in GitHub Desktop.
SimpleSinisterStats
from scene import *
import time
import clipboard
import sys
import speech
class SimpleSinister(object):
def __init__(self):
self.steps = ['Warmup']
self.steps += ["Swing " + str(x) for x in range(1,7)]
self.steps += ["Getup " + str(x) for x in range(1,6)]
self.steps += ["Sprint " + str(x) for x in range(1,4)]
self.step = None
self.times = []
self.last_time = None
def start(self):
self.last_time = time.time()
self.step = 0
speech.say(self.step_name())
def pct_complete(self):
return len(self.times)/float(len(self.steps))
def step_name(self):
try:
return self.steps[self.step]
except:
return ""
def next_step(self):
elapsed = time.time() - self.last_time
self.times.append(elapsed)
self.step += 1
self.last_time = time.time()
if self.step >= len(self.steps):
speech.say("mission completion")
datestr = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
output = "#" + datestr + "\n" + '\n'.join(["{},{:.2f}".format(v, self.times[i]) for i, v in enumerate(self.steps)]) + "\n"
clipboard.set(output)
fh = open("workout_log.txt", "a")
fh.write(output)
return False
else:
speech.say(self.step_name())
return True
class MyScene (Scene):
def setup(self):
self.ss = SimpleSinister()
self.running = False
self.status = "Tap to begin"
self.done = False
def draw(self):
background(0, 0, 0)
w, h = self.size.w, self.size.h
fill(1,1,1)
rect(w*.1, h-40, w*.8, 30)
fill(1,0,0)
rect(w*.1, h-40, w*.8*self.ss.pct_complete(), 30)
fill(1, 0, 0)
rect(w * 0.5 - 100, h * 0.5 - 100, 200, 200)
if not self.running:
text(self.status, font_size=24.0, x=w * 0.5, y=h * 0.5)
else:
text(self.ss.step_name(), font_size=24.0, x=w * 0.5, y=h * 0.5)
def touch_began(self, touch):
if self.done:
sys.exit(0)
if not self.running:
self.ss.start()
self.running = True
return
if not self.ss.next_step():
self.status = "Workout Complete\nTime on Clipboard"
self.running = False
self.done = True
run(MyScene())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment