Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Warm-up: die vier verbliebenen Roh-Lesungen von .warmup ueber isWarmupRow, mit Regressionstests

Duarte Santos55b9dcb864ef
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index a32c3c362..a39b19937 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -334,7 +334,7 @@ export function cascadeWeight(rows, from, value) {
const warm = isWarmupRow(rows[from])
const next = rows.slice()
for (let j = from + 1; j < next.length; j++) {
- if (!!next[j].warmup === warm && !next[j].done) {
+ if (isWarmupRow(next[j]) === warm && !next[j].done) {
if (value == null) delete next[j].w
else next[j].w = value
}
@@ -368,6 +368,6 @@ export function removeRowAt(rows, i) {
/** Completed non-warm-up sets across a workout's entries. */
export function workSetsDone(w) {
return (w?.entries || []).reduce(
- (n, e) => n + (e.sets || []).filter(s => s.done && !s.warmup).length, 0,
+ (n, e) => n + (e.sets || []).filter(s => s.done && !isWarmupRow(s)).length, 0,
)
}
diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js
index b264b891b..650eadac5 100644
--- a/frontend/src/lib/history.test.js
+++ b/frontend/src/lib/history.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, supersetUnits } from './history.js'
+import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, supersetUnits, workSetsDone } from './history.js'
import { EXDB } from './exercises.js'
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
@@ -569,3 +569,25 @@ describe('session row helpers', () => {
expect(next[0].w).toBe(70)
})
})
+
+// The importer writes `phase: 'warmup'` and no `warmup` boolean (import-csv.js), so anything
+// reading the raw flag counts an imported warm-up as work. Read through the model instead.
+describe('warm-up rows identified by phase alone', () => {
+ const imported = { w: 40, r: 10, done: true, phase: 'warmup' }
+ const work = { w: 100, r: 5, done: true }
+
+ it('workSetsDone does not count a phase-only warm-up', () => {
+ expect(workSetsDone({ entries: [{ sets: [imported, work] }] })).toBe(1)
+ })
+
+ it('cascadeWeight keeps phase-only warm-ups in their own lane', () => {
+ const rows = [
+ { w: 40, r: 10, phase: 'warmup' },
+ { w: 45, r: 10, phase: 'warmup' },
+ { w: 100, r: 5 },
+ ]
+ const next = cascadeWeight(rows, 0, 50)
+ expect(next[1].w).toBe(50)
+ expect(next[2].w).toBe(100)
+ })
+})
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index d8f9df6b3..8248df7c7 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -272,7 +272,7 @@ export function applyPrescription(sets, p) {
// would both invent work and never terminate the loop. Leave the entry untouched.
if (!workRows.length) return out
const seed = workRows[workRows.length - 1]
- while (out.filter(s => !s.warmup).length < p.sets) out.push({ ...seed, done: false })
+ while (out.filter(s => !isWarmupRow(s)).length < p.sets) out.push({ ...seed, done: false })
}
return out
}
diff --git a/frontend/src/lib/recovery.js b/frontend/src/lib/recovery.js
index 5d63f005e..373786e4e 100644
--- a/frontend/src/lib/recovery.js
+++ b/frontend/src/lib/recovery.js
@@ -1,5 +1,6 @@
import { EXIDX } from './exercises.js'
import { MUSCLES, musclesOf } from './muscles.js'
+import { isWarmupRow } from './workout-model.js'
// A "normal" hard session for one muscle, in primary-set equivalents. The saturation curve
// 1 - exp(-stimulus / REF) maps any session size onto [0,1) so volume raises the starting
@@ -303,7 +304,7 @@ export function strengthOf(workouts, now, opts = {}) {
const timestamp = workoutTimestamp(workout)
if (!Number.isFinite(timestamp)) continue
for (const entry of workout.entries || []) {
- if (!(entry.sets || []).some(set => set?.done === true && !set?.warmup)) continue
+ if (!(entry.sets || []).some(set => set?.done === true && !isWarmupRow(set))) continue
for (const slug of Object.keys(musclesOf(EXIDX[entry.id]))) {
if (Object.prototype.hasOwnProperty.call(MUSCLES_BY_SLUG, slug) && timestamp > latest[slug]) {
latest[slug] = timestamp