diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index f15e6df..104ad9b 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -286,7 +286,13 @@ const NAME_BP = [ [/\bneck\b/, 'neck'], [/\bgrip\b/, 'lower arms'], ] -export const bpFromName = name => (NAME_BP.find(([re]) => re.test(name)) || [])[1] || null +// Hyphens, underscores and slashes read as spaces first: "Stiff-Legged Deadlift" and +// "Chest-Supported Row" are the same names the rules above spell with a space, and the +// matcher (wordsOf) already treats the two spellings as one exercise — the body part has to agree. +export const bpFromName = name => { + const n = String(name || '').toLowerCase().replace(/[-_/]+/g, ' ').replace(/\s+/g, ' ').trim() + return (NAME_BP.find(([re]) => re.test(n)) || [])[1] || null +} // Categories the exporters use -> the dataset's body parts, for exercises we invent. const CATEGORY_BP = { diff --git a/frontend/src/lib/import-name-bodypart.test.js b/frontend/src/lib/import-name-bodypart.test.js index 976731b..0191f7c 100644 --- a/frontend/src/lib/import-name-bodypart.test.js +++ b/frontend/src/lib/import-name-bodypart.test.js @@ -27,6 +27,19 @@ describe('body part from an exercise name', () => { expect(bp('Deadlift')).toBe('back') }) + // The rules are written with spaces, but people hyphenate these names as often as not (QA C28). + // The matcher already treats "chest-supported row" and "chest supported row" as one exercise; + // the body-part fallback has to agree with it, or the two spellings land on different maps. + it('reads the hyphenated, underscored and slashed spellings like the spaced ones', () => { + expect(bp('Stiff-Legged Deadlift')).toBe('upper legs') + expect(bp('Straight-Leg Deadlift')).toBe('upper legs') + expect(bp('Stiff_Leg Deadlift')).toBe('upper legs') + expect(bp('Chest-Supported Row')).toBe('back') + expect(bp('Chest-Supported T-Bar Row')).toBe('back') + expect(bp('Chest/Supported Row')).toBe('back') + expect(bp('Sit-Up')).toBe('waist') + }) + it('still reads a bare grip exercise as forearms, and the rest as before', () => { expect(bp('Grip Trainer')).toBe('lower arms') expect(bp('Back Squat')).toBe('back') // unchanged: "back" is matched before "squat"