Stats: read the effort back — trend, distribution, hard sets, per exercise
Rating a set only paid off inside the set label until now: Stats never looked at rir/rpe at all. It reads them now, in four places. lib/effort.js aggregates everything in RIR and converts back to whichever scale the profile reads. A history that mixes the two — own logs in RIR, an imported file in RPE — has to average as one series or every chart draws half the data, and RIR is the internal unit because its zero is real where RPE's floor of 6 is a convention. - an Effort card: average and share of sets taken near failure, the week-by-week curve with the week's volume in the tooltip, and where the sets land on the scale - the muscle map gains a hard-sets mode: a muscle can lead on volume and still never be trained near failure - Exercise progress carries effort on the top-set dots and as a curve of its own — the same weight with more left in the tank is progress a weight-only line draws flat - LineChart learns an inverted axis (RIR counts down as it gets harder) and per-point marks Every number carries how much of the training it speaks for: rating is optional and off by default, so an unrated set is left out rather than read as failure, and an average waits for five rated sets before it claims to be one.
This commit is contained in:
1 parent
4c829b6d1f
commit
caaf61d91e
7 files changed
+503
-21
No files matched your search
+111
-13
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX } from '../lib/exercises.js'
|
||||
import { lastBW, streakWeeks, setLabel, modeOf } from '../lib/history.js'
|
||||
import { lastBW, streakWeeks, setLabel, modeOf, effortOf } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, fmtVol, todayISO, weekKey } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
|
||||
@@ -12,26 +12,41 @@ import Icon from '../components/Icon.jsx'
|
||||
import BodyMap, { BodyMapLegend } from '../components/BodyMap.jsx'
|
||||
import { loadOfWorkouts, rankOf, MUSCLE_NAME } from '../lib/muscles.js'
|
||||
import { e1rmSeries, best1RM } from '../lib/onerm.js'
|
||||
import {
|
||||
hasEffort, displayScale, scaleName, toScale, avgRir, effortSummary, effortWeeks,
|
||||
effortHistogram, isHardSet, HARD_RIR
|
||||
} from '../lib/effort.js'
|
||||
import { Button, Segmented, SelectRow } from '../components/ui.jsx'
|
||||
|
||||
// Which muscles the training in a window actually hit — and, the point of the card,
|
||||
// which ones it keeps missing. Shading is relative within the window (lib/muscles.js).
|
||||
function MuscleBalance({ S }) {
|
||||
const [win, setWin] = useState(7)
|
||||
const [hard, setHard] = useState(false)
|
||||
const [sel, setSel] = useState(null)
|
||||
const now = Date.now()
|
||||
const inWin = S.workouts.filter(w =>
|
||||
win === 0 ? true
|
||||
: win === 7 ? weekKey(w.d) === weekKey(todayISO())
|
||||
: (w.start || new Date(w.d).getTime()) > now - win * 86400000)
|
||||
const load = loadOfWorkouts(inWin)
|
||||
// Counting only the sets taken near failure turns the map from "where did the volume go"
|
||||
// into "where did the stimulus go" — a muscle can lead on sets and still never be trained
|
||||
// hard. Offered only when the window holds ratings at all, since with none the hard map
|
||||
// would just be empty and read as "you trained nothing".
|
||||
const rated = inWin.some(w => w.entries.some(e => e.sets.some(s => s.done && isHardSet(s))))
|
||||
const on = hard && rated
|
||||
const load = loadOfWorkouts(inWin, on ? isHardSet : null)
|
||||
const { worked, missed } = rankOf(load)
|
||||
const top = worked.slice(0, 4)
|
||||
const max = worked.length ? load[worked[0]] : 0
|
||||
const sets = m => Math.round((load[m] || 0) * 10) / 10
|
||||
|
||||
return <div className="card">
|
||||
<h2>{t('Muscle balance')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {t('by sets worked')}</span></h2>
|
||||
<div className="row between" style={{ marginBottom: 8 }}>
|
||||
<h2 style={{ margin: 0 }}>{t('Muscle balance')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {on ? t('by hard sets') : t('by sets worked')}</span></h2>
|
||||
{rated && <Button size="sm" icon="flame" style={on ? { color: 'var(--yellow)' } : undefined}
|
||||
onClick={() => { setHard(h => !h); setSel(null) }}>{on ? t('Hard') : t('All')}</Button>}
|
||||
</div>
|
||||
<Segmented className="seg-range" value={win} onChange={v => { setWin(v); setSel(null) }}
|
||||
options={[{ value: 7, label: t('Week') }, { value: 30, label: '30d' }, { value: 90, label: '90d' }, { value: 0, label: t('All') }]} />
|
||||
{inWin.length ? <>
|
||||
@@ -40,23 +55,80 @@ function MuscleBalance({ S }) {
|
||||
<BodyMapLegend />
|
||||
{sel && <div className="mrow" style={{ borderTop: 'var(--hair) solid var(--sep)', marginTop: 4, paddingTop: 10 }}>
|
||||
<span className="nm"><b>{t(MUSCLE_NAME[sel])}</b></span>
|
||||
<span className="v">{sets(sel) ? t('{0} sets', sets(sel)) : t('not trained')}</span>
|
||||
<span className="v">{sets(sel) ? t('{0} sets', sets(sel)) : on ? t('no hard sets') : t('not trained')}</span>
|
||||
</div>}
|
||||
{!sel && top.map(m => <div key={m} className="mrow">
|
||||
<span className="nm">{t(MUSCLE_NAME[m])}</span>
|
||||
<span className="bar"><i style={{ width: Math.round(load[m] / max * 100) + '%' }} /></span>
|
||||
<span className="bar"><i style={{ width: Math.round(load[m] / max * 100) + '%', background: on ? 'var(--yellow)' : undefined }} /></span>
|
||||
<span className="v">{t('{0} sets', sets(m))}</span>
|
||||
</div>)}
|
||||
{missed.length > 0 && <>
|
||||
<h4 className="sec" style={{ marginTop: 12 }}>{t('Not trained in this period')}</h4>
|
||||
<h4 className="sec" style={{ marginTop: 12 }}>{on ? t('No hard sets in this period') : t('Not trained in this period')}</h4>
|
||||
<div className="mchips">{missed.map(m => <span key={m} className="mchip miss">{t(MUSCLE_NAME[m])}</span>)}</div>
|
||||
</>}
|
||||
{!missed.length && worked.length > 0 &&
|
||||
<div className="muted small" style={{ marginTop: 10 }}>{t('Every muscle group got some work in this period.')}</div>}
|
||||
<div className="muted small" style={{ marginTop: 10 }}>{on
|
||||
? t('Every muscle group got at least one hard set in this period.')
|
||||
: t('Every muscle group got some work in this period.')}</div>}
|
||||
</> : <div className="muted small">{t('No workouts in this period yet.')}</div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
// How hard the training was — the half of the picture a volume chart cannot show. Everything
|
||||
// is computed in RIR (lib/effort.js) and converted to whichever scale this profile reads.
|
||||
// Every number carries how much of the training it speaks for: rating is optional and off by
|
||||
// default, so a partly rated history is the normal case, and an average without its
|
||||
// denominator would quietly speak for sets that were never rated.
|
||||
function EffortCard({ S }) {
|
||||
const [win, setWin] = useState(90)
|
||||
const kind = displayScale(S)
|
||||
const hd = scaleName(kind)
|
||||
const sum = effortSummary(S, win)
|
||||
const weeks = effortWeeks(S, win)
|
||||
const hist = effortHistogram(S, win)
|
||||
const maxBin = Math.max(1, ...hist.map(b => b.n))
|
||||
// The week's set count rides along in the tooltip, because the pair is the reading:
|
||||
// volume up with effort up is fatigue piling up, volume up with effort flat is adaptation.
|
||||
const pts = weeks.map(w => ({ t: w.t, y: toScale(kind, w.rir), note: t('{0} sets', w.sets) }))
|
||||
// Bins run hardest-first in both scales: RIR 0 and RPE 10 are the same set.
|
||||
const binLabel = b => kind === 'rpe' ? (b.tail ? '≤ 6' : String(10 - b.rir)) : (b.tail ? b.rir + '+' : String(b.rir))
|
||||
|
||||
return <div className="card">
|
||||
<h2>{t('Effort')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {t('how close to failure')}</span></h2>
|
||||
<Segmented className="seg-range" value={win} onChange={setWin}
|
||||
options={[{ value: 30, label: '30d' }, { value: 90, label: '90d' }, { value: 365, label: '1Y' }, { value: 0, label: t('All') }]} />
|
||||
{sum.rated === 0 ? <div className="muted small">{t('No rated sets in this period.')}</div> : <>
|
||||
<div className="row between" style={{ alignItems: 'flex-end', gap: 12 }}>
|
||||
<div>
|
||||
<div className="stat-v">{sum.avg == null ? '—' : fmtNum(toScale(kind, sum.avg)) + ' ' + hd}</div>
|
||||
<div className="small dim">{t('average effort')}</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<div className="stat-v" style={{ color: 'var(--yellow)' }}>{sum.hardPct == null ? '—' : Math.round(sum.hardPct * 100) + '%'}</div>
|
||||
<div className="small dim">{t('at {0} {1} or harder', hd, fmtNum(toScale(kind, HARD_RIR)))}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="small dim" style={{ marginTop: 8 }}>{t('{0} of {1} finished sets rated', sum.rated, sum.done)}</div>
|
||||
{effortOf(S) === 'none' && <div className="small" style={{ color: 'var(--yellow)', marginTop: 4 }}>
|
||||
{t('Effort per set is switched off — turn it on in Settings to keep rating.')}
|
||||
</div>}
|
||||
{pts.length > 1 && <>
|
||||
<h4 className="sec" style={{ marginTop: 12 }}>{t('Week by week')}</h4>
|
||||
<div className="chart"><LineChart points={pts} h={140} unit={hd} color="var(--yellow)" invert={kind === 'rir'} /></div>
|
||||
</>}
|
||||
<h4 className="sec" style={{ marginTop: 12 }}>{t('Where the sets land')}</h4>
|
||||
{hist.map(b => <div key={b.rir} className="mrow">
|
||||
<span className="nm">{hd} {binLabel(b)}</span>
|
||||
<span className="bar"><i style={{ width: Math.round(b.n / maxBin * 100) + '%', background: b.rir <= HARD_RIR ? 'var(--yellow)' : 'var(--label-3)' }} /></span>
|
||||
<span className="v">{b.n ? b.n + ' · ' + Math.round(b.pct * 100) + '%' : '—'}</span>
|
||||
</div>)}
|
||||
<div className="small dim" style={{ marginTop: 8 }}>
|
||||
{t('Most working sets belong close to failure without living there — half at the floor and half at the top average out to a healthy-looking middle.')}
|
||||
</div>
|
||||
</>}
|
||||
</div>
|
||||
}
|
||||
|
||||
// Stats = the analytics hub: all charts, progress and history live here.
|
||||
export default function Stats() {
|
||||
const nav = useNavigate()
|
||||
@@ -65,6 +137,9 @@ export default function Stats() {
|
||||
const [exId, setExId] = useState(null)
|
||||
const [exMetric, setExMetric] = useState('top')
|
||||
const now = Date.now()
|
||||
const anyEffort = hasEffort(S)
|
||||
const kind = displayScale(S)
|
||||
const hd = scaleName(kind)
|
||||
|
||||
const bwPts = S.bodyweight.filter(b => range === 0 || (b.t || new Date(b.d).getTime()) > now - range * 86400000)
|
||||
.map(b => ({ t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d }))
|
||||
@@ -101,7 +176,23 @@ export default function Stats() {
|
||||
const e1Pts = curEx ? e1rmSeries(S, curEx) : []
|
||||
const e1Best = curEx ? best1RM(S, curEx) : null
|
||||
const showE1 = e1Pts.length > 0
|
||||
// Effort on this exercise, per session. It rides on the top-set curve as well as having a
|
||||
// curve of its own, because the two only mean something together: the same weight moved
|
||||
// with more left in the tank is progress a weight-only chart draws as a flat line.
|
||||
const exRir = exPts.map(p => avgRir(p.sets))
|
||||
const showEff = exRir.filter(v => v != null).length >= 3
|
||||
const effPts = exPts.map((p, i) => (exRir[i] == null ? null : { t: p.t, y: toScale(kind, exRir[i]), d: p.d })).filter(Boolean)
|
||||
const onE1 = showE1 && exMetric === 'e1rm'
|
||||
const onEff = showEff && exMetric === 'effort'
|
||||
const topPts = exPts.map((p, i) => ({
|
||||
t: p.t, y: p.y, d: p.d,
|
||||
// 0 RIR (nothing left) is a full dot, 4+ a faint one; unrated sessions keep the plain line.
|
||||
m: exRir[i] == null ? null : 1 - Math.min(4, Math.max(0, exRir[i])) / 4,
|
||||
note: exRir[i] == null ? undefined : hd + ' ' + fmtNum(toScale(kind, exRir[i]))
|
||||
}))
|
||||
const exOpts = [{ value: 'top', label: t('Top set') }]
|
||||
if (showE1) exOpts.push({ value: 'e1rm', label: t('Est. 1RM') })
|
||||
if (showEff) exOpts.push({ value: 'effort', label: t('Effort') })
|
||||
|
||||
return <>
|
||||
<div className="hdr"><div><h1>{t('Stats')}</h1><div className="sub">{t('Progress & history')}</div></div>
|
||||
@@ -120,6 +211,7 @@ export default function Stats() {
|
||||
</div>
|
||||
|
||||
{S.workouts.length > 0 && <MuscleBalance S={S} />}
|
||||
{anyEffort && <EffortCard S={S} />}
|
||||
|
||||
<div className="cols">
|
||||
<div className="card">
|
||||
@@ -142,18 +234,24 @@ export default function Stats() {
|
||||
<SelectRow title={t('Exercise')} sheetTitle={t('Exercise progress')} value={curEx} onChange={setExId}
|
||||
options={exHist.map(id => ({ value: id, label: EXIDX[id].n }))} />
|
||||
</div>
|
||||
{showE1 && <Segmented className="seg-range" value={exMetric} onChange={setExMetric}
|
||||
options={[{ value: 'top', label: t('Top set') }, { value: 'e1rm', label: t('Est. 1RM') }]} />}
|
||||
<div className="chart"><LineChart points={(onE1 ? e1Pts : exPts).map(p => ({ t: p.t, y: p.y, d: p.d }))} h={150} unit={exUnit} color="var(--blue)" /></div>
|
||||
{exOpts.length > 1 && <Segmented className="seg-range" value={onEff ? 'effort' : onE1 ? 'e1rm' : 'top'} onChange={setExMetric} options={exOpts} />}
|
||||
<div className="chart">
|
||||
{onEff
|
||||
? <LineChart points={effPts} h={150} unit={hd} color="var(--yellow)" invert={kind === 'rir'} />
|
||||
: <LineChart points={onE1 ? e1Pts.map(p => ({ t: p.t, y: p.y, d: p.d })) : topPts} h={150} unit={exUnit} color="var(--blue)" />}
|
||||
</div>
|
||||
<div style={{ marginTop: 8 }}>{exList.map((p, i) => <div key={i} className="row between small" style={{ padding: '6px 0', borderBottom: 'var(--hair) solid var(--sep)' }}>
|
||||
<span className="muted">{fmtDate(p.d, true)}</span><span>{p.sets.map(s => setLabel(curEx, s, p.target)).join(' ')}</span></div>)}</div>
|
||||
<div className="small dim" style={{ marginTop: 8 }}>
|
||||
{onE1 ? t('Estimated 1RM per workout') : curCardio ? t('Top speed per workout') : curTimed ? t('Longest hold per workout') : t('Best set weight per workout')} · {t('Best:')}
|
||||
{' '}<b className="accent">{fmtNum(onE1 ? e1Best.est : exBest)} {onE1 ? S.unit : exUnit}</b>
|
||||
{onEff ? t('Average effort per workout') : onE1 ? t('Estimated 1RM per workout') : curCardio ? t('Top speed per workout') : curTimed ? t('Longest hold per workout') : t('Best set weight per workout')}
|
||||
{onEff ? '' : <> · {t('Best:')}{' '}<b className="accent">{fmtNum(onE1 ? e1Best.est : exBest)} {onE1 ? S.unit : exUnit}</b></>}
|
||||
</div>
|
||||
{showE1 && <div className="small dim" style={{ marginTop: 4 }}>
|
||||
{onE1 && <div className="small dim" style={{ marginTop: 4 }}>
|
||||
{t('Best estimate from {0} on {1} — an estimate, not a tested max.', fmtNum(e1Best.w) + ' ' + S.unit + ' × ' + e1Best.r, fmtDate(e1Best.d, true))}
|
||||
</div>}
|
||||
{!onEff && !onE1 && showEff && <div className="small dim" style={{ marginTop: 4 }}>
|
||||
{t('A fuller dot means less left in the tank — the same weight at a lower {0} is progress the line alone does not show.', hd)}
|
||||
</div>}
|
||||
</> : <div className="muted small">{t('Finish your first workout to see progress curves here.')}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user