Add min/max filter filter for exercise sparkline graph

This commit is contained in:
Peter Stockings
2024-07-29 21:27:30 +10:00
parent 73c1e115bb
commit 1384eb007b
4 changed files with 91 additions and 5 deletions

28
db.py
View File

@@ -494,7 +494,7 @@ class DataBase():
start_dates = [t['start_date'] for t in topsets]
messages = [f'{t["repetitions"]} x {t["weight"]}kg ({t["estimated_1rm"]}kg E1RM) on {t["start_date"].strftime("%d %b %y")}' for t in topsets]
exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages, epoch, person_id, exercise_id)
exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages, epoch, person_id, exercise_id, min_date, max_date)
return exercise_progress
@@ -546,4 +546,30 @@ class DataBase():
# Return a tuple containing the person's name and their workout notes
return (person_name, workout_notes_list)
def get_exercise_earliest_and_latest_dates(self, person_id, exercise_id):
sql_query = """
SELECT
w.start_date
FROM workout w
INNER JOIN topset t on w.workout_id = t.workout_id
INNER JOIN exercise e on t.exercise_id = e.exercise_id
WHERE w.person_id = %s AND e.exercise_id = %s
ORDER BY w.start_date DESC;
"""
# Execute the SQL query
workout_exercise_dates = self.execute(sql_query, [person_id, exercise_id])
if not workout_exercise_dates:
return None, None
latest_date = workout_exercise_dates[0]['start_date']
earliest_date = workout_exercise_dates[-1]['start_date']
return earliest_date, latest_date