From 0f7e3e1291cc97d385dda9fd76c33a031fcd4ff8 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Thu, 17 Sep 2026 11:37:56 +0200 Subject: [PATCH] =?UTF-8?q?Import:=20body=20part=20from=20an=20exercise=20?= =?UTF-8?q?name=20=E2=80=94=20the=20specific=20word=20before=20the=20broad?= =?UTF-8?q?=20one=20(a=20grip=20is=20a=20modifier,=20a=20wrist=20curl=20is?= =?UTF-8?q?=20a=20forearm=20exercise,=20a=20leg=20curl=20and=20a=20Romania?= =?UTF-8?q?n=20deadlift=20are=20legs,=20chest-supported=20is=20a=20row)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/import-csv.js | 19 +++++++--- frontend/src/lib/import-name-bodypart.test.js | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 frontend/src/lib/import-name-bodypart.test.js diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index a53991f..f15e6df 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -265,19 +265,28 @@ export function matchHevyTitle(name) { // 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. +// Order is the rule: the first match wins, so the specific word has to come before the broad one. +// A grip is a modifier on a row or a pulldown, never the movement ("Chest Supported T Row Neutral +// Grip" is a back exercise); a wrist or reverse curl is a forearm exercise that happens to say +// "curl"; a leg curl is not an arm curl; and a Romanian or stiff-leg deadlift trains the legs where +// the conventional pull is filed under the back. "grip" alone still reads as forearms — last. const NAME_BP = [ - [/\b(curl|bicep|biceps|tricep|triceps|skullcrusher|pushdown)\b/, 'upper arms'], - [/\b(wrist|forearm|forearms|grip)\b/, 'lower arms'], + [/\b(wrist|forearm|forearms|reverse curl)\b/, 'lower arms'], + [/\b(leg curl|leg curls|hamstring curl|nordic)\b/, 'upper legs'], + [/\b(romanian|rdl|stiff leg|stiff legged|straight leg)\b.*\bdeadlifts?\b|\brdl\b/, 'upper legs'], + [/\b(curl|curls|bicep|biceps|tricep|triceps|skullcrusher|pushdown)\b/, 'upper arms'], + [/\bchest supported\b/, 'back'], // where the chest rests, not what it trains [/\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(row|rows|pulldown|pullup|pull up|chin up|lat|lats|back|deadlift|deadlifts|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(squat|lunge|leg|glute|hamstring|quad|hip thrust)\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'], + [/\bgrip\b/, 'lower arms'], ] -const bpFromName = name => (NAME_BP.find(([re]) => re.test(name)) || [])[1] || null +export 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 = { diff --git a/frontend/src/lib/import-name-bodypart.test.js b/frontend/src/lib/import-name-bodypart.test.js new file mode 100644 index 0000000..976731b --- /dev/null +++ b/frontend/src/lib/import-name-bodypart.test.js @@ -0,0 +1,36 @@ +// The fallback that reads a body part off an exercise name when the export has no category +// column (Hevy). First match wins, so the order of the rules is the behaviour — reported on +// Discord by rubik_97 with the three cases below. +import { describe, expect, it } from 'vitest' +import { bpFromName } from './import-csv.js' + +const bp = name => bpFromName(name.toLowerCase()) + +describe('body part from an exercise name', () => { + it('reads a grip as a modifier, not as the movement', () => { + expect(bp('Chest Supported T Row Neutral Grip')).toBe('back') + expect(bp('Wide Grip Lat Pulldown')).toBe('back') + expect(bp('Close Grip Bench Press')).toBe('chest') + }) + + it('files wrist and reverse curls under the forearms, not the upper arms', () => { + expect(bp('Wrist Curl')).toBe('lower arms') + expect(bp('Barbell Reverse Curl')).toBe('lower arms') + expect(bp('Hammer Curl')).toBe('upper arms') + }) + + it('keeps leg curls and the hamstring deadlifts on the legs', () => { + expect(bp('Lying Leg Curl')).toBe('upper legs') + expect(bp('Romanian Deadlift')).toBe('upper legs') + expect(bp('Stiff Leg Deadlift')).toBe('upper legs') + expect(bp('RDL')).toBe('upper legs') + expect(bp('Deadlift')).toBe('back') + }) + + 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" + expect(bp('Standing Calf Raise')).toBe('lower legs') + expect(bp('Something Unheard Of')).toBe(null) + }) +})