From e737954e37fe0634d23ea2863ae404f91e3a2d1d Mon Sep 17 00:00:00 2001 From: Ameer Khan Date: Tue, 25 Aug 2026 15:21:19 +0000 Subject: [PATCH] Import: resolve Hevy exercise names instead of inventing customs Hevy writes the equipment in parentheses and says "bicep"/"chest fly" where the catalogue says "biceps"/"fly", so the word-bag matcher landed one word off. A real 34-session export arrived with 27 custom exercises covering a third of its sets. Three separate causes: - SYN rewrote 'machine' -> 'lever' before 'smith machine' -> 'smith' could ever fire, so every Smith-machine name became "smith lever ..." and matched nothing in the catalogue. The two rules are order dependent; 'smith machine' now runs first. - The alias table had no entry for Hevy's vocabulary. Added the names from a real export, mapped by hand to catalogue ids. - Hevy exports no category column, so every invented exercise took the 'upper legs' default and a third of an imported history was attributed to the legs in the muscle map. With no category to read, the body part now comes off the name instead. The same export now creates 2 custom exercises instead of 27. The two that remain, box jump and wall ball, are genuinely not in a 1,324-entry strength catalogue, and guessing would file them under the wrong lift. import-match.test.js covers the new aliases, the SYN ordering and the body-part inference. --- frontend/src/lib/import-csv.js | 43 +++++++++++++++++- frontend/src/lib/import-match.test.js | 63 ++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index 1cf2402..282f0bb 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -111,7 +111,9 @@ export function detectSource(header) { const SYN = [ [/\bbb\b/g, 'barbell'], [/\bdb\b/g, 'dumbbell'], [/\bkb\b/g, 'kettlebell'], [/\bohp\b/g, 'overhead press'], [/\bbw\b/g, 'body weight'], [/\bbodyweight\b/g, 'body weight'], - [/\bmachine\b/g, 'lever'], [/\bsmith machine\b/g, 'smith'], [/\bez bar\b/g, 'ez barbell'], + // 'smith machine' first: the generic machine->lever rule would otherwise eat the word + // and leave 'smith lever', which matches no entry in the dataset. + [/\bsmith machine\b/g, 'smith'], [/\bmachine\b/g, 'lever'], [/\bez bar\b/g, 'ez barbell'], [/\bpull ups?\b/g, 'pull up'], [/\bchin ups?\b/g, 'chin up'], [/\bpush ups?\b/g, 'push up'], [/\bsit ups?\b/g, 'sit up'], [/\bdips?\b/g, 'dip'], [/\braises?\b/g, 'raise'], [/\bcurls?\b/g, 'curl'], [/\bpresses\b/g, 'press'], [/\bextensions?\b/g, 'extension'], @@ -185,6 +187,25 @@ const ALIAS_EX = { // same movement, wrong equipment label, which beats leaving it uncategorised. 'pallof press': '0979', 'cable pallof press': '0979', 'vertical pallof press': '1015', 'cable core pallof press': '0979', 'core pallof press': '0979', + // Hevy's own vocabulary, from a real export. Hevy writes the equipment in parentheses + // and uses "bicep"/"chest fly"/"reverse fly" where the dataset says "biceps"/"fly"/ + // "reverse fly", so these are near-misses the word-bag cannot close on its own. + 'bicep curl (dumbbell)': '0294', 'bicep curl (cable)': '0868', 'bicep curl (barbell)': '0031', + 'chest fly (dumbbell)': '0308', 'chest fly (machine)': '0596', 'butterfly (pec deck)': '0596', + 'incline chest fly (dumbbell)': '0319', 'cable fly crossovers': '1269', + 'rear delt reverse fly (dumbbell)': '0383', 'rear delt reverse fly (machine)': '0602', + 'chest supported reverse fly (dumbbell)': '0383', + 'bench press (smith machine)': '0748', 'overhead press (smith machine)': '0766', + 'hack squat (machine)': '0743', 'iso-lateral row (machine)': '0571', + 'seated cable row - bar grip': '0218', 'reverse grip lat pulldown (cable)': '0673', + 'single arm lateral raise (cable)': '0192', 'plate front raise': '0310', + 'back extension (weighted hyperextension)': '0573', + 'behind the back bicep wrist curl (barbell)': '0104', + // A face pull is a rope rear-delt row; the dataset has no entry under that name. + 'face pull': '0203', + // Cardio again: the only candidates in a 29-entry cardio vocabulary. + 'jumping jack': '3220', 'jumping jacks': '3220', 'battle ropes': '0128', + 'stair machine (steps)': '2311', 'stair machine': '2311', } let ALIAS_IDX = null @@ -230,6 +251,23 @@ export function matchExercise(name) { return ties === 1 ? best : null } +// Hevy exports no category column, so every invented exercise fell through to the +// 'upper legs' default and a third of an imported history was attributed to the legs in +// the muscle map. When there is no category, read the body part off the name instead. +const NAME_BP = [ + [/\b(curl|bicep|biceps|tricep|triceps|skullcrusher|pushdown)\b/, 'upper arms'], + [/\b(wrist|forearm|forearms|grip)\b/, 'lower arms'], + [/\b(bench|chest|pec|fly|flye|crossover|crossovers|dip)\b/, 'chest'], + [/\b(row|pulldown|pullup|pull up|chin up|lat|lats|back|deadlift|shrug)\b/, 'back'], + [/\b(shoulder|delt|delts|overhead|lateral raise|front raise|face pull|press up)\b/, 'shoulders'], + [/\b(calf|calves)\b/, 'lower legs'], + [/\b(squat|lunge|leg|glute|hamstring|quad|hip thrust|deadlift)\b/, 'upper legs'], + [/\b(ab|abs|core|plank|crunch|sit up|oblique|russian twist)\b/, 'waist'], + [/\b(run|running|jog|bike|cycling|rope|ropes|jump|jacks|burpee|sprint|treadmill|stair)\b/, 'cardio'], + [/\bneck\b/, 'neck'], +] +const bpFromName = name => (NAME_BP.find(([re]) => re.test(name)) || [])[1] || null + // Categories the exporters use -> the dataset's body parts, for exercises we invent. const CATEGORY_BP = { chest: 'chest', back: 'back', lats: 'back', shoulders: 'shoulders', delts: 'shoulders', @@ -358,7 +396,8 @@ export function parseWorkoutCSV(text, { unit = 'kg' } = {}) { if (!c) { c = { id: 'im' + uid(), n: name.toLowerCase(), custom: true, eq: 'custom', tg: '', desc: '', - bp: CATEGORY_BP[cell(r, 'category').toLowerCase()] || (km || (mins && !reps) ? 'cardio' : 'upper legs'), + bp: CATEGORY_BP[cell(r, 'category').toLowerCase()] || (km || (mins && !reps) ? 'cardio' : null) + || bpFromName(name.toLowerCase()) || 'upper legs', } created.set(key, c) unmatched.add(name) diff --git a/frontend/src/lib/import-match.test.js b/frontend/src/lib/import-match.test.js index 631b667..2febc5f 100644 --- a/frontend/src/lib/import-match.test.js +++ b/frontend/src/lib/import-match.test.js @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest' -import { matchExercise } from './import-csv.js' +import { matchExercise, parseWorkoutCSV } from './import-csv.js' import { EXIDX } from './exercises.js' // The names other apps actually export, and the catalogue entry each has to land on. @@ -12,6 +12,20 @@ const MAPS = { 'Cable Core Pallof Press': '0979', Elliptical: '2141', 'Stationary Bike': '2138', + // Hevy's vocabulary, from a real export. It writes the equipment in parentheses and says + // "bicep"/"chest fly" where the catalogue says "biceps"/"fly", so the word-bag lands one + // word off on every one of these and they arrived as custom exercises. + 'Bicep Curl (Dumbbell)': '0294', + 'Bicep Curl (Cable)': '0868', + 'Chest Fly (Machine)': '0596', + 'Butterfly (Pec Deck)': '0596', + 'Incline Chest Fly (Dumbbell)': '0319', + 'Rear Delt Reverse Fly (Dumbbell)': '0383', + 'Face Pull': '0203', + 'Battle Ropes': '0128', + 'Hack Squat (Machine)': '0743', + 'Seated Cable Row - Bar Grip': '0218', + 'Single Arm Lateral Raise (Cable)': '0192', } describe('foreign exercise names resolve to the catalogue', () => { @@ -43,8 +57,55 @@ describe('foreign exercise names resolve to the catalogue', () => { expect(matchExercise('Deadlift')).toBe('0032') }) + // SYN rewrote 'machine' -> 'lever' before it ever reached 'smith machine' -> 'smith', + // so every Smith-machine name arrived as "smith lever ..." and could not match anything + // in the catalogue. The two rules are order-dependent; this pins the order. + it('resolves Smith-machine names rather than leaving a stray "lever"', () => { + expect(matchExercise('Bench Press (Smith Machine)')).toBe('0748') + expect(matchExercise('Overhead Press (Smith Machine)')).toBe('0766') + expect(matchExercise('Smith Machine Bench Press')).toBe('0748') + }) + + // The generic machine -> lever rule still has to work on its own. + it('keeps the plain machine alias working', () => { + expect(matchExercise('Seated Fly (Machine)')).toBe('0596') + }) + it('still refuses to guess', () => { expect(matchExercise('Some Movement I Invented')).toBe(null) expect(matchExercise('')).toBe(null) }) }) + +// Hevy exports no category column, so every invented exercise took the 'upper legs' default +// and a third of an imported history was attributed to the legs in the muscle map. With no +// category to read, the body part comes off the name instead. +describe('invented exercises get a body part from their name', () => { + const HEAD = 'title,start_time,end_time,description,exercise_title,superset_id,exercise_notes,set_index,set_type,weight_kg,reps,distance_km,duration_seconds,rpe' + const row = name => `W,"09 Oct 2025, 19:22","09 Oct 2025, 20:22",,"${name}",,,0,normal,40,10,,,` + const bpOf = name => { + const r = parseWorkoutCSV([HEAD, row(name)].join('\n'), { unit: 'kg' }) + return r.customEx[0] && r.customEx[0].bp + } + + it('reads the body part off names the catalogue does not have', () => { + expect(bpOf('Kirk Shrug Machine Thing')).toBe('back') + expect(bpOf('Bicep Curl Contraption')).toBe('upper arms') + expect(bpOf('Standing Calf Thing')).toBe('lower legs') + }) + + it('no longer files everything under the legs', () => { + expect(bpOf('Some Chest Contraption')).not.toBe('upper legs') + expect(bpOf('Some Chest Contraption')).toBe('chest') + }) + + it('leaves a genuine leg movement on the legs', () => { + expect(bpOf('Bulgarian Split Squat Machine v9')).toBe('upper legs') + }) + + it('still prefers an explicit category column when the file has one', () => { + const head = 'Date,Exercise,Category,Weight,Reps' + const r = parseWorkoutCSV([head, '2025-10-09,Some Invented Lift,Shoulders,40,10'].join('\n'), { unit: 'kg' }) + expect(r.customEx[0].bp).toBe('shoulders') + }) +})