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 <>