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)
+47 -7
View File
@@ -12,7 +12,7 @@
<button
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100"
title="Show Progress Graph"
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id) }}"
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id, epoch='All', forecast='true' if forecast_enabled else 'false', forecast_weeks=forecast_weeks, forecast_reps=forecast_target_reps) }}"
hx-target="#exercise-history-container" hx-swap="outerHTML">
<svg class="w-5 h-5 border border-gray-300 rounded p-0.5" fill="none" stroke="currentColor"
viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
@@ -27,10 +27,50 @@
<h2 class="text-xs font-semibold text-blue-200 mb-4 text-center">
{{ best_fit_formula.kg_per_week }} kg/week, {{ best_fit_formula.kg_per_month }} kg/month
</h2>
{% else %}
<div class="mb-4"></div>
{% endif %}
<table class="w-full text-left text-sm text-gray-500">
{% else %}
<div class="mb-4"></div>
{% endif %}
{% if forecast_enabled and forecast.available %}
<div class="mb-4 rounded-lg border border-emerald-100 bg-emerald-50/70 p-3 text-left">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
<div>
<div class="text-xs font-semibold uppercase tracking-wide text-emerald-800">Projected rep-to-weight map</div>
<div class="text-sm text-gray-700">In {{ forecast.horizon_weeks }} weeks · projected E1RM {{ forecast.projected_value }}kg</div>
</div>
<div class="text-xs text-gray-500 sm:text-right">
Based on {{ forecast.observed_rep_min }}–{{ forecast.observed_rep_max }} reps in view<br>
expanded by ±{{ forecast.rep_buffer }} reps
</div>
</div>
<div class="mt-3 overflow-x-auto rounded border border-emerald-100 bg-white">
<table class="w-full text-left text-xs text-gray-600">
<thead class="bg-gray-50 text-gray-500">
<tr>
<th class="px-3 py-2 font-medium">Reps</th>
<th class="px-3 py-2 font-medium">Est. load</th>
<th class="px-3 py-2 font-medium">Model range</th>
<th class="px-3 py-2 font-medium text-right">Proj. E1RM</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
{% for top_set in forecast.top_sets %}
<tr class="cursor-pointer {% if forecast.selected_reps == top_set.repetitions %}bg-emerald-50 text-emerald-800 font-semibold{% else %}hover:bg-gray-50{% endif %}"
title="View {{ top_set.repetitions }} reps on the graph"
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id, epoch='All', forecast='true', forecast_weeks=forecast_weeks, forecast_reps=top_set.repetitions) }}"
hx-target="#exercise-history-container" hx-swap="outerHTML">
<td class="px-3 py-2">{{ top_set.repetitions }}</td>
<td class="px-3 py-2">{{ top_set.weight_display }}kg</td>
<td class="px-3 py-2">{{ top_set.lower_weight_display }}–{{ top_set.upper_weight_display }}kg</td>
<td class="px-3 py-2 text-right">{{ top_set.e1rm_display }}kg</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="mt-2 text-[11px] text-gray-400">Click a row to return to the graph with that rep target selected. Loads rounded to {{ forecast.target_weight_increment_display }}kg increments.</div>
</div>
{% endif %}
<table class="w-full text-left text-sm text-gray-500">
<thead class="text-xs text-gray-700 uppercase bg-gray-100">
<tr>
<th scope="col" class="px-3 py-2">Date</th>
@@ -63,7 +103,7 @@
<td colspan="2" class="px-3 py-3 text-center">
<button
class="text-sm text-blue-600 hover:underline font-medium px-4 py-2 border border-blue-600 rounded"
hx-get="{{ url_for('workout.get_exercise_history', person_id=person_id, exercise_id=exercise_id, limit=limit, offset=offset + limit, source_topset_id=source_topset_id) }}"
hx-get="{{ url_for('workout.get_exercise_history', person_id=person_id, exercise_id=exercise_id, limit=limit, offset=offset + limit, source_topset_id=source_topset_id, forecast='true' if forecast_enabled else 'false', forecast_weeks=forecast_weeks, forecast_reps=forecast_target_reps) }}"
hx-target="#history-load-more-{{ source_topset_id }}-{{ offset + limit }}" hx-swap="outerHTML">
Load More
</button>
@@ -81,4 +121,4 @@
</tbody>
</table>
</div>
{% endif %}
{% endif %}
+5 -33
View File
@@ -79,7 +79,7 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
<button
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-600"
title="Show History"
hx-get="{{ url_for('workout.get_exercise_history', person_id=person_id, exercise_id=exercise_id, source_topset_id=latest_topset_id) }}"
hx-get="{{ url_for('workout.get_exercise_history', person_id=person_id, exercise_id=exercise_id, source_topset_id=latest_topset_id, forecast='true' if forecast_enabled else 'false', forecast_weeks=forecast_weeks, forecast_reps=forecast_target_reps) }}"
hx-target="#svg-plot-{{ unique_id }}" hx-swap="outerHTML">
<svg class="w-5 h-5 border border-gray-300 rounded p-0.5" fill="none" stroke="currentColor"
viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
@@ -140,7 +140,7 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
</div>
</div>
{% if forecast.selected_top_set %}
<div class="mt-3 rounded-lg border border-emerald-100 bg-white/80 px-3 py-2.5">
<div class="mt-3 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 rounded-lg border border-emerald-100 bg-white/80 px-3 py-2.5">
<div class="flex items-center justify-between gap-2">
<div>
<div class="text-xs font-semibold uppercase tracking-wide text-gray-500">Projected top set</div>
@@ -151,38 +151,10 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
<div class="font-semibold text-emerald-700">{{ forecast.selected_top_set.lower_weight_display }}–{{ forecast.selected_top_set.upper_weight_display }}kg</div>
</div>
</div>
<div class="text-[11px] text-gray-500 mt-2">
Based on {{ forecast.observed_rep_min }}–{{ forecast.observed_rep_max }} reps in view, expanded by ±{{ forecast.rep_buffer }} reps.
Click a row to use that rep target in the chart hover.
<div class="text-[11px] text-gray-500 sm:text-right">
Full rep-to-weight forecast in the table view.<br>
Based on {{ forecast.observed_rep_min }}–{{ forecast.observed_rep_max }} reps in view.
</div>
<div class="text-xs font-semibold text-gray-600 mt-3 mb-1">Rep-to-weight map</div>
<div class="mt-2 max-h-64 overflow-y-auto rounded border border-gray-100">
<table class="w-full text-xs text-left">
<thead class="sticky top-0 bg-gray-50 text-gray-500">
<tr>
<th class="px-2 py-1.5 font-medium">Reps</th>
<th class="px-2 py-1.5 font-medium">Est. load</th>
<th class="px-2 py-1.5 font-medium">Model range</th>
<th class="px-2 py-1.5 font-medium text-right">Proj. E1RM</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
{% for top_set in forecast.top_sets %}
<tr class="cursor-pointer {% if forecast.selected_reps == top_set.repetitions %}bg-emerald-50 text-emerald-800 font-semibold{% else %}bg-white text-gray-600 hover:bg-gray-50{% endif %}"
title="Use {{ top_set.repetitions }} reps for chart hover"
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id, epoch=selected_epoch, forecast='true', forecast_weeks=forecast_weeks, forecast_reps=top_set.repetitions) }}"
hx-include="#svg-plot-{{ unique_id }} [name='min_date'], #svg-plot-{{ unique_id }} [name='max_date'], #svg-plot-{{ unique_id }} [name='degree']"
hx-target="#svg-plot-{{ unique_id }}" hx-swap="outerHTML">
<td class="px-2 py-1.5">{{ top_set.repetitions }}</td>
<td class="px-2 py-1.5">{{ top_set.weight_display }}kg</td>
<td class="px-2 py-1.5">{{ top_set.lower_weight_display }}–{{ top_set.upper_weight_display }}kg</td>
<td class="px-2 py-1.5 text-right">{{ top_set.e1rm_display }}kg</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="text-[11px] text-gray-400 mt-2">Loads rounded to the nearest {{ forecast.target_weight_increment_display }}kg from your recorded increments.</div>
</div>
{% endif %}
<div class="flex flex-wrap items-center gap-2 mt-3">