· 6 years ago · Jan 12, 2020, 12:28 PM
1import sqlite3
2import time
3import datetime
4import random
5
6# DB CONNECTION
7conn = sqlite3.connect("exerciseDB.db")
8
9#connSDB = sqlite3.connect("schedulesDB.db")
10
11c = conn.cursor()
12#cS = connSDB.cursor()
13
14
15# CLASSES
16
17class User:
18 def __init__(self, name):
19 #self.userID = ""
20 self.name = name
21
22 def createName(self, name):
23 self.name = name
24 print("You have added: ", self.name + " as you name!")
25
26
27class Schedule:
28 def __init__(self, name, userId, startDate, goalDate):
29 #self.scheduleId = ""
30 self.name = name
31 self.userId = userId
32 #self.exercises = exercises
33 #startDate = date.now()
34 self.startDate = startDate
35 self.goalDate = goalDate
36
37 def scheduleName(self, name):
38 self.name = name
39 print("Schedule name changed to: ", self.name + "!")
40
41class Excercise:
42 def __init__(self, name, exerciseType):
43 #self.exerciseId = ""
44 self.name = name
45 self.exerciseType = exerciseType
46 self.userId = ""
47
48 def newRM(newRM):
49 #self.RMId = ""
50 self.history.append(self.RM)
51 self.RM = newRM
52
53class ExcerciseSession:
54 def __init__(self, name, exerciseType, scheduleId, cycleStatus, date, userId):
55 #self.exerciseId = ""
56 self.name = name
57 self.exerciseType = exerciseType
58 self.scheduleId = scheduleId
59 self.cycleStatus = cycleStatus
60 self.date = date
61 self.userId = userId
62
63 def newRM(newRM):
64 #self.RMId = ""
65 self.history.append(self.RM)
66 self.RM = newRM
67
68class RM:
69 def __init__(self, weight, date):
70 #self.RMId = ""
71 self.exerciseId = ""
72 self.userId = ""
73 self.weight = weight
74 self.date = date
75
76
77# DB TABLES
78
79def create_user_table():
80 c.execute("CREATE TABLE IF NOT EXISTS usersDB(id integer primary key asc autoincrement, name, schedule)")
81 print("usersDB created!")
82
83def create_schedule_table():
84 c.execute("CREATE TABLE IF NOT EXISTS schedulesDB(id integer primary key asc autoincrement, name, userId, startDate, goalDate)")
85 print("schedulesDB created!")
86
87def create_exercise_table():
88 c.execute("CREATE TABLE IF NOT EXISTS exercisesDB(id integer primary key asc autoincrement, name, userId, exerciseType)")
89 print("exercisesDB created!")
90
91def create_excerciseSession_table():
92 c.execute("CREATE TABLE IF NOT EXISTS exerciseSessionsDB(id integer primary key asc autoincrement, name, exerciseType, scheduleId, cycleStatus, date, userId)")
93 print("exercisesDB created!")
94
95def create_RM_table():
96 c.execute("CREATE TABLE IF NOT EXISTS RMsDB(id integer primary key asc autoincrement, exerciseId, userId, weight, date)")
97 print("RMsDB created!")
98
99
100# METHODS
101
102# ADD TO DB
103
104def add_user(name):
105 c.execute("INSERT INTO usersDB(name) VALUES (?)", (name,))
106 conn.commit()
107 c.close()
108 conn.close()
109 print("User " + name + " was created to DB")
110
111def add_schedule(schedule):
112 c.execute("INSERT INTO schedulesDB(name, userId, startDate, goalDate) VALUES (?, ?, ?, ?)", (schedule.name, schedule.userId, schedule.startDate, schedule.goalDate,))
113 conn.commit()
114 c.close()
115 conn.close()
116 print("Schedule " + schedule.name + " was created to DB")
117
118def add_exercise(exercise):
119 c.execute("INSERT INTO exercisesDB(name, userId, exerciseType) VALUES (?, ?, ?)", (exercise.name, exercise.userId, exercise.exerciseType))
120 conn.commit()
121 c.close()
122 conn.close()
123 print("Exercise" , + exercise.name + " was created to DB")
124
125def add_exerciseSession(session):
126 c.execute("INSERT INTO exerciseSessionsDB(name, exerciseType, scheduleId, cycleStatus, date, userId) VALUES (?, ?, ?, ?, ?, ?)", (session.name, session.exerciseType, session.scheduleId, session.cycleStatus, session.date, session.userId,))
127 conn.commit()
128 #c.close()
129 #conn.close()
130 print("Exercise session" + session.name + " was created to DB")
131
132def add_RM(exerciseId, userId, weight, date):
133 c.execute("INSERT INTO RMsDB(exerciseId, userId, weight, date) VALUES (?, ?, ?, ?)", (exerciseId, userId, weight, date,))
134 conn.commit()
135 c.close()
136 conn.close()
137 print("A new RM was created to DB")
138
139
140# ORIGINAL
141
142def createSchedule(exercises):
143 exercisePerWeek = input("Let´s start with how many times a week you want to exercise? ")
144 print("Ok!", exercisePerWeek, " time per week it is!")
145 newSchedule = Schedule(exercises, exercisePerWeek)
146 return newSchedule
147
148def listExercises():
149 exerciseList = []
150 done = False
151 print("Write the name of your exercises. When you are done, write Done!\n")
152 while done == False:
153 newExercise = str(input("Add exercise: "))
154 if newExercise.lower() != "Done":
155 exerciseList.append(newExercise)
156 print("Exercise added!\n")
157
158 else:
159 done = True
160 return exerciseList
161
162
163def calculateIntensity(exerciseFocus, RM):
164 weight = ""
165 reps = ""
166 sets = ""
167
168 if exerciseFocus == "Hypertrophy":
169 weight = RM * 0.70
170 reps = 10
171 sets = 3
172
173 elif exerciseFocus == "Strenght":
174 weight = RM * 0.85
175 reps = 5
176 sets = 5
177
178 return weight, reps, sets
179
180# one algorithm to suggest a schedule depending on amount of epw incl or excl. restdays
181"""def calculateSchedule(exercises, exercisesPerWeek, user):
182 sessions = []
183 if exercisesPerWeek >= 7:
184 for i """
185
186# another algorithm to set a preset strucure according to personal preferences
187def calculateSchedule(scheduleName, userId, exercises, exercisesPerWeek):
188 aerobicSession = []
189 anarobicSessions = []
190 schedule = []
191 sessions = []
192
193 for e in exercises:
194 if e.exerciseType != "Aerobic":
195 aerobicSession.append(e)
196 else:
197 anarobicSessions.append(e)
198
199 """for aes in range(anarobicSessions):
200 session = exerciseSession(anarobicSessions[aes].name, "Anarobic", aes, userId)"""
201
202 session1 = ExcerciseSession("Aerobic, prolonged medium intensity", "Aerobic", "New schedule ID", 1, datetime.datetime.now(), userId)
203 sessions.append(session1)
204
205 session2 = ExcerciseSession("Anarobic, upper body, strenght", "Anarobic", "New schedule ID", 2, datetime.datetime.now(), userId)
206 sessions.append(session2)
207
208 session3 = ExcerciseSession("Aerobic, high intensity intervalls", "Aerobic", "New schedule ID", 3, datetime.datetime.now(), userId)
209 sessions.append(session3)
210
211 session4 = ExcerciseSession("Rest", "None", "New schedule ID", 4, datetime.datetime.now(), userId)
212 sessions.append(session4)
213
214 session5 = ExcerciseSession("Anarobic, hypertrophy", "Aerobic", "New schedule ID", 5, datetime.datetime.now(), userId)
215 sessions.append(session5)
216
217 session6 = ExcerciseSession("Aerobic, prolonged medium intensity", "Aerobic", "New schedule ID", 6, datetime.datetime.now(), userId)
218 sessions.append(session6)
219
220 session7 = ExcerciseSession("Anarobic, low intensity", "Anarobic", "New schedule ID", 7, datetime.datetime.now(), userId)
221 sessions.append(session7)
222
223 session8 = ExcerciseSession("Rest", "None", "New schedule ID", 8, datetime.datetime.now(), userId)
224 sessions.append(session8)
225
226 session9 = ExcerciseSession("Rest", "None", "New schedule ID", 9, datetime.datetime.now(), userId)
227 sessions.append(session9)
228
229 for session in sessions:
230 add_exerciseSession(session)
231 #time.sleep(0.5)
232
233 newSchedule = Schedule(scheduleName, userId, "Today", "No goal date")
234
235 add_schedule(newSchedule)
236
237
238
239
240
241
242
243
244
245
246
247#def setProgressGoals():
248
249
250
251
252def greetUser():
253 userName = str(input("Welcome to the workout app! Please enter your name to create a new user: "))
254
255 print("Thank you " + userName + "\nNow it´s time to tell us about your workout rutine, so we can automate your schedule and keep our mind of that fuzz!")
256
257 exercises = listExercises()
258 schedule = createSchedule(exercises)
259
260 print("nThis is your exercise plan so far:\n")
261
262 print("Exercises:")
263 for e in schedule.exercises:
264 print("-", e)
265
266 confirmSettings = str(input("\nExercies per week: " + str(schedule.exercisePerWeek) + "\nIs this okay " + userName + " or do you want to reset your settings? (Y/N)" ))
267
268 if confirmSettings.lower() == "n":
269 greetUser()
270
271 elif confirmSettings.lower() == "y":
272 print("\nOkay, lets get going!")
273
274
275
276
277
278
279
280# MAIN
281
282def __main__():
283 greetUser()
284
285
286
287
288
289
290# TEST
291
292#reetUser()
293#listExercises()
294"""create_user_table()
295create_schedule_table()
296create_exercise_table()
297create_RM_table()
298create_excerciseSession_table()"""
299
300
301e1 = Excercise("High intensity intervalls", "Aerobic")
302e1.userId = 1
303
304e2 = Excercise("Running medium intensity", "Aerobic")
305e2.userId = 1
306
307e3 = Excercise("Bench press", "Anarobic")
308e3.userId = 1
309
310exercises = [e1, e2, e3]
311
312calculateSchedule("Test schedule", 1, exercises, 15)
313
314
315
316# INIT DB
317
318#add_user("Alex")
319#add_exercise("Bänkpress", 1)
320#add_RM(1, 1, 95, "Today")
321
322
323#<<<<<<<<<< PROTOTYPE FUNC >>>>>>>>>>>>>>
324
325# add user, schedule, excercise and RM
326
327# set new RM-record in exercise connected to USER --> find new RM through user