Import: body part from an exercise name — the specific word before the broad one (a grip is a modifier, a wrist curl is a forearm exercise, a leg curl and a Romanian deadlift are legs, chest-supported is a row)

This commit is contained in:
Duarte Santos committed 2026-09-17 11:37:56 +02:00
1 parent b95561e957
commit 0f7e3e1291
2 files changed
+50 -5

No files matched your search

+14 -5
View File
@@ -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 = {
@@ -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)
})
})