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
fix(import): the Hevy summary counts an exercise in both workouts and routines once
lodepav70ab3574f42b
diff --git a/frontend/src/lib/import-hevy.js b/frontend/src/lib/import-hevy.jsindex 4278b5246..a30799a0b 100644--- a/frontend/src/lib/import-hevy.js+++ b/frontend/src/lib/import-hevy.js@@ -204,11 +204,25 @@ function makeResolver(templates, customEx) {byId,customEx: used => kept(used),unmatchedNames: used => [...new Set(kept(used).map(c => titleOf.get(c.id)))].sort(),+ matchedIds: used => [...matchedIds].filter(id => used.has(id)),matchedCount: used => [...matchedIds].filter(id => used.has(id)).length,createdCount: used => kept(used).length,}}+/**+ * The import sheet's two counts over the parts switched on: each exercise once, by id. An+ * exercise in both the workouts and the routines is one exercise (the same catalogue id, or the+ * same custom one), so adding the two parts' counts would show it twice.+ */+export function hevySummaryCounts(w, r, { workouts = true, routines = true } = {}) {+ const parts = [workouts && w, routines && r].filter(Boolean)+ return {+ matched: new Set(parts.flatMap(p => p.matchedIds || [])).size,+ created: new Set(parts.flatMap(p => (p.customEx || []).map(c => c.id))).size,+ }+}+const toProfileWeight = (wKg, unit) => {if (wKg == null || !isFinite(wKg)) return 0if (unit === 'lb') return Math.round(wKg / LB_TO_KG * 10) / 10@@ -312,6 +326,7 @@ export function parseHevyWorkouts(workouts, templates, { unit = 'kg', customEx =workouts: outWorkouts,customEx: R.customEx(used),matched: R.matchedCount(used),+ matchedIds: R.matchedIds(used),matchedSets: matched,created: R.createdCount(used),unmatchedNames: R.unmatchedNames(used),@@ -399,6 +414,7 @@ export function parseHevyRoutines(routines, templates, { unit = 'kg', customEx =routines: out,customEx: R.customEx(used),matched: R.matchedCount(used),+ matchedIds: R.matchedIds(used),created: R.createdCount(used),unmatchedNames: R.unmatchedNames(used),exerciseCount: out.reduce((n, r) => n + r.ex.length, 0),diff --git a/frontend/src/lib/import-hevy.test.js b/frontend/src/lib/import-hevy.test.jsindex d671441ca..61273cf01 100644--- a/frontend/src/lib/import-hevy.test.js+++ b/frontend/src/lib/import-hevy.test.js@@ -1,7 +1,7 @@import { describe, expect, it, vi, afterEach } from 'vitest'import {matchHevyTemplate, buildHevyExerciseMap, parseHevyWorkouts, parseHevyBodyweight,- parseHevyRoutines, mergeHevyRoutines, localWhen, importHevyData, HevyApiError, HEVY_ID_MAP,+ parseHevyRoutines, mergeHevyRoutines, localWhen, importHevyData, HevyApiError, HEVY_ID_MAP, hevySummaryCounts,} from './import-hevy.js'import { EXIDX } from './exercises.js'import { mergeImport } from './import-csv.js'@@ -320,3 +320,22 @@ describe('parseHevyWorkouts past midnight', () => {expect((w.end - w.start) / 60000).toBe(50)})})++describe('hevySummaryCounts', () => {+ // One library exercise and one custom one, in both a workout and a routine.+ const exercises = [+ { title: 'Lat Pulldown - Close Grip (Cable)', exercise_template_id: '4E5257DE', superset_id: null, sets: [{ type: 'normal', weight_kg: 50, reps: 10 }] },+ { title: 'Lying Neck Rotation', exercise_template_id: 'my-own-template', superset_id: null, sets: [{ type: 'normal', weight_kg: 2, reps: 15 }] },+ ]+ const workout = { id: 'w1', title: 'Neck', start_time: '2026-01-12T10:00:00Z', end_time: '2026-01-12T11:00:00Z', exercises }+ const routine = { id: 'r1', title: 'Neck', exercises }++ it('counts an exercise in both the workouts and the routines once, from the parts switched on', () => {+ const w = parseHevyWorkouts([workout], TEMPLATES, { unit: 'kg' })+ const r = parseHevyRoutines([routine], TEMPLATES, { unit: 'kg' })+ expect([w.matched + r.matched, w.created + r.created]).toEqual([2, 2]) // the sums count each twice+ expect(hevySummaryCounts(w, r)).toEqual({ matched: 1, created: 1 })+ expect(hevySummaryCounts(w, r, { workouts: false })).toEqual({ matched: 1, created: 1 })+ expect(hevySummaryCounts(w, r, { workouts: false, routines: false })).toEqual({ matched: 0, created: 0 })+ })+})diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 2d9f5f006..fb4e4034f 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -32,7 +32,7 @@ import ExerciseViewToggle from './components/ExerciseViewToggle.jsx'import { sameMuscleFirst, swapMuscleOf } from './lib/similar-exercises.js'import { exerciseMuscleSnapshot, loadOfWorkouts, MUSCLES, MUSCLE_NAME, muscleWeightsOf, muscleGroupsOf, hasExplicitMuscleMetadata, inMuscleOrder } from './lib/muscles.js'import { parseImport, mergeImport } from './lib/import-csv.js'-import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.js'+import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines, hevySummaryCounts } from './lib/import-hevy.js'import { buildPlanBundle, parsePlan, mergePlan, printPlan, planPrintHTML } from './lib/plan-share.js'import { printOptions } from './lib/print-doc.js'import { printWorkout } from './lib/report-print.js'@@ -655,6 +655,7 @@ function HevyImportSheet({ close }) {...(wantWorkouts ? w.unmatchedNames : []),...(wantRoutines ? r.unmatchedNames : []),])].sort()+ const counts = hevySummaryCounts(w, r, { workouts: wantWorkouts, routines: wantRoutines })return <><h3>{t('Import from Hevy')}</h3>@@ -666,8 +667,8 @@ function HevyImportSheet({ close }) {<div className="tiles" style={{ textAlign: 'start' }}><div className="tile"><div className="l">{t('Workouts')}</div><div className="v" style={{ fontSize: '1.1rem' }}>{w.workouts.length}</div></div><div className="tile"><div className="l">{t('Routines')}</div><div className="v" style={{ fontSize: '1.1rem' }}>{r.routines.length}</div></div>- <div className="tile"><div className="l">{t('Exercises matched')}</div><div className="v" style={{ fontSize: '1.1rem' }}>{w.matched + r.matched}</div></div>- <div className="tile"><div className="l">{t('Added as your own')}</div><div className="v" style={{ fontSize: '1.1rem' }}>{w.created + r.created}</div></div>+ <div className="tile"><div className="l">{t('Exercises matched')}</div><div className="v" style={{ fontSize: '1.1rem' }}>{counts.matched}</div></div>+ <div className="tile"><div className="l">{t('Added as your own')}</div><div className="v" style={{ fontSize: '1.1rem' }}>{counts.created}</div></div></div>{w.workouts.length > 0 && <div className="row between" style={{ padding: '10px 2px', borderTop: '1px solid var(--sep)', gap: 12 }}>