Improve forecast readability and rep targets

This commit is contained in:
Peter Stockings
2026-09-06 14:30:23 +10:00
parent 499ecdc3c2
commit 7af0202c30
4 changed files with 175 additions and 60 deletions
+98 -40
View File
@@ -32,12 +32,17 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
{% endfor %}
{% endmacro %}
{% macro forecast_circles(data_points, labels, color) %}
{% macro forecast_circles(data_points, details, color) %}
{% for value, position in data_points %}
{% set x = (position * vb_width)+margin %}
{% set y = (vb_height - value)+margin %}
<circle cx="{{ x | int }}" cy="{{ y | int }}" r="1.6" fill="{{ color }}" stroke="{{ color }}"
class="pnt-{{ unique_id }}" data-msg="{{ labels[loop.index0][1] }}"></circle>
class="pnt-{{ unique_id }}"
data-kind="{{ details[loop.index0].kind }}"
data-date="{{ details[loop.index0].date }}"
data-e1rm="{{ details[loop.index0].e1rm }}"
data-topset="{{ details[loop.index0].top_set }}"
data-range="{{ details[loop.index0].range }}"></circle>
{% endfor %}
{% endmacro %}
@@ -53,15 +58,16 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
{% set parts = [random_int()] %}
{% set unique_id = parts|join('-') %}
<div class="relative" id="svg-plot-{{ unique_id }}" _="
on mouseover from .pnt-{{ unique_id }}
put event.target @data-msg into #popover-{{ unique_id }}
then remove .hidden from #popover-{{ unique_id }}
on mouseout from .pnt-{{ unique_id }}
add .hidden to #popover-{{ unique_id }}">
<div id="popover-{{ unique_id }}" class="absolute t-0 r-0 hidden bg-white border border-gray-300 p-2 z-10">
<!-- Popover content will be dynamically inserted here -->
</div>
<div class="relative" id="svg-plot-{{ unique_id }}" _="
on mouseover from .pnt-{{ unique_id }}
put event.target @data-kind into #popover-kind-{{ unique_id }}
then put event.target @data-date into #popover-date-{{ unique_id }}
then put event.target @data-e1rm into #popover-e1rm-{{ unique_id }}
then put event.target @data-topset into #popover-topset-{{ unique_id }}
then put event.target @data-range into #popover-range-{{ unique_id }}
then remove .hidden from #popover-{{ unique_id }}
on mouseout from .pnt-{{ unique_id }}
add .hidden to #popover-{{ unique_id }}">
<div class="flex items-center justify-between sm:justify-center relative mb-1">
<div class="flex flex-col sm:flex-row items-center justify-center w-full gap-x-2">
<h4 class="text-lg font-semibold text-blue-400">{{ title }}</h4>
@@ -137,24 +143,46 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
<div class="mt-3 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">Estimated top set</div>
<div class="text-lg font-bold text-gray-800">{{ forecast.selected_top_set.weight }}kg × {{ forecast.selected_top_set.repetitions }}</div>
<div class="text-xs font-semibold uppercase tracking-wide text-gray-500">Projected top set</div>
<div class="text-lg font-bold text-gray-800">{{ forecast.selected_top_set.weight_display }}kg × {{ forecast.selected_top_set.repetitions }} reps</div>
</div>
<div class="text-right text-xs text-gray-500">
<div>Likely range</div>
<div class="font-semibold text-emerald-700">{{ forecast.selected_top_set.lower_weight }}–{{ forecast.selected_top_set.upper_weight }}kg</div>
<div>Model range</div>
<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="flex flex-wrap items-center gap-1.5 mt-2">
<span class="text-xs text-gray-400 mr-1">Target reps</span>
{% for reps in forecast.target_reps %}
<button class="px-2 py-0.5 rounded text-xs {% if forecast.selected_reps == reps %}bg-emerald-700 text-white{% else %}bg-emerald-50 text-emerald-700 hover:bg-emerald-100{% endif %}"
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=reps) }}"
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">{{ reps }}</button>
{% endfor %}
<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>
<div class="text-[11px] text-gray-400 mt-2">Rounded to the nearest {{ forecast.target_weight_increment }}kg based on your recorded loads.</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">
@@ -259,7 +287,7 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
{% if forecast_enabled and forecast.available %}
<path d="{{ path_band(forecast_band_lower, forecast_band_upper, vb_height) }}" fill="#10b981" fill-opacity="0.10" stroke="none"></path>
<path d="{{ path(forecast_points, vb_height) }}" stroke="#059669" stroke-width="2" stroke-dasharray="5,3" fill="none"></path>
{{ forecast_circles(forecast_points, forecast_labels, '#059669') }}
{{ forecast_circles(forecast_points, forecast_details, '#059669') }}
<line x1="{{ ((forecast_start_position * vb_width) + margin) | int }}" y1="{{ margin }}" x2="{{ ((forecast_start_position * vb_width) + margin) | int }}" y2="{{ vb_height + margin }}" stroke="#059669" stroke-width="0.8" stroke-dasharray="2,2" stroke-opacity="0.5"></line>
{% endif %}
{% for plot in plots %}
@@ -268,28 +296,58 @@ M{% for value, position in lower_points %}{{ (((position * vb_width) + margin) |
</g>
{% endfor %}
<g style="fill-opacity: 0%">
{% for pos, message in plot_labels %}
{% set x = (pos * vb_width) - (stroke_width/2) + margin %}
{% set y = 0 %}
{% set width = stroke_width %}
{% set height = vb_height + margin %}
<rect x="{{ x | int }}" y="{{ y | int }}" width="{{ width | int }}" height="{{ height | int }}"
class="pnt-{{ unique_id }}" data-msg="{{ message }}"></rect>
<g style="fill-opacity: 0%">
{% for detail in plot_details %}
{% set x = (detail.position * vb_width) - (stroke_width/2) + margin %}
{% set y = 0 %}
{% set width = stroke_width %}
{% set height = vb_height + margin %}
<rect x="{{ x | int }}" y="{{ y | int }}" width="{{ width | int }}" height="{{ height | int }}"
class="pnt-{{ unique_id }}"
data-kind="{{ detail.kind }}"
data-date="{{ detail.date }}"
data-e1rm="{{ detail.e1rm }}"
data-topset="{{ detail.top_set }}"
data-range="{{ detail.range }}"></rect>
{% endfor %}
{% if forecast_enabled and forecast.available %}
{% for pos, message in forecast_labels %}
{% set x = (pos * vb_width) - (stroke_width/2) + margin %}
{% for detail in forecast_details %}
{% set x = (detail.position * vb_width) - (stroke_width/2) + margin %}
<rect x="{{ x | int }}" y="0" width="{{ stroke_width | int }}" height="{{ (vb_height + margin) | int }}"
class="pnt-{{ unique_id }}" data-msg="{{ message }}"></rect>
class="pnt-{{ unique_id }}"
data-kind="{{ detail.kind }}"
data-date="{{ detail.date }}"
data-e1rm="{{ detail.e1rm }}"
data-topset="{{ detail.top_set }}"
data-range="{{ detail.range }}"></rect>
{% endfor %}
{% endif %}
</g>
<path d="{{ path_best_fit(best_fit_points, vb_height) }}" stroke="gray" stroke-dasharray="2,1" fill="none"
stroke-opacity="60%" />
</svg>
<div class="flex justify-center pt-2">
<path d="{{ path_best_fit(best_fit_points, vb_height) }}" stroke="gray" stroke-dasharray="2,1" fill="none"
stroke-opacity="60%" />
</svg>
<div id="popover-{{ unique_id }}" class="hidden mt-2 rounded-lg border border-gray-200 bg-white px-3 py-2 shadow-sm">
<div class="flex items-center justify-between gap-3 mb-1.5">
<div id="popover-kind-{{ unique_id }}" class="text-xs font-semibold uppercase tracking-wide text-emerald-700"></div>
<div id="popover-date-{{ unique_id }}" class="text-xs text-gray-500"></div>
</div>
<div class="grid grid-cols-3 gap-2 text-xs">
<div class="rounded bg-gray-50 px-2 py-1.5">
<div class="text-gray-400">E1RM</div>
<div id="popover-e1rm-{{ unique_id }}" class="font-semibold text-gray-800"></div>
</div>
<div class="rounded bg-gray-50 px-2 py-1.5">
<div class="text-gray-400">Top set</div>
<div id="popover-topset-{{ unique_id }}" class="font-semibold text-gray-800"></div>
</div>
<div class="rounded bg-emerald-50 px-2 py-1.5">
<div class="text-emerald-600">Range</div>
<div id="popover-range-{{ unique_id }}" class="font-semibold text-emerald-800"></div>
</div>
</div>
</div>
<div class="flex justify-center pt-2">
{% for plot in plots %}
<div class="flex items-center px-2 select-none cursor-pointer" _="on load put document.querySelector('#svg-plot-{{ unique_id }} g.{{plot.label}}') into my.plot_line
on click toggle .hidden on my.plot_line then toggle .line-through on me">