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)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user