From f5b215f10999b3e0a098facab009f966c41b70aa Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 14:01:25 +0200 Subject: [PATCH] import: fix the gravl column aliases so they can actually match mapHeader normalises the header before comparing ('Weight (kg)' -> 'weight kg') but matches the alias list raw, so an alias written with parentheses never matches. Three of the added ones were dead entries whose normalised twin was already in the table; 'set duration (sec)' had no twin, so gravl's per-set duration was dropped and its cardio rows skipped entirely. Also moves that column from "time" to "seconds", which is what it is: toMinutes() would have read gravl's 22 seconds as 22 minutes. Adds the gravl sample from the merge request as a regression test. --- frontend/src/lib/import-csv.js | 10 +++++----- frontend/src/lib/import-csv.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index a3a049c..1cf2402 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -62,8 +62,8 @@ const COLUMNS = [ ['endTime', ['end time']], ['workoutName', ['workout name', 'title', 'workout']], ['category', ['category', 'body part', 'muscle group']], - ['weightKg', ['weight kg', 'weight (kg)']], - ['weightLb', ['weight lbs', 'weight lb', 'weight (lb)']], + ['weightKg', ['weight kg']], + ['weightLb', ['weight lbs', 'weight lb']], ['weight', ['weight']], ['weightUnit', ['weight unit', 'unit']], ['reps', ['reps', 'repetitions']], @@ -71,11 +71,11 @@ const COLUMNS = [ // when it is there rather than dropping the column on the floor. ['rpe', ['rpe', 'rpe rating']], ['rir', ['rir', 'reps in reserve']], - ['distanceKm', ['distance km', 'distance (km)']], + ['distanceKm', ['distance km']], ['distance', ['distance']], ['distanceUnit', ['distance unit']], - ['seconds', ['seconds', 'duration seconds']], - ['time', ['time', 'duration', 'set duration (sec)']], + ['seconds', ['seconds', 'duration seconds', 'set duration sec']], + ['time', ['time', 'duration']], ['setType', ['set type']], ['note', ['comment', 'comments', 'notes', 'note', 'workout notes']], ] diff --git a/frontend/src/lib/import-csv.test.js b/frontend/src/lib/import-csv.test.js index 346c715..6f392f6 100644 --- a/frontend/src/lib/import-csv.test.js +++ b/frontend/src/lib/import-csv.test.js @@ -24,3 +24,29 @@ describe('CSV warm-up provenance', () => { expect(entry.topW).toBe(85) }) }) + +// gravl writes its units in parentheses ("Weight (kg)", "Set Duration (sec)"). Header text is +// normalised before it is matched, so the alias table has to hold the normalised form — an alias +// written with the parentheses can never match. Sample rows are from the gravl export in !21. +const GRAVL = [ + 'Date,Start Date,Workout,Source,Workout Duration (min),Energy,Exercise,Superset,Set,Set Type,Reps,Weight (kg),Distance (km),Set Duration (sec),Incline,Steps,Effort,Workout Notes', + '2026/01/01,1:11 PM,Push Day,,11,11,Chin Up,No,1,Normal,11,11,0,,,,Ideal,felt strong', + '2026/01/22,2:22 PM,External Something,APP,21,22,Walking,No,0,Normal,0,0,0,22,,,,', +].join('\n') + +describe('gravl export', () => { + it('reads slash dates, parenthesised weight and per-set duration', () => { + const parsed = parseWorkoutCSV(GRAVL, { unit: 'kg' }) + + expect(parsed.skipped).toBe(0) + expect(parsed.from).toBe('2026-01-01') + expect(parsed.to).toBe('2026-01-22') + + const [lift, cardio] = parsed.workouts + expect(lift.name).toBe('Push Day') + expect(lift.entries[0].sets).toEqual([{ w: 11, r: 11, done: true }]) + + // "Set Duration (sec)" is seconds, not minutes: read as `time` it would land as 22 minutes. + expect(cardio.entries[0].sets).toEqual([{ min: 0.4, speed: 0, done: true }]) + }) +})