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.
This commit is contained in:
1 parent
83b2a140d6
commit
f9715d76d3
2 files changed
+20
-1
No files matched your search
@@ -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 = {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user