Added safety checks to the graph regression logic in utils.py. This stops those "illegal value" server warnings and makes the math more efficient for small datasets
This commit is contained in:
18
utils.py
18
utils.py
@@ -48,18 +48,22 @@ def get_exercise_graph_model(title, estimated_1rm, repetitions, weight, start_da
|
||||
|
||||
best_fit_points = []
|
||||
try:
|
||||
if len(relative_positions) > 1: # Ensure there are enough points for polyfit
|
||||
# Fit a polynomial of the given degree
|
||||
coeffs = np.polyfit(relative_positions, estimated_1rm_scaled, degree)
|
||||
# Filter out NaNs if any (though scaled values shouldn't have them if ranges are correct)
|
||||
mask = ~np.isnan(estimated_1rm_scaled)
|
||||
x_fit = relative_positions[mask]
|
||||
y_fit = estimated_1rm_scaled[mask]
|
||||
|
||||
# Ensure we have enough unique X positions for the given degree
|
||||
if len(np.unique(x_fit)) > degree:
|
||||
coeffs = np.polyfit(x_fit, y_fit, degree)
|
||||
poly_fit = np.poly1d(coeffs)
|
||||
y_best_fit = poly_fit(relative_positions)
|
||||
best_fit_points = list(zip(y_best_fit.tolist(), relative_positions.tolist()))
|
||||
else:
|
||||
raise ValueError("Not enough data points for polyfit")
|
||||
except (np.linalg.LinAlgError, ValueError) as e:
|
||||
# Handle cases where polyfit fails
|
||||
best_fit_points = []
|
||||
except (np.linalg.LinAlgError, ValueError, TypeError) as e:
|
||||
# Handle cases where polyfit fails or input is invalid
|
||||
best_fit_points = []
|
||||
m, b = 0, 0
|
||||
|
||||
# Prepare data for plots
|
||||
repetitions_data = {
|
||||
|
||||
Reference in New Issue
Block a user