From 6fece171977196031e84f3dacbde02679903e76a Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 31 Aug 2026 19:12:18 +0200 Subject: [PATCH] fix: align manual weight normalization --- frontend/src/lib/progression.js | 16 ++++++++++------ frontend/src/views/Workout.jsx | 11 ++++++----- frontend/src/views/Workout.test.jsx | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js index 4cc5547..593e73c 100644 --- a/frontend/src/lib/progression.js +++ b/frontend/src/lib/progression.js @@ -81,18 +81,22 @@ export function policyFor(cfg, routine, mode) { } const round1 = v => Math.round(v * 10) / 10 -// Snap to a loadable multiple of the step. -function snap(v, step) { +// Snap to a loadable multiple of the step. Manual weight controls use this same normalization +// so fractional increments produce the same number as automatic progression. +export function snapWeight(v, step) { if (!(step > 0)) return round1(v) return round1(Math.round(v / step) * step) } +export function stepWeight(value, step, direction) { + return Math.max(0, snapWeight((Number(value) || 0) + direction * step, step)) +} // Back off by DELOAD_FACTOR, landing on something you can actually load. Rounding to the // nearest step keeps the cut close to the intended 10 %, but on small weights the nearest // step can be the weight you started from — so a deload that did not actually reduce // anything takes one step down instead. Never goes below a single step. function deloadTo(cur, step) { - let next = snap(cur * DELOAD_FACTOR, step) - if (next >= cur) next = snap(cur - step, step) + let next = snapWeight(cur * DELOAD_FACTOR, step) + if (next >= cur) next = snapWeight(cur - step, step) return Math.max(step, next) } @@ -225,7 +229,7 @@ export function nextPrescription(S, cfg, routine) { const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg)) 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 (last.ok) return { policy, kind: 'up', weight: snapWeight(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) return { policy, kind: 'deload', weight: dw, reps: bottom, why: ['Stalled {0} sessions — deload to {1} {2}.', stalls, dw, unit] } @@ -241,7 +245,7 @@ export function nextPrescription(S, cfg, routine) { const dbl = policy === 'greyskull' && last.goal > 0 && last.amrap >= last.goal * 2 const step = dbl ? inc * 2 : inc return { - policy, kind: 'up', weight: snap(w + step, inc), + policy, kind: 'up', weight: snapWeight(w + step, inc), why: dbl ? ['Last set hit {0} reps — twice the target, so take a double jump of {1} {2}.', last.amrap, step, unit] : ['Every rep last time — {0} {1} more.', step, unit] diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 367f6bc..e571a42 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -13,7 +13,7 @@ import Media from '../components/Media.jsx' import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise } from '../sheets.jsx' import Icon from '../components/Icon.jsx' import { Button, Check, NumberField } from '../components/ui.jsx' -import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement } from '../lib/progression.js' +import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js' import { progressionGuidance } from '../lib/progression-copy.js' import { glyphOf } from '../lib/glyphs.js' import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps } from '../lib/workout-model.js' @@ -140,6 +140,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov // with no ceiling, as they always did. const bump = (s, i, col, dir) => { if (col.eff) return onField(i, col.f, stepEffort(col.eff, s[col.f], dir)) + if (mode === 'reps' && col.f === 'w') return onField(i, col.f, stepWeight(s[col.f], col.step, dir)) onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + dir * col.step) * 100) / 100)) } // Uses the shared stepper markup so a set row picks up the same control styling @@ -155,11 +156,11 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov ) // A smaller stepper for a drop's weight/reps or a burst's reps — editing what the plan (or a // live "+ Drop"/"+ Burst" tap) already put on the row, not typing into a fresh field. - const miniStepper = (value, step, dec, onChange) => ( + const miniStepper = (value, step, dec, onChange, snapWeightStep = false) => (
- + - +
) return <> @@ -235,7 +236,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov {dropsOf(s).map((d, di) => (
{t('Drop {0}', di + 1)} - {miniStepper(d.w, 2.5, true, v => setDropField(i, di, 'w', v))} + {miniStepper(d.w, loadStep, true, v => setDropField(i, di, 'w', v), true)} {miniStepper(d.r, 1, false, v => setDropField(i, di, 'r', v))}
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index b547e87..ee73be5 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client' import { parseHTML } from 'linkedom' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import Workout from './Workout.jsx' +import { nextPrescription } from '../lib/progression.js' const mocks = vi.hoisted(() => { const state = { @@ -426,6 +427,31 @@ describe('active workout weight controls', () => { expect(mocks.S.active.entries[0].sets[0].w).toBe(62.5) }) + it('matches automatic progression rounding for a fractional configured step', async () => { + const target = { mode: 'reps', sets: 1, reps: 5, weight: 60, bodyweight: false, inc: 1.25 } + const automatic = nextPrescription({ + unit: 'kg', + workouts: [{ d: '2026-08-30', entries: [{ id: 'plain-bench', target, sets: [{ w: 60, r: 5, done: true }] }] }], + }, { id: 'plain-bench', ...target }) + + await mount([exercise('plain-bench', [false], { target, sets: [{ w: 60, r: 5, done: false }] })]) + await press('Increase', '.setrow .stp.w') + + expect(automatic.weight).toBe(61.3) + expect(mocks.S.active.entries[0].sets[0].w).toBe(automatic.weight) + }) + + it('uses the configured reps weight step for drop-set weight controls', async () => { + await mount([exercise('plain-bench', [false], { + target: { mode: 'reps', reps: 5, weight: 60, bodyweight: false, inc: 1 }, + sets: [{ w: 60, r: 5, done: false, type: 'dropset', drops: [{ w: 50, r: 5 }] }], + })]) + + await press('Increase', '.subrow .stp') + + expect(mocks.S.active.entries[0].sets[0].drops[0].w).toBe(51) + }) + it('keeps timed seconds and optional timed weight on their existing steps', async () => { await mount([exercise('timed-plank', [false], { target: { mode: 'time', sec: 30, weight: 60, bodyweight: false, inc: 1 },