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.

fix(muscles): exclude zero weights from consumers

Emil Zapatac3872764e8d1
diff --git a/frontend/src/lib/recovery.test.js b/frontend/src/lib/recovery.test.js
index 1c7ca21b0..55fec439c 100644
--- a/frontend/src/lib/recovery.test.js
+++ b/frontend/src/lib/recovery.test.js
@@ -164,6 +164,20 @@ describe('fatigueOf and strengthOf', () => {
expect(strength[untouchedSlug]).toBe(STRENGTH_FLOOR)
})
+ it('gives explicit zero snapshot weights no fatigue or retained-strength stimulus', () => {
+ const workouts = [workoutAt('deleted-zero-mapped', NOW, [{ done: true, w: 80, r: 8 }])]
+ workouts[0].entries[0].muscleSnapshot = {
+ n: 'Zero mapped', muscleWeights: { chest: 1, biceps: 0 },
+ }
+
+ const fatigue = fatigueOf(workouts, NOW)
+ const strength = strengthOf(workouts, NOW)
+ expect(fatigue.chest).toBeGreaterThan(0)
+ expect(fatigue.biceps).toBe(0)
+ expect(strength.chest).toBe(1)
+ expect(strength.biceps).toBe(STRENGTH_FLOOR)
+ })
+
it('raises starting fatigue with volume, never pins, and fades without a cliff', () => {
const at0 = count => fatigueOf([doneWorkoutAt(SINGLE.id, NOW, count)], NOW)[SINGLE_SLUG]
expect(at0(1)).toBeCloseTo(1 - Math.exp(-V / FATIGUE_REF_VOLUME), 10)
diff --git a/frontend/src/lib/strength-exercises.js b/frontend/src/lib/strength-exercises.js
index 946fa93a5..07e1b108f 100644
--- a/frontend/src/lib/strength-exercises.js
+++ b/frontend/src/lib/strength-exercises.js
@@ -38,15 +38,15 @@ function lastWorkSetAt(S, id) {
function snapshotWeights(entry) {
const catalogue = entry && typeof entry === 'object' ? EXIDX[entry.id] : null
- if (catalogue) {
- const weights = musclesOf(catalogue)
- if (Object.keys(weights).length) return weights
- }
+ if (catalogue) return musclesOf(catalogue)
const direct = entry && typeof entry === 'object'
? (entry.muscleWeights || entry.muscleSnapshot?.muscleWeights)
: null
if (direct && typeof direct === 'object' && !Array.isArray(direct) && Object.keys(direct).length) {
- return direct
+ return Object.fromEntries(Object.entries(direct).filter(([, value]) => {
+ const weight = Number(value)
+ return Number.isFinite(weight) && weight > 0
+ }))
}
return musclesOf(entry)
}
diff --git a/frontend/src/lib/strength-exercises.test.js b/frontend/src/lib/strength-exercises.test.js
index 77beb0f7c..fa8af297e 100644
--- a/frontend/src/lib/strength-exercises.test.js
+++ b/frontend/src/lib/strength-exercises.test.js
@@ -204,6 +204,18 @@ describe('strengthExerciseRowsForMuscle', () => {
const S = unitState([workout(3, [bench])])
expect(strengthExerciseRowsForMuscle(S, NOW, 'biceps')).toEqual([])
})
+
+ it('does not expose zero-weight historical mappings as strength rows', () => {
+ const zeroMapped = {
+ id: 'deleted-zero-mapped',
+ muscleSnapshot: { n: 'Zero mapped', muscleWeights: { chest: 1, biceps: 0 } },
+ sets: [{ phase: 'work', w: 80, r: 8, done: true, unit: 'kg' }],
+ }
+ const S = unitState([workout(3, [zeroMapped])])
+
+ expect(strengthExerciseRowsForMuscle(S, NOW, 'chest')).toHaveLength(1)
+ expect(strengthExerciseRowsForMuscle(S, NOW, 'biceps')).toEqual([])
+ })
})
describe('primaryMuscleOf', () => {
@@ -214,4 +226,9 @@ describe('primaryMuscleOf', () => {
expect(primaryMuscleOf({})).toBeNull()
expect(primaryMuscleOf(null)).toBeNull()
})
+
+ it('never selects an explicit zero as the primary muscle', () => {
+ expect(primaryMuscleOf({ muscleWeights: { chest: 0, biceps: 0 } })).toBeNull()
+ expect(primaryMuscleOf({ muscleWeights: { chest: 1, biceps: 0 } })).toEqual({ slug: 'chest', weight: 1 })
+ })
})
diff --git a/frontend/src/views/Plan.weekly-volume.test.jsx b/frontend/src/views/Plan.weekly-volume.test.jsx
index 92ed28c87..661c2543f 100644
--- a/frontend/src/views/Plan.weekly-volume.test.jsx
+++ b/frontend/src/views/Plan.weekly-volume.test.jsx
@@ -50,4 +50,20 @@ describe('Plan — weekly muscle volume', () => {
expect(summary().textContent).toContain('No muscle volume planned.')
expect(summary().querySelector('.mrow')).toBeNull()
})
+
+ it('omits explicit zero-weight muscles from planned volume', () => {
+ const zeroPress = { id: 'zero-press', n: 'Zero press', muscleWeights: { chest: 1, biceps: 0 }, custom: true }
+ useStore.setState(s => ({
+ S: {
+ ...s.S,
+ customEx: [zeroPress],
+ routines: [{ id: 'zero-plan', name: 'Zero plan', ex: [{ id: zeroPress.id, sets: 2 }] }],
+ week: { 1: ['zero-plan'] },
+ },
+ }))
+ mount()
+
+ expect(summary().textContent).toContain('Chest2 sets')
+ expect(summary().textContent).not.toContain('Biceps')
+ })
})
diff --git a/frontend/src/views/Stats.recovery.test.jsx b/frontend/src/views/Stats.recovery.test.jsx
index 0e260032c..ea13af4e8 100644
--- a/frontend/src/views/Stats.recovery.test.jsx
+++ b/frontend/src/views/Stats.recovery.test.jsx
@@ -312,6 +312,28 @@ describe('Stats muscle recovery view runtime', () => {
expect(Math.min(...Object.values(strengthMap.load))).toBe(STRENGTH_FLOOR)
expect(strengthMap.thresholds.at(-1)).toEqual({ at: 1, level: 4 })
})
+
+ it('keeps zero-weight snapshots out of recovery maps and last-trained recency', async () => {
+ resetFixture([workout('zero-mapped', BASE_NOW, [{
+ id: 'deleted-zero-mapped',
+ muscleSnapshot: { n: 'Zero mapped', muscleWeights: { chest: 1, biceps: 0 } },
+ sets: [set(true)],
+ }])])
+ await mountStats()
+
+ expect(lastMap().load).toEqual({ chest: 1 })
+ await click(viewButton('Fatigue'))
+ expect(lastMap().load.chest).toBeGreaterThan(0)
+ expect(lastMap().load.biceps).toBe(0)
+ expect(levelsOf(lastMap().load, lastMap().thresholds).biceps).toBe(0)
+
+ await click(viewButton('Strength'))
+ expect(lastMap().load.chest).toBe(1)
+ expect(lastMap().load.biceps).toBe(STRENGTH_FLOOR)
+ const bicepsRow = [...muscleCard().querySelectorAll('.mrow')]
+ .find(row => row.querySelector('.nm')?.textContent === 'Biceps')
+ expect(bicepsRow.querySelector('.v').textContent).toContain('not trained')
+ })
})
describe('Stats strength exercise rows', () => {
diff --git a/frontend/src/views/Stats.weekly-volume.test.jsx b/frontend/src/views/Stats.weekly-volume.test.jsx
index 52017c24c..4f2504ccd 100644
--- a/frontend/src/views/Stats.weekly-volume.test.jsx
+++ b/frontend/src/views/Stats.weekly-volume.test.jsx
@@ -250,4 +250,27 @@ describe('Stats — weekly planned vs completed volume', () => {
expect(comparison().textContent).not.toContain('Planned')
expect(comparison().querySelector('[aria-label*="Planned"]')).toBeNull()
})
+
+ it('omits 0/0 mappings while retaining planned-positive completed-zero rows', () => {
+ const zeroPress = { id: 'zero-press', n: 'Zero press', muscleWeights: { chest: 1, biceps: 0 }, custom: true }
+ const plannedOnly = { id: 'planned-only', n: 'Planned only', muscleWeights: { triceps: 1 }, custom: true }
+ mocks.S = state({
+ customEx: [zeroPress, plannedOnly],
+ routines: [{
+ id: 'zero-plan', name: 'Zero plan',
+ ex: [{ id: zeroPress.id, sets: 2 }, { id: plannedOnly.id, sets: 1 }],
+ }],
+ week: { 1: ['zero-plan'] },
+ workouts: [{
+ id: 'zero-workout', d: '2026-09-30', start: new Date('2026-09-30T12:00:00').getTime(),
+ entries: [{ id: zeroPress.id, exercise: zeroPress, sets: [{ done: true }, { done: true }] }],
+ }],
+ })
+ mount()
+
+ expect(mocks.bodyMaps.at(-1).load).toEqual({ chest: 2 })
+ expect(value('chest').textContent).toBe('2/2 · 100%')
+ expect(value('triceps').textContent).toBe('0/1 · 0%')
+ expect(row('biceps')).toBeNull()
+ })
})