From e3de9f886b05944b7e0059238b52cfd50d44fcde Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 9 Mar 2024 17:15:08 +1100 Subject: [PATCH] Display liner formula for E1RM over time, and weekly/monthly progress in weight (this part doesnt work well, will probably remove) --- templates/base.html | 3 ++- templates/partials/sparkline.html | 7 ++++++- utils.py | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/templates/base.html b/templates/base.html index 342b6b6..9fec697 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,8 @@ Workout Tracker + @@ -14,7 +16,6 @@ - diff --git a/templates/partials/sparkline.html b/templates/partials/sparkline.html index faa2914..f9ac889 100644 --- a/templates/partials/sparkline.html +++ b/templates/partials/sparkline.html @@ -46,7 +46,12 @@ -

{{ title }}

+

{{ title }}

+

+ {% if best_fit_formula %} + y = {{ best_fit_formula.slope }}x {% if best_fit_formula.intercept != 0 %}+ {{ best_fit_formula.intercept }}{% endif %}, {{ best_fit_formula.kg_per_week }} kg/week, {{ best_fit_formula.kg_per_month }} kg/month + {% endif %} +

{% for plot in plots %} diff --git a/utils.py b/utils.py index 6b0787d..6450d96 100644 --- a/utils.py +++ b/utils.py @@ -260,6 +260,8 @@ def get_exercise_graph_model(title, estimated_1rm, repetitions, weight, start_da relative_positions = [(date - min_date).days / total_span for date in start_dates] best_fit_points = [] + best_fit_formula = {} + # trry catch LinAlgError try: # Convert relative positions and scaled estimated 1RM values to numpy arrays @@ -272,6 +274,16 @@ def get_exercise_graph_model(title, estimated_1rm, repetitions, weight, start_da # Generate points along the line of best fit y_best_fit = [m * xi + b for xi in x] best_fit_points = list(zip(y_best_fit, relative_positions)) + + # Convert the slope from scaled units per day to kg per day + slope_kg_per_day = m * (max_e1rm - min_e1rm) / total_span + + best_fit_formula = { + 'slope': round(m,1), + 'intercept': round(b,1), + 'kg_per_week': round(slope_kg_per_day * 7, 1), # Convert to kg/week + 'kg_per_month': round(slope_kg_per_day * 30, 1) # Convert to kg/month + } except: pass @@ -305,6 +317,7 @@ def get_exercise_graph_model(title, estimated_1rm, repetitions, weight, start_da 'vb_height': vb_height, 'plots': [repetitions, weight, estimated_1rm], 'best_fit_points': best_fit_points, + 'best_fit_formula': best_fit_formula, 'plot_labels': plot_labels }