From f9715d76d35dc3401bce52fe0de741ce00b25849 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Sat, 19 Sep 2026 17:08:09 +0200 Subject: [PATCH] Import: hyphenated names get the same body part as their spaced spelling (QA C28) bpFromName matched its rules against the lower-cased name only, while the rules are written with spaces: 'Stiff-Legged Deadlift' fell through to the deadlift rule (back) and 'Chest-Supported Row' hit 'chest' before 'row'. The matcher's wordsOf already treats both spellings as one exercise, so the fallback now reads '-', '_' and '/' as spaces before the rules run and agrees with it. --- frontend/src/lib/import-csv.js | 8 +++++++- frontend/src/lib/import-name-bodypart.test.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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"