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
Merge remote-tracking branch 'pr/94'
Duarte Santos8323e06819c8
diff --cc frontend/src/lib/history.test.jsindex 650eadac5,fed50f5ae..352972e5e--- a/frontend/src/lib/history.test.js+++ b/frontend/src/lib/history.test.js@@@ -477,48 -477,101 +477,141 @@@ describe('workoutVolume', () =>const w = { entries: [{ id: BW, target: { bodyweight: true }, sets: [{ w: 0, r: 20, done: true }] }] }expect(workoutVolume(w)).toBe(0)})++ it('recognizes both warm-up schemas in work-set counts', () => {+ const w = {+ unit: 'kg',+ entries: [{+ id: LIFT,+ unit: 'kg',+ sets: [+ { warmup: true, unit: 'kg', w: 20, r: 5, done: true },+ { phase: 'warmup', unit: 'kg', w: 30, r: 5, done: true },+ { phase: 'work', unit: 'kg', w: 60, r: 5, done: true },+ ],+ }],+ }+ expect(workSetsDone(w)).toBe(1)+ })++ it('does not use a warm-up as the previous best working weight', () => {+ expect(bestWeightFor({ workouts: [{ entries: [{ id: LIFT, topW: 120, sets: [+ { phase: 'warmup', done: true, w: 120 },+ { phase: 'work', done: true, w: 80 },+ ] }] }] }, LIFT)).toBe(80)+ expect(bestWeightFor({ workouts: [{ entries: [{ id: LIFT, topW: 120, sets: [+ { phase: 'warmup', done: true, w: 120 },+ ] }] }] }, LIFT)).toBe(0)+ })++ it('uses completed non-warm-up load for timed entries', () => {+ expect(bestWeightForEntry({ target: { mode: 'time' }, topW: 200, sets: [+ { phase: 'warmup', sec: 30, w: 30, done: true },+ { phase: 'work', sec: 60, w: 20, done: true },+ { phase: 'work', sec: 75, w: 25, done: true },+ { phase: 'work', sec: 90, w: 40, done: false },+ ] })).toBe(25)+ })++ it('does not report a repeated weighted timed hold as a new load PR (blocker 3)', () => {+ const prior = {+ id: LIFT,+ target: { mode: 'time' },+ sets: [{ phase: 'work', sec: 60, w: 20, done: true }],+ }+ const repeated = {+ id: LIFT,+ target: { mode: 'time' },+ sets: [{ phase: 'work', sec: 60, w: 20, done: true }],+ }+ const state = { workouts: [{ entries: [prior] }] }+ const repeatedWeight = Math.max(0, ...repeated.sets.filter(set => set.done).map(set => set.w || 0))++ expect(bestWeightForEntry(prior)).toBe(20)+ expect(repeatedWeight > bestWeightFor(state, LIFT)).toBe(false)+ })+ })++ describe('superset editing', () => {+ it('pairs adjacent entries without mutating the source and keeps the display units contiguous', () => {+ const entries = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]+ const paired = pairAdjacent(entries, 1, 2, 'sg-new')++ expect(paired).toEqual([{ id: 'a' }, { id: 'b', sg: 'sg-new' }, { id: 'c', sg: 'sg-new' }])+ expect(entries).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }])+ expect(supersetUnits(paired)).toEqual([[0], [1, 2]])+ })++ it('merges both contiguous groups when their boundary entries are paired', () => {+ const entries = [+ { id: 'a', sg: 'left' }, { id: 'b', sg: 'left' },+ { id: 'c', sg: 'right' }, { id: 'd', sg: 'right' }+ ]+ const merged = pairAdjacent(entries, 1, 2)++ expect(merged.map(e => e.sg)).toEqual(['left', 'left', 'left', 'left'])+ expect(entries.map(e => e.sg)).toEqual(['left', 'left', 'right', 'right'])+ })++ it('unpairs one entry and removes sg values left without an adjacent partner', () => {+ const entries = [+ { id: 'a', sg: 'group' }, { id: 'b', sg: 'group' }, { id: 'c', sg: 'group' },+ { id: 'd', sg: 'orphan' }+ ]+ const unpaired = unpairSuperset(entries, 1)++ expect(unpaired).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }])+ expect(entries.map(e => e.sg)).toEqual(['group', 'group', 'group', 'orphan'])+ })++ it('rejects a non-adjacent pairing request', () => {+ const entries = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]++ expect(() => pairAdjacent(entries, 0, 2, 'sg-invalid')).toThrow(/adjacent/)+ expect(entries).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }])+ })})+describe('superset editing', () => {+ it('pairs adjacent entries without mutating the source and keeps the display units contiguous', () => {+ const entries = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]+ const paired = pairAdjacent(entries, 1, 2, 'sg-new')++ expect(paired).toEqual([{ id: 'a' }, { id: 'b', sg: 'sg-new' }, { id: 'c', sg: 'sg-new' }])+ expect(entries).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }])+ expect(supersetUnits(paired)).toEqual([[0], [1, 2]])+ })++ it('merges both contiguous groups when their boundary entries are paired', () => {+ const entries = [+ { id: 'a', sg: 'left' }, { id: 'b', sg: 'left' },+ { id: 'c', sg: 'right' }, { id: 'd', sg: 'right' }+ ]+ const merged = pairAdjacent(entries, 1, 2)++ expect(merged.map(e => e.sg)).toEqual(['left', 'left', 'left', 'left'])+ expect(entries.map(e => e.sg)).toEqual(['left', 'left', 'right', 'right'])+ })++ it('unpairs one entry and removes sg values left without an adjacent partner', () => {+ const entries = [+ { id: 'a', sg: 'group' }, { id: 'b', sg: 'group' }, { id: 'c', sg: 'group' },+ { id: 'd', sg: 'orphan' }+ ]+ const unpaired = unpairSuperset(entries, 1)++ expect(unpaired).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }])+ expect(entries.map(e => e.sg)).toEqual(['group', 'group', 'group', 'orphan'])+ })++ it('rejects a non-adjacent pairing request', () => {+ const entries = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]++ expect(() => pairAdjacent(entries, 0, 2, 'sg-invalid')).toThrow(/adjacent/)+ expect(entries).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }])+ })+})+describe('session row helpers', () => {it('cascadeWeight propagates to same-flag undone rows and never rewrites done sets', () => {diff --cc frontend/src/lib/recovery.jsindex 373786e4e,477c19387..a1b2f3ba8--- a/frontend/src/lib/recovery.js+++ b/frontend/src/lib/recovery.js@@@ -274,13 -111,21 +274,14 @@@ function fatigueValue(events, now)** @param {Array<object>} workouts Workout history with `start`/`d` and entry set arrays.* @param {number} now Current time in milliseconds; injected to keep this function deterministic.+ * @param {{unit?: string}} options Reserved profile-level options; unit is supplied at the UI boundary.* @returns {Record<string, number>} Fatigue values keyed by every drawable muscle slug.*/-export function fatigueOf(workouts, now, options = {}) {- // Keep the profile unit at this boundary for a future separately reviewed tonnage model.- // The current mainline set-count model is intentionally unit-independent.- void options.unit+export function fatigueOf(workouts, now, opts = {}) {const current = Number(now)- const cutoff = current - FATIGUE_SCAN_MS- const stimuli = completedStimuli(workouts, timestamp => timestamp > cutoff)- const byMuscle = Object.fromEntries(MUSCLES.map(slug => [slug, []]))- for (const stimulus of stimuli) byMuscle[stimulus.slug].push(stimulus)-const result = emptyMuscleMap(0)if (!Number.isFinite(current)) return result+ const byMuscle = fatigueStimuli(workouts, current, opts)for (const slug of MUSCLES) result[slug] = fatigueValue(byMuscle[slug], current)return result}diff --cc frontend/src/views/Stats.jsxindex 14ef77bb4,b2e5a2652..c16a41246--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@@ -11,7 -11,8 +11,8 @@@ import Heatmap from '../components/Heatimport Icon from '../components/Icon.jsx'import BodyMap, { BodyMapLegend } from '../components/BodyMap.jsx'import { loadOfWorkouts, rankOf, MUSCLE_NAME, musclesOf } from '../lib/muscles.js'-import { fatigueOf, strengthOf, STRENGTH_FLOOR } from '../lib/recovery.js'+import { fatigueOf, strengthOf, STRENGTH_FLOOR, LB_TO_KG } from '../lib/recovery.js'+ import { strengthExerciseRowsForMuscle } from '../lib/strength-exercises.js'import { fatigueStateOf } from '../lib/recovery-view.js'import { e1rmSeries, best1RM } from '../lib/onerm.js'import {@@@ -100,19 -103,10 +103,18 @@@ function MuscleBalance({ S })const [sel, setSel] = useState(null)const now = useNow()const workouts = S.workouts- const fatigue = useMemo(() => fatigueOf(workouts, now, { unit: S.unit }), [workouts, now, S.unit])- const strength = useMemo(() => strengthOf(workouts, now), [workouts, now])+ // The user's own last registered bodyweight drives bodyweight-exercise tonnage.+ const bodyweightKg = useMemo(() => {+ const entries = S.bodyweight || []+ if (!entries.length) return null+ const last = entries.slice().sort((a, b) => String(a.d).localeCompare(String(b.d))).at(-1)+ if (!last || !(last.w > 0)) return null+ return S.unit === 'lb' ? last.w * LB_TO_KG : last.w+ }, [S.bodyweight, S.unit])+ const fatigue = useMemo(() => fatigueOf(workouts, now, { bodyweightKg, unit: S.unit }), [workouts, now, bodyweightKg, S.unit])+ const strength = useMemo(() => strengthOf(workouts, now, { bodyweightKg, unit: S.unit }), [workouts, now, bodyweightKg, S.unit])+ const muscleExercises = useMemo(() => (sel ? strengthExerciseRowsForMuscle(S, now, sel) : []), [S, now, sel])const lastTrained = useMemo(() => latestMuscleTraining(workouts), [workouts])- const { worked: strengthOrder } = rankOf(strength)- const detrained = strengthOrder.filter(slug => strength[slug] < 1)const strengthHint = slug => {if (lastTrained[slug] == null) return t('not trained')const weeks = weeksSinceTraining(now, lastTrained[slug])