From 2a8b72a8818366785e3cdd6ee5b3ff5a8e18a3aa Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Wed, 20 Jul 2022 21:27:11 +1000 Subject: [PATCH] Fix spelling of Exercise table/column --- db.py | 24 +++++++------- migrations/CreateTables.sql | 62 +++++++++++++++++++----------------- migrations/InsertData.sql | 50 +++++++++++++++++------------ templates/index.html | 4 +-- templates/topset.html | 2 +- templates/workout.html | 2 +- templates/workouts.html | 4 +-- utils.py | 10 +++--- workout.db | Bin 24576 -> 24576 bytes 9 files changed, 84 insertions(+), 74 deletions(-) diff --git a/db.py b/db.py index 28cf80e..c720517 100644 --- a/db.py +++ b/db.py @@ -19,8 +19,8 @@ class DataBase(): return (rv[0] if rv else None) if one else rv def get_exercises(self): - exercises = self.execute('SELECT * FROM Excercise') - return [{"ExcerciseId": e['ExcerciseId'], "Name": e['Name']} for e in exercises] + exercises = self.execute('SELECT * FROM Exercise') + return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises] def get_person(self, person_id): person = self.execute( @@ -45,11 +45,11 @@ class DataBase(): [workout_id], commit=True) def update_topset(self, exercise_id, repetitions, weight, topset_id): - self.execute('UPDATE TopSet SET ExcerciseId=?, Repetitions=?, Weight=? WHERE TopSetId=?', [ + self.execute('UPDATE TopSet SET ExerciseId=?, Repetitions=?, Weight=? WHERE TopSetId=?', [ exercise_id, repetitions, weight, topset_id], commit=True) def create_topset(self, workout_id, exercise_id, repetitions, weight): - self.execute('INSERT INTO TopSet (WorkoutId, ExcerciseId, Repetitions, Weight) VALUES (?, ?, ?, ?)', [ + self.execute('INSERT INTO TopSet (WorkoutId, ExerciseId, Repetitions, Weight) VALUES (?, ?, ?, ?)', [ workout_id, exercise_id, repetitions, weight], commit=True) def delete_topset(self, topset_id): @@ -91,14 +91,14 @@ class DataBase(): W.WorkoutId, W.StartDate, T.TopSetId, - E.ExcerciseId, + E.ExerciseId, E.Name AS ExerciseName, T.Repetitions, T.Weight FROM Person P LEFT JOIN Workout W ON P.PersonId=W.PersonId LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId - LEFT JOIN Excercise E ON T.ExcerciseId=E.ExcerciseId + LEFT JOIN Exercise E ON T.ExerciseId=E.ExerciseId WHERE P.PersonId=?""", [person_id]) return { @@ -116,14 +116,14 @@ class DataBase(): W.WorkoutId, W.StartDate, T.TopSetId, - E.ExcerciseId, + E.ExerciseId, E.Name AS ExerciseName, T.Repetitions, T.Weight FROM Person P LEFT JOIN Workout W ON P.PersonId=W.PersonId LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId - LEFT JOIN Excercise E ON T.ExcerciseId=E.ExcerciseId + LEFT JOIN Exercise E ON T.ExerciseId=E.ExerciseId WHERE P.PersonId=? AND W.WorkoutId = ?""", [person_id, workout_id]) @@ -133,7 +133,7 @@ class DataBase(): 'WorkoutId': workout_id, 'StartDate': next((t['StartDate'] for t in topsets), 'Unknown'), 'Exercises': self.get_exercises(), - 'TopSets': [{"TopSetId": t['TopSetId'], "ExcerciseId": t['ExcerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None] + 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None] } def get_topset_final(self, person_id, workout_id, topset_id): @@ -144,14 +144,14 @@ class DataBase(): W.WorkoutId, W.StartDate, T.TopSetId, - E.ExcerciseId, + E.ExerciseId, E.Name AS ExerciseName, T.Repetitions, T.Weight FROM Person P INNER JOIN Workout W ON P.PersonId=W.PersonId INNER JOIN TopSet T ON W.WorkoutId=T.WorkoutId - INNER JOIN Excercise E ON T.ExcerciseId=E.ExcerciseId + INNER JOIN Exercise E ON T.ExerciseId=E.ExerciseId WHERE P.PersonId=? AND W.WorkoutId = ? AND T.TopSetId = ?""", [person_id, workout_id, topset_id], one=True) @@ -163,7 +163,7 @@ class DataBase(): 'StartDate': topset['StartDate'], 'Exercises': self.get_exercises(), "TopSetId": topset['TopSetId'], - "ExcerciseId": topset['ExcerciseId'], + "ExerciseId": topset['ExerciseId'], "ExerciseName": topset['ExerciseName'], "Weight": topset['Weight'], "Repetitions": topset['Repetitions'] diff --git a/migrations/CreateTables.sql b/migrations/CreateTables.sql index 286dfd7..2f0e250 100644 --- a/migrations/CreateTables.sql +++ b/migrations/CreateTables.sql @@ -1,32 +1,34 @@ -CREATE TABLE IF NOT EXISTS "Person" ( - "PersonId" INTEGER, - "Name" TEXT, - PRIMARY KEY("PersonId" AUTOINCREMENT) -); +CREATE TABLE + IF NOT EXISTS "Person" ( + "PersonId" INTEGER, + "Name" TEXT, + PRIMARY KEY("PersonId" AUTOINCREMENT) + ); -CREATE TABLE IF NOT EXISTS "Workout" ( - "WorkoutId" INTEGER, - "PersonId" INTEGER, - "StartDate" TEXT NOT NULL, - - PRIMARY KEY("WorkoutId" AUTOINCREMENT), - FOREIGN KEY("PersonId") REFERENCES Person (PersonId) -); +CREATE TABLE + IF NOT EXISTS "Workout" ( + "WorkoutId" INTEGER, + "PersonId" INTEGER, + "StartDate" TEXT NOT NULL, + PRIMARY KEY("WorkoutId" AUTOINCREMENT), + FOREIGN KEY("PersonId") REFERENCES Person (PersonId) ON DELETE CASCADE + ); -CREATE TABLE IF NOT EXISTS "TopSet" ( - "TopSetId" INTEGER, - "WorkoutId" INTEGER, - "ExcerciseId" INTEGER, - "Repetitions" INTEGER, - "Weight" INTEGER, - PRIMARY KEY("TopSetId" AUTOINCREMENT), - FOREIGN KEY("WorkoutId") REFERENCES Workout (WorkoutId), - FOREIGN KEY("ExcerciseId") REFERENCES Excercise (ExcerciseId) -); - -CREATE TABLE IF NOT EXISTS "Excercise" ( - "ExcerciseId" INTEGER, - "Name" TEXT, - PRIMARY KEY("ExcerciseId" AUTOINCREMENT) -); - \ No newline at end of file +CREATE TABLE + IF NOT EXISTS "TopSet" ( + "TopSetId" INTEGER, + "WorkoutId" INTEGER, + "ExerciseId" INTEGER, + "Repetitions" INTEGER, + "Weight" INTEGER, + PRIMARY KEY("TopSetId" AUTOINCREMENT), + FOREIGN KEY("WorkoutId") REFERENCES Workout (WorkoutId) ON DELETE CASCADE, + FOREIGN KEY("ExerciseId") REFERENCES Exercise (ExerciseId) ON DELETE CASCADE + ); + +CREATE TABLE + IF NOT EXISTS "Exercise" ( + "ExerciseId" INTEGER, + "Name" TEXT, + PRIMARY KEY("ExerciseId" AUTOINCREMENT) + ); \ No newline at end of file diff --git a/migrations/InsertData.sql b/migrations/InsertData.sql index 2451a5f..2f7fc82 100644 --- a/migrations/InsertData.sql +++ b/migrations/InsertData.sql @@ -1,22 +1,30 @@ -INSERT INTO Person (Name) - VALUES ("Gabe"), - ("Michael"); +INSERT INTO + Person (Name) +VALUES + ("Gabe"), + ("Michael"); -INSERT INTO Excercise (Name) - VALUES ("Squat"), - ("Bench"), - ("Deadlift"), - ("Hotep"), - ("Lat Pulldown"); - -INSERT INTO Workout (PersonId, StartDate) - VALUES (1, "2022-06-29 00:00:00.000"), - (1, "2022-07-07 00:00:00.000"), - (1, "2022-07-12 00:00:00.000"); - -INSERT INTO TopSet (WorkoutId, ExcerciseId, Repetitions, Weight) - VALUES (1, 2, 11, 40), - (2, 1, 5, 65), - (2, 4, 6, 30), - (3, 2, 4, 60), - (3, 3, 9, 100); \ No newline at end of file +INSERT INTO + Exercise (Name) +VALUES + ("Squat"), + ("Bench"), + ("Deadlift"), + ("Hotep"), + ("Lat Pulldown"); + +INSERT INTO + Workout (PersonId, StartDate) +VALUES + (1, "2022-06-29 00:00:00.000"), + (1, "2022-07-07 00:00:00.000"), + (1, "2022-07-12 00:00:00.000"); + +INSERT INTO + TopSet (WorkoutId, ExerciseId, Repetitions, Weight) +VALUES + (1, 2, 11, 40), + (2, 1, 5, 65), + (2, 4, 6, 30), + (3, 2, 4, 60), + (3, 3, 9, 100); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index d108194..1adf3fc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,7 +11,7 @@ Current rep maxes
- View workouts
@@ -173,7 +173,7 @@ Current rep maxes
- View workouts
diff --git a/templates/topset.html b/templates/topset.html index c81bc37..d7abec0 100644 --- a/templates/topset.html +++ b/templates/topset.html @@ -31,7 +31,7 @@ class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" id="grid-state" name="exercise_id"> {% for e in topset['Exercises'] %} - {% endfor %} diff --git a/templates/workout.html b/templates/workout.html index 0fa147e..f68f48e 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -81,7 +81,7 @@ class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" id="grid-state" name="exercise_id"> {% for e in workout['Exercises'] %} - {% endfor %} diff --git a/templates/workouts.html b/templates/workouts.html index a638020..031ceeb 100644 --- a/templates/workouts.html +++ b/templates/workouts.html @@ -44,8 +44,8 @@ {% for e in person['Exercises'] %} {% set topset_exercise = - get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExcerciseId', - e['ExcerciseId']) %} + get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExerciseId', + e['ExerciseId']) %} {% if topset_exercise %} {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg {% endif %} diff --git a/utils.py b/utils.py index 93800f2..3e157dc 100644 --- a/utils.py +++ b/utils.py @@ -11,18 +11,18 @@ def get_workouts(topsets): workouts.append({ 'WorkoutId': workout_id, 'StartDate': topsets_in_workout[0]['StartDate'], - 'TopSets': [{"TopSetId": t['TopSetId'], "ExcerciseId": t['ExcerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets_in_workout] + 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets_in_workout] }) return workouts def get_all_exercises_from_topsets(topsets): - exercise_ids = set([t['ExcerciseId'] - for t in topsets if t['ExcerciseId'] is not None]) + exercise_ids = set([t['ExerciseId'] + for t in topsets if t['ExerciseId'] is not None]) exercises = [] for exercise_id in exercise_ids: exercises.append({ - 'ExcerciseId': exercise_id, - 'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExcerciseId'] == exercise_id), 'Unknown') + 'ExerciseId': exercise_id, + 'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExerciseId'] == exercise_id), 'Unknown') }) return exercises diff --git a/workout.db b/workout.db index 9d64e18d03b5a467574cff833c8f9cba25ec7e8e..110ac684888caf1cd6e47f477487cb13383777bc 100644 GIT binary patch delta 970 zcmZ`&O=uHA6y8bpr^#mX8b}Q#gieEpEVO2gLP11WlWAE@H+8d8i-#K9MT6SZWR)IT z(lmJLMVX7>O+m;}dJgnZda@UxhhFp`co4m*XE({FO-=G(ci+A@Z{GKPZ)STRZSSL3 z(U8h84DUQ$3%{Pa5>c5;xh)BH7*5<|KncE+-UhIt5Q)W5ZObk^cw&(a ztGrUIoPN2qK~$4qQ@xobINnXiaYFKA$4(>KY8-32N#=+#<)-w)Q!9>5a@TYt3x+nY z8cX;VSxUHt^nTz%6=S*1azbQ$9KBp=!!S$hdCTs+`STDu!7~7z{{ih6OXbI<=k|b1 zmxY_U(F@wJ)-Ahe7fWlEK0=FD@!=!;|1iZ;f^BI*HEE`bb2`qDEO9hTtNFB=AujpZ zoI$iXy_bB&auCSaAhX0EdYa^M7a2};J#AI)-?AmJyu-3WBpOBa<+fxUx>ehy&7N1y zjh@LiT%850Tq&&$kS%W)%66t;yF&OW#SK0#=&k~n&pyY>%vqVv-L delta 803 zcmZoTz}Rqrae}lU3j+fK8xX?)&qN(#aTW$W|5{%DCI(jSrwsfCd~11+@|1Hw-7F}O z&t2ch&&Dn;FVEPRTauWRlj>TLoLZEeS&U$?IS08qhPWz(I6C>bDk#AfC@E<0a&aQ~ zo+(P4o_-;&?yf;PAPK+3+*Bpb5Z8zh5H}#m)7LR5Qo-9bQUh6!zLJ7tXo$b3AJ7(G zSHBQVUM|fhZ&r43NlC_*La>uU@(Y4fOCTicWCI?_dQK$>4``(VvX$ZaMcMhKCFsI% zC!>{+O)ArwQ~|IG>3;$W;u?;8+@gbV&-4T!2g*482?IO`kT!^d8K_c z4-5Yp2L3PnPx)`~pV=&^aGYO^m7AGani1+dW?m*{c}8HMO@6B{zL-TofRB~`7z6)T x{#X3>_%HDv0~)l2fAX<-D*0RYMk;Tr$|