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
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']

View File

@@ -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,
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
);
PRIMARY KEY("WorkoutId" AUTOINCREMENT),
FOREIGN KEY("PersonId") REFERENCES Person (PersonId)
);
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)
);
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)
);

View File

@@ -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
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
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);
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);

View File

@@ -11,7 +11,7 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div>
<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>
</div>
</div>
@@ -173,7 +173,7 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div>
<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>
</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"
id="grid-state" name="exercise_id">
{% 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 %}>{{
e['Name']}}</option>
{% 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"
id="grid-state" name="exercise_id">
{% for e in workout['Exercises'] %}
<option value="{{ e['ExcerciseId'] }}">{{
<option value="{{ e['ExerciseId'] }}">{{
e['Name']}}</option>
{% endfor %}
</select>

View File

@@ -44,8 +44,8 @@
{% for e in person['Exercises'] %}
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
{% 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 %}

View File

@@ -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

Binary file not shown.