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/450'
Duarte Santos5db1ce68cc6a
diff --cc frontend/src/lib/onerm.jsindex 1837819b1,1837819b1..4504eaf57--- a/frontend/src/lib/onerm.js+++ b/frontend/src/lib/onerm.js@@@ -1,6 -1,6 +1,6 @@@import { isAssisted } from './exercises.js'import { isSideSet } from './workout-model.js'--import { entriesForExercise, metricRowsForEntry } from './history.js'++import { entriesForExercise, metricRowsForEntry, workoutAt } from './history.js'// Estimated one-rep max (issue #18).//// Deliberately knows nothing about the exercise database: an estimate needs a weight AND a@@@ -78,7 -78,7 +78,7 @@@ export function e1rmSeries(S, exId, forconst pts = [];(S.workouts || []).forEach(w => {const best = bestSetOfEntries(entriesForExercise(w, exId), formula)-- if (best) pts.push({ t: w.start, d: w.d, y: best.est, w: best.w, r: best.r })++ if (best) pts.push({ t: workoutAt(w), d: w.d, y: best.est, w: best.w, r: best.r })})return pts}diff --cc frontend/src/lib/per-set.jsindex 000000000,f2c35546c..058b1e3cemode 000000,100644..100644--- a/frontend/src/lib/per-set.js+++ b/frontend/src/lib/per-set.js@@@ -1,0 -1,78 +1,78 @@@+ /* Per-set progress (issue #145): Stats → Exercise progress drawn as one line per set number, so+ * the set you drop off on shows up — which is often not the last one.+ *+ * A set's number is its place among the session's working sets of this exercise, in reps mode:+ * warm-ups are not counted, a set left undone keeps its number (set 4 never reads as set 3), a+ * per-side set is one set, and a drop set or rest-pause set is plotted at its main set. The same+ * exercise twice in one workout keeps counting across both entries. Pure, so the chart and the+ * tests read the same thing. */-import { entriesForExercise, completedRepsOf } from './history.js'++import { entriesForExercise, completedRepsOf, workoutAt } from './history.js'+ import { phaseForSet, modeForSet, hasCompletedWork, isSideSet } from './workout-model.js'+ import { estimate1RM } from './onerm.js'++ export const PER_SET_MAX = 5++ const doneSides = set => [set.sides.L, set.sides.R].filter(side => side?.done === true)+ const weightOf = set => (isSideSet(set) ? Math.max(0, ...doneSides(set).map(side => Number(side.w) || 0)) : Number(set.w) || 0)++ /** Each session with plottable sets: [{ t, d, sets: [{ n, y, w, r }] }], in workout order.+ * `metric`: 'weight' (default), 'reps', or 'e1rm' — the estimated 1RM of the set itself, which+ * is what tells straight sets apart: at one weight their lines would lie on top of each other,+ * and the rep that went missing in the last set is the thing to see. A set past the estimate's+ * rep cap has no point, as on the Est. 1RM curve. A per-side set is estimated from one side's+ * reps, not both added up. */+ export function perSetSessions(workouts, exId, { metric = 'weight' } = {}) {+ const out = []+ for (const w of workouts || []) {+ let n = 0+ const sets = []+ for (const entry of entriesForExercise(w, exId)) {+ const target = entry.target || entry+ for (const set of Array.isArray(entry.sets) ? entry.sets : []) {+ if (phaseForSet(set) !== 'work' || modeForSet(set, target) !== 'reps') continue+ n+++ if (!hasCompletedWork(set)) continue+ const wt = weightOf(set), r = completedRepsOf(set)+ const perSide = isSideSet(set) ? r / doneSides(set).length : r+ const y = metric === 'reps' ? r : metric === 'e1rm' ? estimate1RM(wt, perSide) || 0 : wt+ if (y > 0) sets.push({ n, y, w: wt, r })+ }+ }- if (sets.length) out.push({ t: w.start, d: w.d, sets })++ if (sets.length) out.push({ t: workoutAt(w), d: w.d, sets })+ }+ return out+ }++ /** One line per set number for the chart, at most PER_SET_MAX of them: { lines, hidden }, where+ * `hidden` counts the set numbers left out, so the card can say so instead of dropping them quietly. */+ export function perSetLines(sessions) {+ const byN = new Map()+ for (const s of sessions) {+ for (const set of s.sets) {+ if (!byN.has(set.n)) byN.set(set.n, [])+ byN.get(set.n).push({ t: s.t, y: set.y, d: s.d })+ }+ }+ const all = [...byN.keys()].sort((a, b) => a - b).map(n => ({ n, points: byN.get(n) }))+ const lines = all.slice(0, PER_SET_MAX)+ return { lines, hidden: all.length - lines.length }+ }++ /** The set that most often is the first to fall below set 1, as { n, count, of } — `of` being+ * the sessions with a set 1 and at least one more. Null with fewer than three such sessions (too+ * few to call it a pattern) or when no session dropped. Ties go to the earlier set. */+ export function dropOffSet(sessions) {+ const multi = sessions.filter(s => s.sets.length >= 2 && s.sets[0].n === 1)+ if (multi.length < 3) return null+ const counts = new Map()+ for (const s of multi) {+ const first = s.sets[0].y+ const drop = s.sets.slice(1).find(set => set.y < first)+ if (drop) counts.set(drop.n, (counts.get(drop.n) || 0) + 1)+ }+ let best = null+ for (const [n, count] of counts) {+ if (!best || count > best.count || (count === best.count && n < best.n)) best = { n, count }+ }+ return best && { ...best, of: multi.length }+ }diff --cc frontend/src/views/Stats.jsxindex fd6b29c61,dc242de6b..548db9613--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@@ -1,8 -1,8 +1,8 @@@import { useEffect, useMemo, useState } from 'react'import { useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'- import { EXIDX, matchExercise, betterWeight } from '../lib/exercises.js'+ import { EXIDX, matchExercise, betterWeight, isAssisted } from '../lib/exercises.js'-import { lastBW, streakWeeks, setLabel, modeOf, effortOf, entriesForExercise, metricEntriesForExercise, metricModeForEntry, bestWeightForEntry, completedRepsOf, workoutDay } from '../lib/history.js'+import { lastBW, streakWeeks, setLabel, modeOf, effortOf, entriesForExercise, metricEntriesForExercise, metricModeForEntry, bestWeightForEntry, completedRepsOf, workoutDay, workoutAt } from '../lib/history.js'import { fmtNum, fmtDate, fmtVol, todayISO, isoOf, weekKey, weekStartOf, exerciseNameText } from '../lib/format.js'import { speedUnitOf, speedLabel, toSpeed } from '../lib/speed.js'import { t, exerciseNameFor, exerciseNameClass, getLang } from '../lib/i18n.js'