From 039a2807774aa29dac1f7d6a6123f264480e0e81 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Sat, 5 Sep 2026 14:16:02 +0200 Subject: [PATCH] =?UTF-8?q?Warm-up-Ramp=20und=20Prescription=20snappen=20a?= =?UTF-8?q?uf=20das=20Inkrement=20der=20Uebung=20(weightIncrement),=20nich?= =?UTF-8?q?t=20auf=20den=20Einheiten-Default=20=E2=80=94=20in=20session-st?= =?UTF-8?q?art,=20Add-Exercise,=20Progression-Sheet=20und=20Swap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/session-start.js | 9 ++++++--- frontend/src/lib/session-start.test.js | 23 +++++++++++++++++++++++ frontend/src/sheets.jsx | 4 ++-- frontend/src/views/Workout.jsx | 6 +++--- 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 frontend/src/lib/session-start.test.js diff --git a/frontend/src/lib/session-start.js b/frontend/src/lib/session-start.js index cf3dd1b..cc453b5 100644 --- a/frontend/src/lib/session-start.js +++ b/frontend/src/lib/session-start.js @@ -3,8 +3,8 @@ // to identical entries, or the two paths drift apart the first time a prescription rule changes. // Imports both history.js and progression.js (which itself imports history.js); nothing in // either imports this file, so there is no cycle. -import { buildSets, applyIntensifierPlan } from './history.js' -import { nextPrescription, applyPrescription, defaultIncrement } from './progression.js' +import { buildSets, applyIntensifierPlan, modeOf } from './history.js' +import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement } from './progression.js' export function buildSessionEntries(st, r) { // The prescription is applied as the session is built, so you walk up to the bar with the @@ -13,7 +13,10 @@ export function buildSessionEntries(st, r) { const excluded = r?.excludeFromProgression === true const entries = (r ? r.ex : []).map(cfg => { const plan = excluded ? { policy: 'off', kind: 'off' } : nextPrescription(st, cfg, r) - const step = defaultIncrement(cfg.id, st.unit) + // The warm-up ramp and the prescription snap to the exercise's own increment (1.25 kg + // plates exist), not the unit default; a timed exercise's `inc` is seconds, so it keeps the + // default for its optional load. + const step = modeOf(cfg) === 'reps' ? weightIncrement(cfg, st.unit) : defaultIncrement(cfg.id, st.unit) const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step, useTarget: plan.kind === 'off' }), plan, step), cfg) return { id: cfg.id, sg: cfg.sg, target: { ...cfg }, plan, sets } }) diff --git a/frontend/src/lib/session-start.test.js b/frontend/src/lib/session-start.test.js new file mode 100644 index 0000000..45c2dd9 --- /dev/null +++ b/frontend/src/lib/session-start.test.js @@ -0,0 +1,23 @@ +import { describe, it, expect } from 'vitest' +import { buildSessionEntries } from './session-start.js' +import { isWarmupRow } from './workout-model.js' + +// The session builder used by the live start and by "log a past workout". +describe('buildSessionEntries', () => { + const st = { unit: 'kg', workouts: [], exWeights: {}, routines: [] } + + it('ramps the warm-ups on the exercise’s own increment, not the unit default', () => { + const r = { id: 'r', prog: 'off', ex: [{ id: '0025', sets: 3, reps: 5, weight: 60, inc: 1.25, warmupSets: 2 }] } + const { entries } = buildSessionEntries(st, r) + const warm = entries[0].sets.filter(isWarmupRow).map(s => s.w) + expect(warm).toHaveLength(2) + for (const w of warm) expect(Math.round(w / 1.25 * 1000) / 1000 % 1).toBe(0) // a multiple of 1.25 + expect(entries[0].sets.filter(s => !isWarmupRow(s)).every(s => s.w === 60)).toBe(true) + }) + + it('keeps the unit default for timed exercises, whose inc is seconds', () => { + const r = { id: 'r', prog: 'off', ex: [{ id: '0025', mode: 'time', sets: 2, sec: 30, inc: 10, weight: 0 }] } + const { entries } = buildSessionEntries(st, r) + expect(entries[0].sets.every(s => s.sec === 30)).toBe(true) + }) +}) diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 9c795f1..e3f3619 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -23,7 +23,7 @@ import { parseImport, mergeImport } from './lib/import-csv.js' import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.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 { nextPrescription, applyPrescription, policyFor, defaultIncrement, POLICIES_FOR, POLICY_NAME, POLICY_DESC, MAX_BW_SETS, weightIncrement } 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' @@ -881,7 +881,7 @@ export function swapActiveWorkoutExercise(index) { // Same rows the add flow builds: last time's loads and, in a planned session, the // prescription — swapping barbell for dumbbell bench must not start you at an empty bar. const freestyle = !st.active?.routineId - const step = defaultIncrement(ex.id, st.unit) + const step = modeOf(full) === 'reps' ? weightIncrement(full, st.unit) : defaultIncrement(ex.id, st.unit) const plan = freestyle ? null : nextPrescription(st, full, st.routines.find(r => r.id === st.active.routineId)) const built = buildSets(st, full, { step, ...(freestyle ? { preferLast: true } : {}), ...(plan?.kind === 'off' ? { useTarget: true } : {}) }) const replacement = { diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 69b91e1..7bb1ba5 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -577,7 +577,7 @@ function ActiveWorkout() { if (!activeEntry || activeEntry.id !== entryId) return const full = { ...cfg, id: activeEntry.id } const activeRoutine = s.routines.find(r => r.id === s.active.routineId) - const step = defaultIncrement(activeEntry.id, s.unit) + const step = modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(activeEntry.id, s.unit) // A config without a set count keeps the rows the session already has. if (!(full.sets > 0)) full.sets = activeEntry.sets.filter(x => !isWarmupRow(x)).length || 1 const plan = nextPrescription(s, full, activeRoutine) @@ -840,11 +840,11 @@ function ActiveWorkout() { const full = { ...cfg, id: ex.id } const plan = freestyle ? null : nextPrescription(s, full, s.routines.find(r => r.id === s.active.routineId)) const sets = buildSets(s, full, { - step: defaultIncrement(ex.id, s.unit), + step: modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit), ...(freestyle ? { preferLast: true } : {}), ...(plan?.kind === 'off' ? { useTarget: true } : {}) }) - const progressed = freestyle ? sets : applyPrescription(sets, plan, defaultIncrement(ex.id, s.unit)) + const progressed = freestyle ? sets : applyPrescription(sets, plan, modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit)) const insertAt = insertionIndexAfterCurrentUnit(supersetUnits(s.active.entries), s.active.cur, s.active.entries.length) s.active.entries.splice(insertAt, 0, { id: ex.id, target: { ...cfg }, plan, sets: applyIntensifierPlan(progressed, full) }) s.active.cur = insertAt