-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_driver.py
117 lines (78 loc) · 2.88 KB
/
test_driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#from tabataGUI import close_app
from guizero import App, Text, PushButton
import threading
from random import randint
import time
exerciseFile = [line.rstrip('\n') for line in open('exercises.txt')]
exercises = exerciseFile[2:len(exerciseFile)]
categories = exerciseFile[0].split()
catStarts = exerciseFile[1].split()
catEnds = catStarts[1:len(catStarts)] + [len(exercises)]
numCats = len(catStarts)
numExerInCatComplete = [0] * numCats
exerciseList = []
repetitions = 2
numExercises = 5
paused = False
start = threading.Event()
stop = threading.Event()
def togglePause():
paused = not paused
pauseButton = PushButton(app, text = "Pause", align = "left", command = pause_app)
minExerPerCat = int(numExercises / numCats)
frequency = 2500 # Set Frequency To 2500 Hertz
duration = 50 # Set Duration To 1000 ms == 1 second
app = App(title="Tapata", width = 400, height=400)
text = Text(app, text="", size=24, align = "bottom")
counter = Text(app, text="0 , 0", size=24, align = "top")
debug = Text(app, text="", size=24, align = "left")
def shortPause():
time.sleep(0.2)
def findNextCat():
nxtCat = randint(0,numCats-1)
if (all(x >= minExerPerCat for x in numExerInCatComplete)):
return nxtCat
else:
while (numExerInCatComplete[nxtCat] >= minExerPerCat):
nxtCat = randint(0,numCats-1)
return nxtCat
def getExercise():
cat = findNextCat()
numExerInCatComplete[cat] += 1
i = randint(int(catStarts[cat]),int(catEnds[cat]) - 1)
while (i in exerciseList):
i = randint(int(catStarts[cat]),int(catEnds[cat]) - 1)
exerciseList.append(i)
return i
def main():
for exer in range(0,numExercises):
nxt = getExercise()
debug.value = exerciseList + ["\n"] + numExerInCatComplete
text.value = exercises[nxt]
app.bg = "green"
counter.value = str(exer+1) + " , 1"
app.update()
#Play sound to notify of new exercise
for rep in range(0,repetitions):
counter.value = str(exer+1) + " , " + str(rep+1)
app.bg = "green"
app.update()
#Rest Timer
tRest = threading.Thread(target=shortPause)
tRest.start()
tRest.join()
app.bg = "red"
app.update()
#Excercise timer
tExercise = threading.Thread(target=shortPause)
tExercise.start()
tExercise.join()
app.bg = "green"
debug.value = ""
text.size = 18
finalOutput = ["Workout Complete\n"] + [exercises[i] for i in exerciseList] + ["\n"] + [exerciseFile[0]] + ["\n"] + [numExerInCatComplete]
text.value = finalOutput
app.update()
app.display()
if __name__ == '__main__':
main()