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
@@ -173,7 +173,7 @@ Current rep maxes 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'] %}