WIP: When selecting an exercise on new workout view, render a graph of exercise progress for the active user

This commit is contained in:
Peter Stockings
2023-12-07 20:34:26 +11:00
parent 5bf31d0cb9
commit 469054048e
5 changed files with 120 additions and 9 deletions

28
db.py
View File

@@ -462,3 +462,31 @@ class DataBase():
exercises = self.execute(
'SELECT exercise_id, name FROM exercise')
return exercises
def get_exercise_progress_for_user(self, person_id, exercise_id):
topsets = self.execute("""
SELECT
T.topset_id,
E.name AS exercise_name,
W.person_id,
T.workout_id,
T.repetitions,
T.weight,
ROUND((100 * T.weight::NUMERIC::INTEGER) / (101.3 - 2.67123 * T.repetitions), 0)::NUMERIC::INTEGER AS estimated_1rm,
W.start_date
FROM
topset T
JOIN
exercise E ON T.exercise_id = E.exercise_id
JOIN
workout W ON T.workout_id = W.workout_id
WHERE
W.person_id = %s AND
E.exercise_id = %s
ORDER BY
W.start_date;""", [person_id, exercise_id])
# Get a list of all estimated_1rm values
estimated_1rm = [t['estimated_1rm'] for t in topsets]
# Get a list of all start_dates
start_dates = [t['start_date'] for t in topsets]
return (estimated_1rm, start_dates)