Merge #164: a per-exercise rest for warm-up ramp sets, warmupRestSec (kurktchiev)
This commit is contained in:
commit
6c8bc51d18
6 files changed
+102
-8
No files matched your search
@@ -53,6 +53,7 @@ function cleanEx(e) {
|
||||
// only when set, so a plan that never asked for one leaves the recipient's own default
|
||||
// timer in charge. parsePlan and mergePlan carry it through by spread.
|
||||
if (e.restSec > 0) o.restSec = e.restSec
|
||||
if (e.warmupRestSec > 0) o.warmupRestSec = e.warmupRestSec // the ramp's own rest travels with the work rest
|
||||
if (e.sg) o.sg = e.sg
|
||||
if (e.note) o.note = e.note
|
||||
const warm = cleanWarmupSets(e.warmupSets)
|
||||
@@ -141,8 +142,9 @@ export function parsePlan(raw) {
|
||||
const warm = cleanWarmupSets(e.warmupSets)
|
||||
const intens = cleanIntensifier(e.intensifier)
|
||||
const rest = cleanRestSec(e.restSec)
|
||||
const { warmupSets, intensifier, restSec, ...passthrough } = e
|
||||
return { ...passthrough, ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}) }
|
||||
const warmRest = cleanRestSec(e.warmupRestSec)
|
||||
const { warmupSets, intensifier, restSec, warmupRestSec, ...passthrough } = e
|
||||
return { ...passthrough, ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}), ...(warmRest ? { warmupRestSec: warmRest } : {}) }
|
||||
})
|
||||
}))
|
||||
return {
|
||||
|
||||
@@ -46,6 +46,14 @@ describe('what survives a shared plan', () => {
|
||||
expect(roundTrip({ restSec: 180 }).restSec).toBe(180)
|
||||
})
|
||||
|
||||
// The ramp's own rest is the same kind of prescription: a shared plan whose warm-up sets
|
||||
// arrive resting the full working rest is not the plan that was written.
|
||||
it('carries a per-exercise warm-up rest, and leaves it out when unset', () => {
|
||||
expect(roundTrip({ restSec: 150, warmupRestSec: 45 }).warmupRestSec).toBe(45)
|
||||
expect('warmupRestSec' in roundTrip({})).toBe(false)
|
||||
expect('warmupRestSec' in roundTrip({ warmupRestSec: 0 })).toBe(false)
|
||||
})
|
||||
|
||||
// The absence has to survive too: writing a 0 would pin the recipient's timer to "off"
|
||||
// instead of letting the exercise keep inheriting whatever their own default is.
|
||||
it('leaves an exercise that set no rest free of the field', () => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Pure decisions for the active-workout superset flow. Keeping these independent of React and
|
||||
// the stores makes the uneven-round and re-check rules explicit and directly testable.
|
||||
import { isWarmupRow } from './workout-model.js'
|
||||
|
||||
const hasWork = (entries, idx) => !!entries[idx]?.sets?.some(set => !set.done)
|
||||
|
||||
// Return the first unfinished navigation unit after the current one, wrapping once so a user
|
||||
@@ -89,6 +91,25 @@ export function restSecFor(entries, unit, defaultRestSec) {
|
||||
}, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* The rest a completed set earns when it was a warm-up ramp set.
|
||||
*
|
||||
* Ramp sets are light and short, so an exercise may carry its own `warmupRestSec` in its target
|
||||
* next to `restSec`. It applies between ramp sets only: the break after the LAST ramp set, into
|
||||
* the first work set, is `workRestSec` (the value restSecFor resolved), because that is the rest
|
||||
* the first heavy set actually needs. An exercise without the field, or a work set, rests
|
||||
* `workRestSec` — exactly what every routine did before the field existed.
|
||||
*/
|
||||
export function warmupRestSecFor(entry, setIdx, workRestSec) {
|
||||
const sets = Array.isArray(entry?.sets) ? entry.sets : []
|
||||
const set = sets[setIdx]
|
||||
if (!set || !isWarmupRow(set)) return workRestSec
|
||||
const next = sets.slice(setIdx + 1).find(s => !s.done)
|
||||
if (!next || !isWarmupRow(next)) return workRestSec
|
||||
const own = Number(entry?.target?.warmupRestSec)
|
||||
return own > 0 ? own : workRestSec
|
||||
}
|
||||
|
||||
// Decide where a newly completed superset set goes next. Spent members are skipped, including
|
||||
// across the wrap. A round ends when no later member in display order has work left; this makes
|
||||
// the last *active* member the boundary rather than blindly using the group's last array index.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from './supersetFlow.js'
|
||||
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor } from './supersetFlow.js'
|
||||
|
||||
const entry = done => ({ sets: done.map(value => ({ done: value })) })
|
||||
|
||||
@@ -137,3 +137,44 @@ describe('restSecFor', () => {
|
||||
expect(restSecFor(undefined, [0], undefined)).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('warmupRestSecFor', () => {
|
||||
const ramp = (warmupRestSec, done = [false, false, false, false]) => ({
|
||||
target: { restSec: 150, ...(warmupRestSec ? { warmupRestSec } : {}) },
|
||||
sets: [
|
||||
{ phase: 'warmup', w: 60, r: 8, done: done[0] },
|
||||
{ phase: 'warmup', w: 95, r: 5, done: done[1] },
|
||||
{ phase: 'work', w: 125, r: 6, done: done[2] },
|
||||
{ phase: 'work', w: 125, r: 6, done: done[3] },
|
||||
],
|
||||
})
|
||||
|
||||
it('rests the warm-up rest between ramp sets', () => {
|
||||
expect(warmupRestSecFor(ramp(45), 0, 150)).toBe(45)
|
||||
})
|
||||
|
||||
it('rests the working rest after the last ramp set, into the first work set', () => {
|
||||
expect(warmupRestSecFor(ramp(45), 1, 150)).toBe(150)
|
||||
})
|
||||
|
||||
it('rests the working rest after a work set', () => {
|
||||
expect(warmupRestSecFor(ramp(45), 2, 150)).toBe(150)
|
||||
expect(warmupRestSecFor(ramp(45), 3, 150)).toBe(150)
|
||||
})
|
||||
|
||||
it('without the field a ramp set rests like a work set (the pre-field behaviour)', () => {
|
||||
expect(warmupRestSecFor(ramp(null), 0, 150)).toBe(150)
|
||||
expect(warmupRestSecFor({ target: { warmupRestSec: 0 }, sets: ramp(null).sets }, 0, 90)).toBe(90)
|
||||
})
|
||||
|
||||
it('looks at the next UNFINISHED set: a ramp set re-checked after the work began rests the working rest', () => {
|
||||
expect(warmupRestSecFor(ramp(45, [true, true, false, false]), 0, 150)).toBe(150)
|
||||
})
|
||||
|
||||
it('is safe on a legacy warmup boolean and on missing entries', () => {
|
||||
const legacy = { target: { warmupRestSec: 45 }, sets: [{ warmup: true, done: false }, { warmup: true, done: false }, { done: false }] }
|
||||
expect(warmupRestSecFor(legacy, 0, 120)).toBe(45)
|
||||
expect(warmupRestSecFor(undefined, 0, 120)).toBe(120)
|
||||
expect(warmupRestSecFor({ target: {}, sets: [] }, 0, 120)).toBe(120)
|
||||
})
|
||||
})
|
||||
@@ -10,7 +10,7 @@ import { fmtNum, capWords, fmtDate, todayISO, exCount, DAYN } from '../lib/forma
|
||||
import { beep, vibrate } from '../lib/sound.js'
|
||||
import { t, exerciseNameFor } from '../lib/i18n.js'
|
||||
import { api } from '../lib/api.js'
|
||||
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'
|
||||
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor } from '../lib/supersetFlow.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet } from '../sheets.jsx'
|
||||
import { effortColor } from '../lib/effort.js'
|
||||
@@ -863,11 +863,14 @@ function ActiveWorkout() {
|
||||
// timer when it did not, and the longest of the group's across a superset (issue #10).
|
||||
// Resolved once here so every branch below times the same break.
|
||||
const restSec = restSecFor(fresh.entries, freshUnit || [idx], S.restSec)
|
||||
// A warm-up ramp set may rest shorter than a work set (the exercise's warmupRestSec); the
|
||||
// last ramp set, into the first work set, still gets the working rest.
|
||||
const restAfter = warmupRestSecFor(fresh.entries[idx], i, restSec)
|
||||
|
||||
// A re-check of finished work must not navigate or reopen a sheet, but it may still owe
|
||||
// you a rest — see restOnRecheck, and the other half of issue #3.
|
||||
if (!progress.isNew) {
|
||||
if (!restBeforeWarmup && restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restSec, idx)
|
||||
if (!restBeforeWarmup && restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restAfter, idx)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -876,17 +879,17 @@ function ActiveWorkout() {
|
||||
// stopRest() first so a rest that belongs after this set replaces the one that was running.
|
||||
if (freshUnitDone) stopRest()
|
||||
if (!freshUnit || freshUnit.length <= 1) {
|
||||
if (!restBeforeWarmup && restAfterSet({ unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restSec, idx)
|
||||
if (!restBeforeWarmup && restAfterSet({ unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restAfter, idx)
|
||||
return
|
||||
}
|
||||
|
||||
const step = supersetFlowStep(fresh.entries, freshUnit, idx)
|
||||
if (!step) return
|
||||
if (step.unitDone) {
|
||||
if (nextUnit?.length && !restBeforeWarmup) startRest(restSec, idx)
|
||||
if (nextUnit?.length && !restBeforeWarmup) startRest(restAfter, idx)
|
||||
} else {
|
||||
if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx })
|
||||
if (step.roundDone) startRest(restSec, idx)
|
||||
if (step.roundDone) startRest(restAfter, idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +202,25 @@ afterEach(async () => {
|
||||
})
|
||||
|
||||
describe('Workout set completion flow', () => {
|
||||
it('rests the exercise\'s warm-up rest between ramp sets, and its working rest after the last ramp set', async () => {
|
||||
await mount([exercise('ramped-squat', [false, false, false, false], {
|
||||
target: { mode: 'reps', reps: 6, weight: 125, bodyweight: false, restSec: 150, warmupRestSec: 45 },
|
||||
sets: [
|
||||
{ w: 60, r: 8, done: false, phase: 'warmup' },
|
||||
{ w: 95, r: 5, done: false, phase: 'warmup' },
|
||||
{ w: 125, r: 6, done: false, phase: 'work' },
|
||||
{ w: 125, r: 6, done: false, phase: 'work' },
|
||||
],
|
||||
})])
|
||||
await toggleSet(0)
|
||||
expect(mocks.startRest).toHaveBeenLastCalledWith(45, expect.any(Number))
|
||||
await toggleSet(1)
|
||||
expect(mocks.startRest).toHaveBeenLastCalledWith(150, expect.any(Number))
|
||||
await toggleSet(2)
|
||||
expect(mocks.startRest).toHaveBeenLastCalledWith(150, expect.any(Number))
|
||||
expect(mocks.startRest).toHaveBeenCalledTimes(3)
|
||||
})
|
||||
|
||||
it('starts rest after a non-final ordinary set, but stops rest without restarting it on the final set', async () => {
|
||||
await mount([exercise('plain-bench', [false, false, false])])
|
||||
await toggleSet(0)
|
||||
|
||||
Reference in new issue
Block a user