Display liner formula for E1RM over time, and weekly/monthly progress in weight (this part doesnt work well, will probably remove)

This commit is contained in:
Peter Stockings
2024-03-09 17:15:08 +11:00
parent fd04eb00b1
commit e3de9f886b
3 changed files with 21 additions and 2 deletions

View File

@@ -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
}