Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
CSV export: distance_km rounded to ten metres, more only where the re-import needs it (#647)
Duarte Santosd0a2d4102d16
diff --git a/frontend/src/lib/export-csv.js b/frontend/src/lib/export-csv.jsindex 2a568dfae..54f4dd952 100644--- a/frontend/src/lib/export-csv.js+++ b/frontend/src/lib/export-csv.js@@ -47,6 +47,23 @@ const stamp = ms => {return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())} ${p2(d.getHours())}:${p2(d.getMinutes())}`}+/**+ * A cardio set's distance, as short as it can be: speed × minutes is 4.708333 km for 25 minutes at+ * 11.3, which nobody wants in a spreadsheet. Two decimals (ten metres) mostly do; a short set+ * gets more, as many as our importer needs to read the same speed back (it rounds to 0.01 km/h).+ */+function distanceKm(s) {+ const min = Number(s.min) || 0, speed = Number(s.speed) || 0+ const km = speed * min / 60+ if (!(km > 0)) return '0'+ const back = x => Math.round(x / (min / 60) * 100)+ for (let d = 2; d < 6; d++) {+ const r = Math.round(km * 10 ** d) / 10 ** d+ if (back(r) === Math.round(speed * 100)) return String(r)+ }+ return n(km)+}+/** Workouts whose day falls inside [from, to] (ISO days, either may be null for open), oldest first. */const workoutsIn = (S, from, to) => (S.workouts || []).filter(w => { const d = workoutDay(w); return d && (!from || d >= from) && (!to || d <= to) })@@ -85,8 +102,7 @@ export function workoutRows(S, { from = null, to = null } = {}) {no++const type = isWarmupRow(s) ? 'warmup' : isFailureSet(s) ? 'failure' : 'normal'if (cardio(s)) {- const km = (Number(s.speed) || 0) * (Number(s.min) || 0) / 60- push([no, type, '', '', unit, '', '', '', n(km) || '0', n(Math.round((Number(s.min) || 0) * 60)), s.incline != null ? n(s.incline) : ''])+ push([no, type, '', '', unit, '', '', '', distanceKm(s), n(Math.round((Number(s.min) || 0) * 60)), s.incline != null ? n(s.incline) : ''])continue}const effort = x => [x.rpe != null ? n(x.rpe) : '', x.rir != null ? n(x.rir) : '']diff --git a/frontend/src/lib/export-csv.test.js b/frontend/src/lib/export-csv.test.jsindex 7fc27c4fc..2103b0028 100644--- a/frontend/src/lib/export-csv.test.js+++ b/frontend/src/lib/export-csv.test.js@@ -108,6 +108,16 @@ describe('the workout CSV', () => {expect(hold[col('reps')]).toBe('')})+ it('rounds the distance instead of writing float noise, but never so far the speed changes', () => {+ const km = sets => parseCSV(workoutsCSV({ unit: 'kg', workouts: [{ id: 'c', d: '2026-03-04', start: 1, entries: [{ id: '3666', sets }] }] }))+ .slice(1).map(r => r[col('distance_km')])+ // 25 min at 11.3 km/h is 4.708333 km; a one-minute set at 9.4 needs four to read 9.4 again.+ expect(km([{ min: 25, speed: 11.3, done: true }, { min: 1, speed: 9.4, done: true }, { min: 30, speed: 10, done: true }]))+ .toEqual(['4.71', '0.1567', '5'])+ const back = parseWorkoutCSV(workoutsCSV({ unit: 'kg', workouts: [{ id: 'c', d: '2026-03-04', start: 1, entries: [{ id: '3666', sets: [{ min: 25, speed: 11.3, done: true }, { min: 1, speed: 9.4, done: true }, { min: 0.5, speed: 12.5, done: true }] }] }] }), { unit: 'kg' })+ expect(back.workouts[0].entries[0].sets.map(s => s.speed)).toEqual([11.3, 9.4, 12.5])+ })+it('survives commas, quotes and line breaks in names and notes', () => {const grip = body.find(r => r[col('exercise_id')] === 'cx1')expect(grip[col('exercise')]).toBe('Grip Trainer, "Heavy"')