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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
feat(muscles): preserve explicit zero weights
Emil Zapata93f0e31f6c10
diff --git a/frontend/src/lib/muscles.js b/frontend/src/lib/muscles.jsindex 1896d4ad1..2c4b869fb 100644--- a/frontend/src/lib/muscles.js+++ b/frontend/src/lib/muscles.js@@ -186,16 +186,16 @@ export function matchesMuscleGroups(ex, requested) {return wanted.some(group => groups.has(group))}-/** Muscles one exercise trains: { slug: 0…1 }. Duplicate metadata never adds load twice. */-export function musclesOf(ex) {+/** Complete muscle-weight metadata, including explicit zero-credit associations. */+export function muscleWeightsOf(ex) {if (!ex) return {}const sourceEx = metadataOf(ex)- if (sourceEx !== ex) return musclesOf(sourceEx)+ if (sourceEx !== ex) return muscleWeightsOf(sourceEx)if (ex.muscleWeights && typeof ex.muscleWeights === 'object' && !Array.isArray(ex.muscleWeights)) {const snapshot = {}MUSCLES.forEach(slug => {const weight = Number(ex.muscleWeights[slug])- if (Number.isFinite(weight) && weight > 0) snapshot[slug] = weight+ if (Number.isFinite(weight) && weight >= 0 && weight <= 1) snapshot[slug] = weight})if (Object.keys(snapshot).length) return snapshot}@@ -221,13 +221,18 @@ export function musclesOf(ex) {return out}+/** Muscles one exercise trains: positive effective stimulus only. */+export function musclesOf(ex) {+ return Object.fromEntries(Object.entries(muscleWeightsOf(ex)).filter(([, weight]) => weight > 0))+}+/** Snapshot display and weighted muscle metadata into a completed history entry. */export function exerciseMuscleSnapshot(ex) {if (!ex || typeof ex !== 'object') return {}const out = {}if (ex.n != null) out.n = ex.nif (ex.bp != null) out.bp = ex.bp- const weights = musclesOf(ex)+ const weights = muscleWeightsOf(ex)if (Object.keys(weights).length) out.muscleWeights = { ...weights }const parts = explicitPartsOf(ex)if (parts) {diff --git a/frontend/src/lib/muscles.test.js b/frontend/src/lib/muscles.test.jsindex dba5a412e..a4e087607 100644--- a/frontend/src/lib/muscles.test.js+++ b/frontend/src/lib/muscles.test.js@@ -3,7 +3,8 @@ import { EXIDX, EXDB, smOf } from './exercises.js'import { LANGS, DERIVED_LOCALES } from './i18n-core.js'import {MUSCLE_NAME, exerciseMuscleSnapshot, hasExplicitMuscleMetadata, levelsOf, loadOf,- loadOfWorkouts, loadOfWeeklyPlan, matchesMuscleGroups, muscleBalanceWindow, muscleGroupsOf, musclesOf, rankOf+ loadOfWorkouts, loadOfWeeklyPlan, matchesMuscleGroups, muscleBalanceWindow, muscleGroupsOf,+ musclesOf, muscleWeightsOf, rankOf} from './muscles.js'describe('multi-muscle exercise metadata', () => {@@ -50,6 +51,33 @@ describe('multi-muscle exercise metadata', () => {})})+describe('explicit muscle weights', () => {+ const complete = { chest: 1, deltoids: 0.4, triceps: 0 }++ it('preserves every finite explicit weight from zero through one', () => {+ expect(muscleWeightsOf({ muscleWeights: complete })).toEqual(complete)+ })++ it('keeps effective stimulus positive-only', () => {+ expect(musclesOf({ muscleWeights: complete })).toEqual({ chest: 1, deltoids: 0.4 })+ })++ it('treats a recognized all-zero map as authoritative instead of using body-part defaults', () => {+ const ex = { bp: 'chest', muscleWeights: { chest: 0, triceps: 0 } }+ expect(muscleWeightsOf(ex)).toEqual({ chest: 0, triceps: 0 })+ expect(musclesOf(ex)).toEqual({})+ })++ it('preserves complete weights in history snapshots', () => {+ expect(exerciseMuscleSnapshot({ n: 'Press', bp: 'chest', muscleWeights: complete }))+ .toMatchObject({ n: 'Press', bp: 'chest', muscleWeights: complete })+ })++ it('keeps legacy primary and secondary fallback weights', () => {+ expect(muscleWeightsOf({ tg: 'pectorals', mg: 'triceps' })).toEqual({ chest: 1, triceps: 0.4 })+ })+})+describe('catalogue secondary muscles', () => {it('maps a bench press to chest, triceps and deltoids', () => {expect(musclesOf(EXIDX['0025'])).toMatchObject({