Move forecast map into exercise history

This commit is contained in:
Peter Stockings
2026-09-06 14:38:30 +10:00
parent 7af0202c30
commit d26da9a066
3 changed files with 99 additions and 69 deletions
+47 -29
View File
@@ -297,40 +297,58 @@ def get_most_recent_topset_for_exercise(person_id, workout_id):
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
@workout_bp.route("/person/<int:person_id>/exercise/<int:exercise_id>/history", methods=['GET'])
def get_exercise_history(person_id, exercise_id):
limit = request.args.get('limit', type=int, default=5)
offset = request.args.get('offset', type=int, default=0)
source_topset_id = request.args.get('source_topset_id', type=int)
topsets = db.get_recent_topsets_for_exercise(person_id, exercise_id, limit, offset)
title = "History"
best_fit_formula = None
latest_workout_id = None
latest_topset_id = None
if topsets:
# Fetch progress data to get title and best_fit_formula if there's history
exercise_progress = db.get_exercise_progress_for_user(
person_id, exercise_id, epoch='all')
if exercise_progress:
title = exercise_progress.get('title', "History")
best_fit_formula = exercise_progress.get('best_fit_formula')
latest_workout_id = exercise_progress.get('latest_workout_id')
latest_topset_id = exercise_progress.get('latest_topset_id')
def get_exercise_history(person_id, exercise_id):
limit = request.args.get('limit', type=int, default=5)
offset = request.args.get('offset', type=int, default=0)
source_topset_id = request.args.get('source_topset_id', type=int)
forecast_enabled = request.args.get('forecast', '').lower() in ('1', 'true', 'yes', 'on')
forecast_weeks = request.args.get('forecast_weeks', type=int, default=8)
forecast_weeks = max(4, min(forecast_weeks, 26))
forecast_target_reps = request.args.get('forecast_reps', type=int)
if forecast_target_reps is not None:
forecast_target_reps = max(1, min(forecast_target_reps, 20))
topsets = db.get_recent_topsets_for_exercise(person_id, exercise_id, limit, offset)
title = "History"
best_fit_formula = None
latest_workout_id = None
latest_topset_id = None
forecast = {'available': False}
if topsets:
# Fetch progress data to get title and best_fit_formula if there's history
exercise_progress = db.get_exercise_progress_for_user(
person_id,
exercise_id,
epoch='all',
forecast_enabled=forecast_enabled,
forecast_weeks=forecast_weeks,
forecast_target_reps=forecast_target_reps)
if exercise_progress:
title = exercise_progress.get('title', "History")
best_fit_formula = exercise_progress.get('best_fit_formula')
latest_workout_id = exercise_progress.get('latest_workout_id')
latest_topset_id = exercise_progress.get('latest_topset_id')
forecast = exercise_progress.get('forecast', forecast)
forecast_target_reps = exercise_progress.get('forecast_target_reps', forecast_target_reps)
return render_template('partials/exercise_history.html',
person_id=person_id,
exercise_id=exercise_id,
topsets=topsets,
limit=limit,
offset=offset,
source_topset_id=source_topset_id,
title=title,
best_fit_formula=best_fit_formula,
latest_workout_id=latest_workout_id,
latest_topset_id=latest_topset_id)
source_topset_id=source_topset_id,
title=title,
best_fit_formula=best_fit_formula,
latest_workout_id=latest_workout_id,
latest_topset_id=latest_topset_id,
forecast=forecast,
forecast_enabled=forecast_enabled,
forecast_weeks=forecast_weeks,
forecast_target_reps=forecast_target_reps)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>", methods=['GET'])
def show_workout(person_id, workout_id):
@@ -341,4 +359,4 @@ def show_workout(person_id, workout_id):
return redirect(url_for('calendar.get_calendar', person_id=person_id)) # Redirect to calendar on error
if htmx:
return render_block(current_app.jinja_env, 'workout.html', 'content', **view_model)
return render_template('workout.html', **view_model)
return render_template('workout.html', **view_model)