From c71cb09515a1ee32401c7de7b8782f74ac1e1990 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 30 Aug 2026 01:23:20 +0200 Subject: [PATCH] feat: expose the double progression rep range --- frontend/src/lib/progression.js | 6 ++-- frontend/src/lib/rep-range.js | 14 +++++++++ frontend/src/lib/rep-range.test.js | 29 ++++++++++++++++++ frontend/src/locales/de.js | 1 + frontend/src/locales/es.js | 1 + frontend/src/locales/fr.js | 1 + frontend/src/locales/hi.js | 1 + frontend/src/locales/it.js | 1 + frontend/src/locales/ko.js | 1 + frontend/src/locales/pl.js | 1 + frontend/src/locales/pt-BR.js | 1 + frontend/src/locales/pt.js | 1 + frontend/src/locales/ru.js | 1 + frontend/src/locales/tr.js | 1 + frontend/src/locales/zh.js | 1 + frontend/src/sheets.jsx | 47 +++++++++++++++++++++++++----- 16 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 frontend/src/lib/rep-range.js create mode 100644 frontend/src/lib/rep-range.test.js diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js index eb96818..a1c8ac4 100644 --- a/frontend/src/lib/progression.js +++ b/frontend/src/lib/progression.js @@ -19,6 +19,7 @@ import { modeOf, repStep, rerampWarmups } from './history.js' import { EXIDX } from './exercises.js' import { isWarmupRow } from './workout-model.js' +import { normalizeRepRange } from './rep-range.js' export const POLICIES = ['off', 'linear', 'greyskull', 'double', 'time'] @@ -210,8 +211,9 @@ export function nextPrescription(S, cfg, routine) { return { policy, kind: 'up', weight: 0, reps: next, why: ['Bodyweight — every rep last time, so go for {0} this time.', next] } } if (policy === 'double') { - const top = cfg.reps || last.goal || 10 - const bottom = Math.min(cfg.repsMin || Math.max(1, top - 2), top) + const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin) + const top = range.reps + const bottom = range.repsMin if (last.ok) return { policy, kind: 'up', weight: snap(w + inc, inc), reps: bottom, why: ['Top of the rep range in every set — {0} {1} more, back to {2} reps.', inc, unit, bottom] } if (stalls >= deloadAt) { const dw = deloadTo(w, inc) diff --git a/frontend/src/lib/rep-range.js b/frontend/src/lib/rep-range.js new file mode 100644 index 0000000..b01aab1 --- /dev/null +++ b/frontend/src/lib/rep-range.js @@ -0,0 +1,14 @@ +// Normalize the two bounds used by double progression. +// `reps` is the upper bound and `repsMin` is the lower bound in persisted configs. +export function normalizeRepRange(reps, repsMin) { + const upper = positiveInt(reps, 10) + const lower = positiveInt(repsMin, Math.max(1, upper - 2)) + return lower >= upper + ? { reps: lower + 1, repsMin: lower } + : { reps: upper, repsMin: lower } +} + +function positiveInt(value, fallback) { + const n = Number(value) + return Number.isFinite(n) && n > 0 ? Math.max(1, Math.round(n)) : fallback +} diff --git a/frontend/src/lib/rep-range.test.js b/frontend/src/lib/rep-range.test.js new file mode 100644 index 0000000..5446b21 --- /dev/null +++ b/frontend/src/lib/rep-range.test.js @@ -0,0 +1,29 @@ +import { describe, expect, it } from 'vitest' +import { normalizeRepRange } from './rep-range.js' + +describe('normalizeRepRange', () => { + it('keeps valid positive integer bounds unchanged', () => { + expect(normalizeRepRange(12, 8)).toEqual({ reps: 12, repsMin: 8 }) + }) + + it('rounds bounds to positive integers', () => { + expect(normalizeRepRange(12.4, 7.6)).toEqual({ reps: 12, repsMin: 8 }) + expect(normalizeRepRange(0, -2)).toEqual({ reps: 10, repsMin: 8 }) + }) + + it('raises the upper bound when the lower bound reaches it', () => { + expect(normalizeRepRange(8, 8)).toEqual({ reps: 9, repsMin: 8 }) + }) + + it('raises the upper bound when the lower bound exceeds it', () => { + expect(normalizeRepRange(8, 12)).toEqual({ reps: 13, repsMin: 12 }) + }) + + it('keeps the lower bound at least one below a lowered upper bound', () => { + expect(normalizeRepRange(6, 8)).toEqual({ reps: 9, repsMin: 8 }) + }) + + it('supplies a usable default lower bound for a small upper bound', () => { + expect(normalizeRepRange(1, undefined)).toEqual({ reps: 2, repsMin: 1 }) + }) +}) diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index 8c91155..d5f48c5 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -536,6 +536,7 @@ export default { 'Step ({0})': 'Schritt ({0})', 'Step (seconds)': 'Schritt (Sekunden)', 'Reps from': 'Wdh. ab', + 'Reps up to': 'Wdh. bis', 'No automatic progression': 'Keine automatische Progression', 'Linear progression': 'Lineare Progression', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index b1ea117..3c06f51 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Incremento ({0})', 'Step (seconds)': 'Incremento (segundos)', 'Reps from': 'Reps desde', + 'Reps up to': 'Reps hasta', 'No automatic progression': 'Sin progresión automática', 'Linear progression': 'Progresión lineal', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 387bf25..a068fb2 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Palier ({0})', 'Step (seconds)': 'Palier (secondes)', 'Reps from': 'Reps à partir de', + 'Reps up to': 'Reps jusqu’à', 'No automatic progression': 'Pas de progression automatique', 'Linear progression': 'Progression linéaire', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index 09038df..6623a6a 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'स्टेप ({0})', 'Step (seconds)': 'स्टेप (सेकंड)', 'Reps from': 'रेप्स से', + 'Reps up to': 'रेप्स तक', 'No automatic progression': 'कोई स्वचालित प्रोग्रेशन नहीं', 'Linear progression': 'रैखिक प्रोग्रेशन', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index 1c53c34..f860f22 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Incremento ({0})', 'Step (seconds)': 'Incremento (secondi)', 'Reps from': 'Rip. da', + 'Reps up to': 'Rip. fino a', 'No automatic progression': 'Nessuna progressione automatica', 'Linear progression': 'Progressione lineare', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index 170f6d3..e32e462 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': '증가폭 ({0})', 'Step (seconds)': '증가폭 (초)', 'Reps from': '최소 횟수', + 'Reps up to': '최대 횟수', 'No automatic progression': '자동 증가 없음', 'Linear progression': '선형 증가', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index b914fbc..3ad8d7b 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Skok ({0})', 'Step (seconds)': 'Skok (sekundy)', 'Reps from': 'Powt. od', + 'Reps up to': 'Powt. do', 'No automatic progression': 'Bez automatycznej progresji', 'Linear progression': 'Progresja liniowa', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js index 11022ba..5ed415f 100644 --- a/frontend/src/locales/pt-BR.js +++ b/frontend/src/locales/pt-BR.js @@ -5,6 +5,7 @@ import pt from './pt.js' export const PT_BR_OVERRIDES = { 'Press back again to exit': 'Pressione voltar novamente para sair', + 'Reps up to': 'Reps até', 'Delete': 'Excluir', 'Save': 'Salvar', 'Log': 'Registrar', diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index d14ccb1..c8562b7 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Incremento ({0})', 'Step (seconds)': 'Incremento (segundos)', 'Reps from': 'Reps a partir de', + 'Reps up to': 'Reps até', 'No automatic progression': 'Sem progressão automática', 'Linear progression': 'Progressão linear', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index 1e260d1..0cf2dfa 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Шаг ({0})', 'Step (seconds)': 'Шаг (секунды)', 'Reps from': 'Повт. от', + 'Reps up to': 'Повт. до', 'No automatic progression': 'Без автопрогрессии', 'Linear progression': 'Линейная прогрессия', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index 79b3125..0f487eb 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': 'Artış ({0})', 'Step (seconds)': 'Artış (saniye)', 'Reps from': 'Tekrar en az', + 'Reps up to': 'Tekrar en çok', 'No automatic progression': 'Otomatik ilerleme yok', 'Linear progression': 'Doğrusal ilerleme', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index 533434d..2e8978a 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -518,6 +518,7 @@ export default { 'Step ({0})': '加量({0})', 'Step (seconds)': '加量(秒)', 'Reps from': '次数下限', + 'Reps up to': '次数上限', 'No automatic progression': '不自动进阶', 'Linear progression': '线性进阶', 'Greyskull LP': 'Greyskull LP', diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 6ca69e0..5f31e95 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -20,6 +20,7 @@ import { parseImport, mergeImport } from './lib/import-csv.js' import { buildPlanBundle, parsePlan, mergePlan, printPlan } from './lib/plan-share.js' import { estimate1RM, best1RM, is1RMRecord, REP_CAP } from './lib/onerm.js' import { nextPrescription, applyPrescription, policyFor, defaultIncrement, POLICIES_FOR, POLICY_NAME, POLICY_DESC, MAX_BW_SETS } from './lib/progression.js' +import { normalizeRepRange } from './lib/rep-range.js' import { MOBILE, shareExport } from './lib/mobile.js' import { buildCompletedWorkout } from './lib/finish-workout.js' import { isWarmupRow } from './lib/workout-model.js' @@ -564,10 +565,17 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) { const inherited = policyFor({ id: ex.id }, routine, mode) const active = policyFor({ ...c, id: ex.id }, routine, mode) const inc = c.inc > 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit)) + const range = active === 'double' ? normalizeRepRange(c.reps, c.repsMin) : null + const setRule = v => setC(x => { + const next = { ...x, prog: v || undefined } + return policyFor({ ...next, id: ex.id }, routine, mode) === 'double' + ? { ...next, ...normalizeRepRange(next.reps, next.repsMin) } + : next + }) return <>

{t('Progression')}

- setC(x => ({ ...x, prog: v || undefined }))} + ({ value: p, label: t(POLICY_NAME[p]) }))]} />
@@ -575,8 +583,12 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) { {active !== 'off' &&
setC(x => ({ ...x, inc: v }))} /> - {active === 'double' && setC(x => ({ ...x, repsMin: v }))} />} + {active === 'double' && <> + setC(x => ({ ...x, ...normalizeRepRange(x.reps, v) }))} /> + setC(x => ({ ...x, ...normalizeRepRange(v, x.repsMin) }))} /> + }
} } @@ -584,15 +596,28 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) { function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { const st = useStore(s => s.S) const cardio = isCardio(ex.id) - const [c, setC] = useState(existing || initial || defaultConfig(ex.id)) + const seed = existing || initial || defaultConfig(ex.id) + const [c, setC] = useState(() => { + const cfg = { ...seed } + return policyFor({ ...cfg, id: ex.id }, routine, modeOf({ ...cfg, id: ex.id })) === 'double' + ? { ...cfg, ...normalizeRepRange(cfg.reps, cfg.repsMin) } + : cfg + }) // Cardio keeps its own duration+speed form; the reps/time choice (issue #16) is offered for // everything else, which is where the gap was — planks, hangs, wall sits, loaded carries. const mode = cardio ? 'cardio' : modeOf({ ...c, id: ex.id }) // Both default from the dataset and are then whatever the config says — see isBw. const bw = !cardio && isBw({ ...c, id: ex.id }) const perSide = isPerSide(c) + const activePolicy = policyFor({ ...c, id: ex.id }, routine, mode) + const double = mode === 'reps' && activePolicy === 'double' // Keep whatever the other mode already had (sets, weight) and fill only what is missing. - const setMode = m => setC(x => ({ ...defaultConfig(ex.id, m), ...x, mode: m })) + const setMode = m => setC(x => { + const next = { ...defaultConfig(ex.id, m), ...x, mode: m } + return m === 'reps' && policyFor({ ...next, id: ex.id }, routine, 'reps') === 'double' + ? { ...next, ...normalizeRepRange(next.reps, next.repsMin) } + : next + }) const save = () => { close() const sets = Math.max(1, Math.round(c.sets) || (cardio ? 1 : 3)) @@ -623,9 +648,15 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { // A unilateral target is stored even: the split has to divide, and a typed 15 would // otherwise plan seven reps on one side and eight on the other, every session. const typed = Math.max(1, Math.round(c.reps) || 10) - const reps = perSide ? Math.ceil(typed / 2) * 2 : typed + let reps = perSide ? Math.ceil(typed / 2) * 2 : typed + let range = null + if (double) { + range = normalizeRepRange(reps, c.repsMin) + if (perSide) range = normalizeRepRange(Math.ceil(range.reps / 2) * 2, range.repsMin) + reps = range.reps + } const out = { sets, mode: 'reps', reps, weight: Math.max(0, c.weight || 0), ...flags, ...(perSide ? { side: true } : {}), ...prog, ...withNote, ...withWarmups } - if (policyFor({ ...c, id: ex.id }, routine, 'reps') === 'double') out.repsMin = Math.min(reps, Math.max(1, Math.round(c.repsMin) || Math.max(1, reps - 2))) + if (double) out.repsMin = range.repsMin // A ceiling below the working reps would tell you to add a set on day one. if (bw && !(out.weight > 0) && c.repsMax > 0) out.repsMax = Math.max(reps, Math.round(c.repsMax)) // Every set in this exercise becomes a drop-set/rest-pause (buildSets stamps the rows) — @@ -665,7 +696,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { rest-pause work set — so "Sets" has nothing left to mean and only invites a mismatch. */} {c.intensifier?.type !== 'restpause' && setC(x => ({ ...x, sets: v }))} />} - setC(x => ({ ...x, reps: v }))} /> + {!double && setC(x => ({ ...x, reps: v }))} />} {/* On bodyweight work the weight stepper is the click #32 is about, so it is not here until there is a belt to describe — see the added-weight row below. */} {!bw && setC(x => ({ ...x, weight: v }))} />}