Add running fitness history and configurable heart rate zones

This commit is contained in:
Peter Stockings
2026-10-22 23:20:35 +11:00
parent b8eb6d10f8
commit 95e751d05c
15 changed files with 534 additions and 2 deletions
+12
View File
@@ -0,0 +1,12 @@
{% set zones = fitness_zones(current_user) %}
<section class="panel settings-card"><span class="eyebrow">RUNNING FITNESS</span><h2>Heart-rate zones</h2>
<p>{{ zones.source }}{% if zones.max_hr %} · {{ zones.max_hr }} bpm{% endif %}</p>
<p>{% for label in zones.labels %}Z{{ loop.index }}: {{ label }} bpm{{ ' · ' if not loop.last }}{% endfor %}</p>
<form method="post" action="{{ url_for('training.zones') }}" class="stack"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<label>Zone calculation<select name="mode"><option value="auto" {{ 'selected' if zones.mode == 'auto' }}>Automatic from age</option><option value="max" {{ 'selected' if zones.mode == 'max' }}>Manual maximum heart rate</option><option value="custom" {{ 'selected' if zones.mode == 'custom' }}>Manual zone boundaries</option></select></label>
<label>Birthday (optional, for automatic updates)<input type="date" name="birthday" value="{{ zones.config.get('birthday', '') }}"></label>
<label>Maximum HR (for manual maximum mode)<input type="number" name="max_hr" min="100" max="230" value="{{ zones.config.get('max_hr', '') }}"></label>
{% for boundary in zones.boundaries %}<label>Z{{ loop.index + 1 }} starts at (bpm, for manual zones)<input type="number" name="z{{ loop.index + 1 }}" min="30" max="230" value="{{ boundary }}" required></label>{% endfor %}
<p class="field-help">Automatic mode uses 220 minus age, or 190 bpm without a birthday. Zones begin at 65%, 80%, 87% and 95% of maximum HR (rounded to the nearest bpm). These are Stride's published defaults, which may differ from Strava. Age-based zones update on your birthday. Manual settings remain fixed until edited.</p>
<p class="field-help">New runs and rest days update the fitness graph automatically. Zone edits recalculate all historical scores using the current zones. Existing three-band Stats settings are independent.</p>
<button class="button primary">Save fitness zones</button></form></section>
+1 -1
View File
@@ -1,4 +1,4 @@
{% if owner_view %}<section class="panel settings-card"><span class="eyebrow">PRIVATE SESSION CONTEXT</span><h2>How did this run feel?</h2>
{% if owner_view %}{% set effort = run_effort(activity, fitness_zones(current_user).boundaries) %}<section class="panel settings-card"><h2>Run effort: {{ '%.1f'|format(effort.score) if effort.score is not none else 'Unscored' }}</h2><p>{{ effort.reason }} · HR coverage {{ effort.coverage }}%. <a href="{{ url_for('training.fitness') }}">View fitness history</a></p></section><section class="panel settings-card"><span class="eyebrow">PRIVATE SESSION CONTEXT</span><h2>How did this run feel?</h2>
<form method="post" action="{{ url_for('training.context', activity_id=activity.id) }}" class="stack"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<label>Perceived effort (1–10)<input name="perceived_effort" type="number" min="1" max="10" value="{{ activity.session_context.get('perceived_effort', '') }}"></label>
<label>Fatigue before the run (0–10)<input name="fatigue" type="number" min="0" max="10" value="{{ activity.session_context.get('fatigue', '') }}"></label>
+1
View File
@@ -1,3 +1,4 @@
{% include '_fitness_zones.html' %}
<section class="panel settings-card"><span class="eyebrow">EFFORT DISTRIBUTION</span><h2>Your heart-rate bands</h2>
<p class="field-help">Set two boundaries for your lower, middle and upper effort bands. Use your own chosen thresholds; these labels do not infer physiological zones.</p>
<form method="post" action="{{ url_for('training.bands') }}" class="stack"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
+1
View File
@@ -14,6 +14,7 @@
<a class="brand" href="{{ url_for('web.dashboard') }}"><span class="brand-mark">s</span>stride<span class="brand-dot">.</span></a>
<nav class="header-nav" aria-label="Main navigation"><a class="{{ 'active' if request.endpoint == 'web.dashboard' }}" href="{{ url_for('web.dashboard') }}">Dashboard</a><a class="{{ 'active' if request.endpoint in ('web.friends', 'web.profile') }}" href="{{ url_for('web.friends') }}">Friends</a></nav>
<a class="stats-nav {{ 'active' if request.endpoint == 'web.stats' }}" href="{{ url_for('web.stats') }}">Stats</a>
<a class="stats-nav {{ 'active' if request.endpoint == 'training.fitness' }}" href="{{ url_for('training.fitness') }}">Fitness</a>
<a class="stats-nav {{ 'active' if request.blueprint == 'planner' }}" href="{{ url_for('planner.index') }}">Routes</a>
<div class="header-actions">{% if request.endpoint != 'web.profile' %}<a class="button primary header-import" href="{{ url_for('web.settings') }}">{{ icon('plus') }} Import run</a>{% endif %}<details class="account-dropdown"><summary class="avatar" aria-label="Account menu" title="Account menu">{{ current_user.display_name[:1]|upper }}</summary><div class="account-dropdown-menu"><strong>{{ current_user.display_name }}</strong><a href="{{ url_for('web.settings') }}">Settings & Garmin sync</a><a href="{{ url_for('web.settings') }}">Import runs</a><form method="post" action="{{ url_for('web.logout') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><button class="text-button">Sign out</button></form></div></details></div>
</header>
+20
View File
@@ -0,0 +1,20 @@
{% extends 'base.html' %}
{% block title %}Running fitness · Stride{% endblock %}
{% block head %}<link rel="stylesheet" href="{{ url_for('static', filename='fitness.css') }}">{% endblock %}
{% block content %}
<div class="fitness-page">
<span class="eyebrow">YOUR TRAINING OVER TIME</span><h1>Running fitness</h1>
<p>Accumulated running effort, fatigue and form. Scores describe training load, alongside your performance trends.</p>
<p>{{ data.zones.source }} · <a href="{{ url_for('web.settings') }}">Edit fitness zones</a></p>
<p>{% for label in data.zones.labels %}Z{{ loop.index }}: {{ label }} bpm{{ ' · ' if not loop.last }}{% endfor %}</p>
{% if data.series %}
{% set latest = data.series[-1] %}
<div class="stats-grid">{% for key in ['fitness', 'fatigue', 'form'] %}<article class="stat-card"><div class="stat-label">{{ key|upper }}</div><div class="stat-value">{{ '%.1f'|format(latest[key]) }}</div><p>{{ 'Provisional estimate' if latest.provisional else 'Running load estimate' }}</p></article>{% endfor %}</div>
<section class="panel"><div class="section-head"><h2>Fitness, fatigue & form</h2><label>Show <select id="fitness-range"><option value="90">90 days</option><option value="365">1 year</option><option value="all" selected>All history</option></select></label></div><div class="chart-wrap"><canvas id="fitness-chart" role="img" aria-label="Daily running fitness, fatigue and form"></canvas></div></section>
{% endif %}
<p>{{ data.runs|length }} historical runs · {{ data.unscored }} unscored. Runs missing sufficient HR remain unscored. On those days the model uses only known effort, so subsequent values may underestimate load.</p>
<details class="panel methodology"><summary>How these scores work</summary><p>Effort v1 adds recorded moving minutes in Z1–Z5 with weights 1, 2, 3, 4 and 5. At each boundary HR belongs to the higher zone. At least 80% of timer time must have usable HR; missing time is not extrapolated. Recording breaks, stops and suspect HR are excluded by the recording analysis.</p><p>Each calendar day in your timezone updates fitness by (daily effort − previous fitness) × (1 − exp(−1/42)); fatigue uses 7 instead of 42. Form is same-day fitness minus fatigue. Multiple runs are summed; rest days contribute zero. The full history is calculated before choosing the visible range.</p><p>The model starts at zero at your earliest imported run; its first 126 days are provisional. Missing runs and unscored sessions can understate load. Only running is included. Changing HR zones recalculates all history with those zones. These are Stride estimates, with their own scale, rather than exact Strava scores.</p></details>
<section class="panel"><div class="section-head"><h2>Run effort</h2></div><div class="activity-table-wrap"><table><thead><tr><th>Date</th><th>Run</th><th>Effort</th><th>HR coverage</th></tr></thead><tbody>{% for run in data.runs %}<tr><td>{{ run.day }}</td><td><a href="{{ url_for('web.activity', activity_id=run.id) }}">{{ run.title }}</a></td><td title="{{ run.reason }}">{{ '%.1f'|format(run.score) if run.score is not none else 'Unscored' }}</td><td>{{ run.coverage }}%</td></tr>{% else %}<tr><td colspan="4">Import runs to build your fitness history.</td></tr>{% endfor %}</tbody></table></div></section>
</div>
{% endblock %}
{% block scripts %}<script id="fitness-data" type="application/json" data-url="{{ url_for('training.fitness_data') }}">{{ data|tojson }}</script><script src="{{ url_for('static', filename='vendor/chart.umd.js') }}"></script><script src="{{ url_for('static', filename='fitness.js') }}"></script>{% endblock %}