Add support to set degree of line of best fit for exercise progress graphs in custom view

This commit is contained in:
Peter Stockings
2025-02-06 23:43:10 +11:00
parent 116de33df3
commit 39e91f2655
4 changed files with 145 additions and 52 deletions

18
db.py
View File

@@ -481,7 +481,7 @@ class DataBase():
'SELECT exercise_id, name FROM exercise')
return exercises
def get_exercise_progress_for_user(self, person_id, exercise_id, min_date=None, max_date=None, epoch='all'):
def get_exercise_progress_for_user(self, person_id, exercise_id, min_date=None, max_date=None, epoch='all', degree=1):
today = datetime.now()
if epoch == '1M':
min_date = today - relativedelta(months=1)
@@ -489,6 +489,7 @@ class DataBase():
min_date = today - relativedelta(months=3)
elif epoch == '6M':
min_date = today - relativedelta(months=6)
# Execute SQL query to fetch topset data for a specific person and exercise
topsets = self.execute("""
SELECT
@@ -516,13 +517,26 @@ class DataBase():
return None
# Extracting values and calculating value ranges for SVG dimensions
exercise_name = topsets[0]['exercise_name']
estimated_1rm = [t['estimated_1rm'] for t in topsets]
repetitions = [t['repetitions'] for t in topsets]
weight = [t['weight'] for t in topsets]
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, min_date, max_date)
exercise_progress = get_exercise_graph_model(
exercise_name,
estimated_1rm,
repetitions,
weight,
start_dates,
messages,
epoch,
person_id,
exercise_id,
min_date,
max_date,
degree)
return exercise_progress