From faa7c5789e4f22ededb2c7039da3b637c541ee27 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 10 Sep 2022 13:59:21 +1000 Subject: [PATCH] Display heaviest topsets over time on home page --- app.py | 6 +- db.py | 21 ++- static/edit-icon.svg | 4 + templates/index.html | 291 ++---------------------------------------- templates/person.html | 2 +- utils.py | 52 ++++++++ workout.db | Bin 24576 -> 24576 bytes 7 files changed, 94 insertions(+), 282 deletions(-) create mode 100644 static/edit-icon.svg diff --git a/app.py b/app.py index b350ce1..517fc86 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ from flasgger import Swagger, swag_from from db import DataBase from decorators import validate_person, validate_topset, validate_workout +from utils import get_people_and_exercise_rep_maxes app = Flask(__name__) app.config.from_pyfile('config.py') @@ -14,7 +15,10 @@ db = DataBase(app) @ app.route("/") @ swag_from('swagger/dashboard.yml') def dashboard(): - return render_template('index.html') + all_topsets = db.get_all_topsets() + people_and_exercise_rep_maxes = get_people_and_exercise_rep_maxes( + all_topsets) + return render_template('index.html', model=people_and_exercise_rep_maxes) @ app.route("/person/") diff --git a/db.py b/db.py index 9f4e7c8..1ace723 100644 --- a/db.py +++ b/db.py @@ -1,7 +1,7 @@ import datetime import sqlite3 -from utils import get_all_exercises_from_topsets, get_workouts +from utils import get_all_exercises_from_topsets, get_people_and_exercise_rep_maxes, get_workouts class DataBase(): @@ -170,3 +170,22 @@ class DataBase(): "Weight": topset['Weight'], "Repetitions": topset['Repetitions'] } + + def get_all_topsets(self): + all_topsets = self.execute(""" + SELECT + P.PersonId, + P.Name AS PersonName, + W.WorkoutId, + W.StartDate, + T.TopSetId, + 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 Exercise E ON T.ExerciseId=E.ExerciseId""") + + return all_topsets diff --git a/static/edit-icon.svg b/static/edit-icon.svg new file mode 100644 index 0000000..2fafe56 --- /dev/null +++ b/static/edit-icon.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 1adf3fc..e846808 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,24 +3,26 @@ {% block content %}
+ {% for p in model %}
-

Gabe

+

{{ p['PersonName'] }}

Current rep maxes
+ {% for e in p['Exercises'] %}
-

Bench

+

{{ e['ExerciseName'] }}

@@ -32,300 +34,31 @@ class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Rep Max - - - - - - - - - - - - - - - - - - - - - - -
- Estimated 1 Rep max -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
-
-
-
-
-
-
-
-
-

Squat

- - - - - - - - - + {% for rm in e['RepMaxes'] %} - - - - - - - - - - - - - - - - + {% endfor %} +
- Date - - Rep Max - - Estimated 1 Rep max -
- Apr 23 ,2021 + {{ rm['StartDate'] }} - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg + {{ rm['Repetitions'] }} x {{ rm['Weight'] }}kg
+ {% endfor %}
+ {% endfor %} -
- -
-
-

Michael

- Current rep maxes -
- -
- -
-
-
-
-

Bench

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Date - - Rep Max - - Estimated 1 Rep max -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
-
-
-
-
- -
-
-
-
-

Squat

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Date - - Rep Max - - Estimated 1 Rep max -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
- Apr 23 ,2021 - - 5 x 100kg - - 130kg -
-
-
-
-
-
diff --git a/templates/person.html b/templates/person.html index cf698ce..c47acaf 100644 --- a/templates/person.html +++ b/templates/person.html @@ -2,7 +2,7 @@ {% block content %}
-
+
diff --git a/utils.py b/utils.py index 3e157dc..a99401d 100644 --- a/utils.py +++ b/utils.py @@ -1,3 +1,6 @@ +from datetime import datetime + + def get_workouts(topsets): # Get all unique workout_ids (No duplicates) workout_ids = set([t['WorkoutId'] @@ -26,3 +29,52 @@ def get_all_exercises_from_topsets(topsets): 'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExerciseId'] == exercise_id), 'Unknown') }) return exercises + + +def get_rep_maxes_for_person(person_topsets): + person_exercises = get_all_exercises_from_topsets(person_topsets) + + rep_maxes_in_exercises = [] + for e in person_exercises: + exercise_topsets = [ + t for t in person_topsets if t['ExerciseId'] == e['ExerciseId']] + set_reps = set([t['Repetitions'] for t in exercise_topsets]) + + topsets_for_exercise = [] + for rep in set_reps: + reps = [t for t in exercise_topsets if t['Repetitions'] == rep] + max_weight = max([t['Weight'] for t in reps]) + max_topset_for_rep = [t for t in reps if t['Weight'] == max_weight] + topsets_for_exercise.append({ + 'StartDate': max_topset_for_rep[0]['StartDate'], + 'Repetitions': rep, + 'Weight': max_weight + }) + + # datetime.strptime(x['StartDate'], "%Y-%m-%d") + topsets_for_exercise.sort( + key=lambda x: x['Repetitions'], reverse=True) + + rep_maxes_in_exercises.append({ + 'ExerciseId': e['ExerciseId'], + 'ExerciseName': e['ExerciseName'], + 'RepMaxes': topsets_for_exercise, + }) + return rep_maxes_in_exercises + + +def get_people_and_exercise_rep_maxes(topsets): + # Get all unique workout_ids (No duplicates) + people_ids = set([t['PersonId'] for t in topsets]) + + # Group topsets into workouts + people = [] + for person_id in people_ids: + workouts_for_person = [ + t for t in topsets if t['PersonId'] == person_id] + people.append({ + 'PersonId': person_id, + 'PersonName': workouts_for_person[0]['PersonName'], + 'Exercises': get_rep_maxes_for_person(workouts_for_person) + }) + return people diff --git a/workout.db b/workout.db index 794c68852abb4711a2f52a13fb0d50a13aab5e04..1ec3fa705a7d83d2c74e160e4f21a18f5bc33202 100644 GIT binary patch delta 60 zcmV-C0K@-)zyW~30gxL3>yaEo0qe0~p-%@7y#QJZ)c}(UP_zOI)w2;07Yno1Tb~00 S20@c{Uq=K0000S-!Cya5&{m0qL<|p-%|_003JH)c_B@lL%0>vk?#%3$xW*p92Cx R29tJQM+6541^|=6Uq5Ex6CVHo