Import: the stored volume leaves warm-up sets out, like a workout finished in the app (QA C14)

Both importers summed every set into w.vol, while a workout finished in the app
writes workoutVolume(w), which skips warm-ups — the config sheet promises they
stay out of volume, records and progression. The inflated number is stored with
the workout and read straight back by History, the heatmap and the month totals.
Filter with isWarmupRow, as the topW line right above it already does.
This commit is contained in:
Duarte Santos committed 2026-09-19 17:08:51 +02:00
1 parent f9715d76d3
commit e20201a870
4 files changed
+29 -2

No files matched your search

+3 -1
View File
@@ -498,7 +498,9 @@ export function parseWorkoutCSV(text, { unit = 'kg' } = {}) {
id: 'iw' + uid(), d, start, end: end > start ? end : start,
routineId: null, name: day.name || 'Imported', entries, prs: [],
}
w.vol = entries.reduce((a, e) => a + e.sets.reduce((b, s) => b + (s.w || 0) * (s.r || 0), 0), 0)
// Work sets only, like `workoutVolume` for a workout finished in the app: warm-ups are
// promised to stay out of the volume, and this number is stored with the workout for good.
w.vol = entries.reduce((a, e) => a + e.sets.reduce((b, s) => b + (isWarmupRow(s) ? 0 : (s.w || 0) * (s.r || 0)), 0), 0)
return w
})
+21
View File
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { parseWorkoutCSV } from './import-csv.js'
import { workoutVolume } from './history.js'
const CSV = [
'Date,Exercise,Weight,Reps,Set Type',
@@ -50,3 +51,23 @@ describe('gravl export', () => {
expect(cardio.entries[0].sets).toEqual([{ min: 0.4, speed: 0, done: true }])
})
})
// A finished workout stores `vol = workoutVolume(w)`, which leaves warm-ups out; an imported one
// wrote the sum of every set, so the History row, the heatmap and the month totals read a number
// the app's own arithmetic never produces — and it stays wrong forever (QA C14).
const HEVY_WARMUPS = [
'title,start_time,end_time,description,exercise_title,superset_id,exercise_notes,set_index,set_type,weight_kg,reps,distance_km,duration_seconds,rpe',
'"QA","03 Mar 2025, 18:00","03 Mar 2025, 19:00","","Bench Press (Barbell)",,"",0,warmup,20,10,,,',
'"QA","03 Mar 2025, 18:00","03 Mar 2025, 19:00","","Bench Press (Barbell)",,"",1,normal,60,5,,,',
'"QA","03 Mar 2025, 18:00","03 Mar 2025, 19:00","","Bench Press (Barbell)",,"",2,normal,60,5,,,',
'"QA","03 Mar 2025, 18:00","03 Mar 2025, 19:00","","Squat (Barbell)",,"",0,warmup,40,5,,,',
'"QA","03 Mar 2025, 18:00","03 Mar 2025, 19:00","","Squat (Barbell)",,"",1,normal,100,5,,,',
].join('\n')
describe('imported volume', () => {
it('stores the work-set volume, the same number workoutVolume computes', () => {
const [w] = parseWorkoutCSV(HEVY_WARMUPS, { unit: 'kg' }).workouts
expect(w.vol).toBe(1100)
expect(w.vol).toBe(workoutVolume(w))
})
})
+2 -1
View File
@@ -267,7 +267,8 @@ export function parseHevyWorkouts(workouts, templates, { unit = 'kg' } = {}) {
id: 'iw' + uid(), d, start: startMs, end: endMs > startMs ? endMs : startMs,
routineId: null, name: day.name || 'Imported', entries, prs: [],
}
workout.vol = entries.reduce((a, e) => a + e.sets.reduce((b, s) => b + (s.w || 0) * (s.r || 0), 0), 0)
// Work sets only, the number `workoutVolume` gives a workout finished in the app; it is stored for good.
workout.vol = entries.reduce((a, e) => a + e.sets.reduce((b, s) => b + (isWarmupRow(s) ? 0 : (s.w || 0) * (s.r || 0)), 0), 0)
return workout
})
+3
View File
@@ -124,6 +124,9 @@ describe('parseHevyWorkouts', () => {
expect(pulldown.topW).toBe(52)
expect(parsed.warmups).toBe(1)
expect(parsed.rpeSets).toBe(1)
// The stored volume leaves the warm-up out, like a workout finished in the app (QA C14):
// 52×15 + 52×10 + 20×12 = 1,540, not 1,915.
expect(parsed.workouts[0].vol).toBe(1540)
const custom = entries.find(e => String(e.id).startsWith('im'))
expect(custom).toBeTruthy()