-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataimport.py
147 lines (120 loc) · 4.29 KB
/
dataimport.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import numpy as np
import matplotlib.pyplot as plt
import datetime
import matplotlib.dates
def containsNumber(value):
for character in value:
if character.isdigit():
return True
return False
# import data from notes and put it in a list
with open("liftingpostcovid.txt", "r") as data:
rawNotes = [(line.strip()).split() for line in data]
k = 0
while k < len(rawNotes):
if rawNotes[k] == "Front" and rawNotes[k + 1] == "Squat":
rawNotes[k : k + 1] = ["".join(rawNotes[k : k + 1])]
k = k + 1
print(rawNotes[0:5])
flatNotes = [x for note in rawNotes for x in note]
print(flatNotes[0:5])
# initialize benchWeight and benchReps arrays
def masterFunc(liftName):
weight = []
reps = []
liftDate = []
i = 0
def findDate(j):
# Finds corresponding date for a particular set
while j > 0:
if "/" in flatNotes[j - 1]:
newDate = datetime.datetime.strptime(flatNotes[j - 1], "%m/%d/%y")
newDate = matplotlib.dates.date2num(newDate)
j = 0
else:
j = j - 1
return newDate
# create 3 arrays, for lift weight, reps performed, and date performed
while i < len(flatNotes):
# make sure entry is in valid form
if liftName in flatNotes[i]:
if not containsNumber(flatNotes[i + 1]) or not containsNumber(
flatNotes[i + 2]
):
i = i + 2
print("oops", flatNotes[i], matplotlib.dates.num2date(findDate(i)))
# add value for rep and weight to list
else:
weight = np.append(weight, flatNotes[i + 1])
reps = np.append(reps, flatNotes[i + 2])
j = i
# add corresponding date value to list
liftDate = np.append(liftDate, findDate(j))
i = i + 1
######### do error test and print line for which iti doesnt work and date and stufdf here
# find the hardest set for each day
x = 0
# grab only value of highest reps performed that day, discard lighter sets
highestReps = []
while x < len(reps):
if "," in reps[x]:
newReps = [int(x) for x in reps[x].split(",")]
highestReps = np.append(highestReps, (max(newReps)))
x = x + 1
elif "x" in reps[x]:
newReps = [reps[x][2 : len(reps[x])]]
x = x + 1
highestReps = np.append(highestReps, newReps)
else:
newReps = reps[x]
x = x + 1
highestReps = np.append(highestReps, newReps)
weight = weight.astype(float)
highestReps = highestReps.astype(int)
# print(highestReps)
# creating empty rep max table
repidx = [i for i in range(1, 11)]
repweight = [0 for i in range(1, 11)]
table = np.array(list(zip(repidx, repweight)))
n = 0
while n < len(highestReps):
highestReps[n] = min(highestReps[n], 10)
idx = highestReps[n] - 1
if weight[n] > repweight[idx]:
repweight[idx] = weight[n]
n = n + 1
table = np.array(list(zip(repidx, repweight)))
highestReps = highestReps.astype(int)
# calculate the estimated 1 rep max based on hardest set of each day
# print(highestReps)
# print(weight)
e1rm = weight * (36 / (37 - highestReps)) # Bryzcki formula
# e1rm = weight*highestReps**.1 #Lombardi formula
# print(e1rm)
# plotting stuff
plt.figure()
matplotlib.pyplot.plot_date(liftDate, e1rm)
plt.xlabel("Date")
plt.ylabel("Estimated " + str(liftName) + "1 Rep Max")
ax = plt.gca()
n = 7 # Keeps every 7th label
[
l.set_visible(False)
for (i, l) in enumerate(ax.xaxis.get_ticklabels())
if i % n != 0
]
plt.grid(True)
plt.suptitle(liftName)
plt.savefig(str(liftName) + " e1RM")
fig, ax = plt.subplots(1, 1)
ax.set_title(liftName)
data = table
column_labels = ["Reps", "Weight"]
ax.axis("tight")
ax.axis("off")
ax.table(cellText=data, colLabels=column_labels, loc="center")
return
masterFunc("Bench")
# masterFunc("Deadlift")
# masterFunc("Ohp")
# masterFunc("Squat")