Fix spelling of Exercise table/column

This commit is contained in:
Peter Stockings
2022-07-20 21:27:11 +10:00
parent ee8245bb4c
commit 2a8b72a881
9 changed files with 84 additions and 74 deletions

24
db.py
View File

@@ -19,8 +19,8 @@ class DataBase():
return (rv[0] if rv else None) if one else rv return (rv[0] if rv else None) if one else rv
def get_exercises(self): def get_exercises(self):
exercises = self.execute('SELECT * FROM Excercise') exercises = self.execute('SELECT * FROM Exercise')
return [{"ExcerciseId": e['ExcerciseId'], "Name": e['Name']} for e in exercises] return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises]
def get_person(self, person_id): def get_person(self, person_id):
person = self.execute( person = self.execute(
@@ -45,11 +45,11 @@ class DataBase():
[workout_id], commit=True) [workout_id], commit=True)
def update_topset(self, exercise_id, repetitions, weight, topset_id): 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) exercise_id, repetitions, weight, topset_id], commit=True)
def create_topset(self, workout_id, exercise_id, repetitions, weight): 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) workout_id, exercise_id, repetitions, weight], commit=True)
def delete_topset(self, topset_id): def delete_topset(self, topset_id):
@@ -91,14 +91,14 @@ class DataBase():
W.WorkoutId, W.WorkoutId,
W.StartDate, W.StartDate,
T.TopSetId, T.TopSetId,
E.ExcerciseId, E.ExerciseId,
E.Name AS ExerciseName, E.Name AS ExerciseName,
T.Repetitions, T.Repetitions,
T.Weight T.Weight
FROM Person P FROM Person P
LEFT JOIN Workout W ON P.PersonId=W.PersonId LEFT JOIN Workout W ON P.PersonId=W.PersonId
LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId 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]) WHERE P.PersonId=?""", [person_id])
return { return {
@@ -116,14 +116,14 @@ class DataBase():
W.WorkoutId, W.WorkoutId,
W.StartDate, W.StartDate,
T.TopSetId, T.TopSetId,
E.ExcerciseId, E.ExerciseId,
E.Name AS ExerciseName, E.Name AS ExerciseName,
T.Repetitions, T.Repetitions,
T.Weight T.Weight
FROM Person P FROM Person P
LEFT JOIN Workout W ON P.PersonId=W.PersonId LEFT JOIN Workout W ON P.PersonId=W.PersonId
LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId 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=? WHERE P.PersonId=?
AND W.WorkoutId = ?""", [person_id, workout_id]) AND W.WorkoutId = ?""", [person_id, workout_id])
@@ -133,7 +133,7 @@ class DataBase():
'WorkoutId': workout_id, 'WorkoutId': workout_id,
'StartDate': next((t['StartDate'] for t in topsets), 'Unknown'), 'StartDate': next((t['StartDate'] for t in topsets), 'Unknown'),
'Exercises': self.get_exercises(), '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): def get_topset_final(self, person_id, workout_id, topset_id):
@@ -144,14 +144,14 @@ class DataBase():
W.WorkoutId, W.WorkoutId,
W.StartDate, W.StartDate,
T.TopSetId, T.TopSetId,
E.ExcerciseId, E.ExerciseId,
E.Name AS ExerciseName, E.Name AS ExerciseName,
T.Repetitions, T.Repetitions,
T.Weight T.Weight
FROM Person P FROM Person P
INNER JOIN Workout W ON P.PersonId=W.PersonId INNER JOIN Workout W ON P.PersonId=W.PersonId
INNER JOIN TopSet T ON W.WorkoutId=T.WorkoutId 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=? WHERE P.PersonId=?
AND W.WorkoutId = ? AND W.WorkoutId = ?
AND T.TopSetId = ?""", [person_id, workout_id, topset_id], one=True) AND T.TopSetId = ?""", [person_id, workout_id, topset_id], one=True)
@@ -163,7 +163,7 @@ class DataBase():
'StartDate': topset['StartDate'], 'StartDate': topset['StartDate'],
'Exercises': self.get_exercises(), 'Exercises': self.get_exercises(),
"TopSetId": topset['TopSetId'], "TopSetId": topset['TopSetId'],
"ExcerciseId": topset['ExcerciseId'], "ExerciseId": topset['ExerciseId'],
"ExerciseName": topset['ExerciseName'], "ExerciseName": topset['ExerciseName'],
"Weight": topset['Weight'], "Weight": topset['Weight'],
"Repetitions": topset['Repetitions'] "Repetitions": topset['Repetitions']

View File

@@ -1,32 +1,34 @@
CREATE TABLE IF NOT EXISTS "Person" ( CREATE TABLE
"PersonId" INTEGER, IF NOT EXISTS "Person" (
"Name" TEXT, "PersonId" INTEGER,
PRIMARY KEY("PersonId" AUTOINCREMENT) "Name" TEXT,
); PRIMARY KEY("PersonId" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS "Workout" ( CREATE TABLE
"WorkoutId" INTEGER, IF NOT EXISTS "Workout" (
"PersonId" INTEGER, "WorkoutId" INTEGER,
"StartDate" TEXT NOT NULL, "PersonId" INTEGER,
"StartDate" TEXT NOT NULL,
PRIMARY KEY("WorkoutId" AUTOINCREMENT), PRIMARY KEY("WorkoutId" AUTOINCREMENT),
FOREIGN KEY("PersonId") REFERENCES Person (PersonId) FOREIGN KEY("PersonId") REFERENCES Person (PersonId) ON DELETE CASCADE
); );
CREATE TABLE IF NOT EXISTS "TopSet" ( CREATE TABLE
"TopSetId" INTEGER, IF NOT EXISTS "TopSet" (
"WorkoutId" INTEGER, "TopSetId" INTEGER,
"ExcerciseId" INTEGER, "WorkoutId" INTEGER,
"Repetitions" INTEGER, "ExerciseId" INTEGER,
"Weight" INTEGER, "Repetitions" INTEGER,
PRIMARY KEY("TopSetId" AUTOINCREMENT), "Weight" INTEGER,
FOREIGN KEY("WorkoutId") REFERENCES Workout (WorkoutId), PRIMARY KEY("TopSetId" AUTOINCREMENT),
FOREIGN KEY("ExcerciseId") REFERENCES Excercise (ExcerciseId) FOREIGN KEY("WorkoutId") REFERENCES Workout (WorkoutId) ON DELETE CASCADE,
); FOREIGN KEY("ExerciseId") REFERENCES Exercise (ExerciseId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "Excercise" (
"ExcerciseId" INTEGER, CREATE TABLE
"Name" TEXT, IF NOT EXISTS "Exercise" (
PRIMARY KEY("ExcerciseId" AUTOINCREMENT) "ExerciseId" INTEGER,
); "Name" TEXT,
PRIMARY KEY("ExerciseId" AUTOINCREMENT)
);

View File

@@ -1,22 +1,30 @@
INSERT INTO Person (Name) INSERT INTO
VALUES ("Gabe"), Person (Name)
("Michael"); VALUES
("Gabe"),
("Michael");
INSERT INTO Excercise (Name) INSERT INTO
VALUES ("Squat"), Exercise (Name)
("Bench"), VALUES
("Deadlift"), ("Squat"),
("Hotep"), ("Bench"),
("Lat Pulldown"); ("Deadlift"),
("Hotep"),
INSERT INTO Workout (PersonId, StartDate) ("Lat Pulldown");
VALUES (1, "2022-06-29 00:00:00.000"),
(1, "2022-07-07 00:00:00.000"), INSERT INTO
(1, "2022-07-12 00:00:00.000"); Workout (PersonId, StartDate)
VALUES
INSERT INTO TopSet (WorkoutId, ExcerciseId, Repetitions, Weight) (1, "2022-06-29 00:00:00.000"),
VALUES (1, 2, 11, 40), (1, "2022-07-07 00:00:00.000"),
(2, 1, 5, 65), (1, "2022-07-12 00:00:00.000");
(2, 4, 6, 30),
(3, 2, 4, 60), INSERT INTO
(3, 3, 9, 100); 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);

View File

@@ -11,7 +11,7 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span> <span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div> </div>
<div class="flex-shrink-0"> <div class="flex-shrink-0">
<a href="{{ url_for('get_workout' ,person_id=1) }}" <a href="{{ url_for('get_person' ,person_id=1) }}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a> class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a>
</div> </div>
</div> </div>
@@ -173,7 +173,7 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span> <span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div> </div>
<div class="flex-shrink-0"> <div class="flex-shrink-0">
<a href="{{ url_for('get_workout' ,person_id=2) }}" <a href="{{ url_for('get_person' ,person_id=2) }}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a> class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a>
</div> </div>
</div> </div>

View File

@@ -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" 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"> id="grid-state" name="exercise_id">
{% for e in topset['Exercises'] %} {% for e in topset['Exercises'] %}
<option value="{{ e['ExcerciseId'] }}" {% if topset['ExcerciseId']==e['ExcerciseId'] %} <option value="{{ e['ExerciseId'] }}" {% if topset['ExerciseId']==e['ExerciseId'] %}
selected {% endif %}>{{ selected {% endif %}>{{
e['Name']}}</option> e['Name']}}</option>
{% endfor %} {% endfor %}

View File

@@ -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" 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"> id="grid-state" name="exercise_id">
{% for e in workout['Exercises'] %} {% for e in workout['Exercises'] %}
<option value="{{ e['ExcerciseId'] }}">{{ <option value="{{ e['ExerciseId'] }}">{{
e['Name']}}</option> e['Name']}}</option>
{% endfor %} {% endfor %}
</select> </select>

View File

@@ -44,8 +44,8 @@
{% for e in person['Exercises'] %} {% for e in person['Exercises'] %}
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900"> <td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
{% set topset_exercise = {% set topset_exercise =
get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExcerciseId', get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExerciseId',
e['ExcerciseId']) %} e['ExerciseId']) %}
{% if topset_exercise %} {% if topset_exercise %}
{{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg
{% endif %} {% endif %}

View File

@@ -11,18 +11,18 @@ def get_workouts(topsets):
workouts.append({ workouts.append({
'WorkoutId': workout_id, 'WorkoutId': workout_id,
'StartDate': topsets_in_workout[0]['StartDate'], '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 return workouts
def get_all_exercises_from_topsets(topsets): def get_all_exercises_from_topsets(topsets):
exercise_ids = set([t['ExcerciseId'] exercise_ids = set([t['ExerciseId']
for t in topsets if t['ExcerciseId'] is not None]) for t in topsets if t['ExerciseId'] is not None])
exercises = [] exercises = []
for exercise_id in exercise_ids: for exercise_id in exercise_ids:
exercises.append({ exercises.append({
'ExcerciseId': exercise_id, 'ExerciseId': exercise_id,
'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExcerciseId'] == exercise_id), 'Unknown') 'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExerciseId'] == exercise_id), 'Unknown')
}) })
return exercises return exercises

Binary file not shown.