Skip to content

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.

fix(import): keep a converted weight to the hundredth, and Hevy's note line breaks

lodepav668fb5785eb5
diff --git a/frontend/src/lib/import-bodyweight.test.js b/frontend/src/lib/import-bodyweight.test.js
index ab35076e8..50ddfa169 100644
--- a/frontend/src/lib/import-bodyweight.test.js
+++ b/frontend/src/lib/import-bodyweight.test.js
@@ -5,8 +5,8 @@ const record = (day, value, unit) => `<Record type="HKQuantityTypeIdentifierBody
describe('Apple Health body-weight units', () => {
it.each([
- ['kg', [80, 81.6]],
- ['lb', [176.4, 180]],
+ ['kg', [80, 81.65]],
+ ['lb', [176.37, 180]],
])('converts each record into %s independently', (unit, expected) => {
const parsed = parseBodyweight(record('01', 80, 'kg') + record('02', 180, 'lb'), { unit })
expect(parsed.bodyweight.map(b => b.w)).toEqual(expected)
@@ -20,8 +20,8 @@ describe('Apple Health body-weight units', () => {
})
it('preserves conversion for single-unit XML and CSV exports', () => {
- expect(parseBodyweight(record('01', 180, 'lb')).bodyweight[0].w).toBe(81.6)
- expect(parseBodyweight('Date,Weight (lbs)\n2026-09-01,180').bodyweight[0].w).toBe(81.6)
+ expect(parseBodyweight(record('01', 180, 'lb')).bodyweight[0].w).toBe(81.65)
+ expect(parseBodyweight('Date,Weight (lbs)\n2026-09-01,180').bodyweight[0].w).toBe(81.65)
expect(parseBodyweight(record('01', 80, 'kg')).converted).toBe(false)
})
})
diff --git a/frontend/src/lib/import-csv.hostile.test.js b/frontend/src/lib/import-csv.hostile.test.js
index 2e424f680..8236a1baa 100644
--- a/frontend/src/lib/import-csv.hostile.test.js
+++ b/frontend/src/lib/import-csv.hostile.test.js
@@ -51,7 +51,7 @@ describe('Apple Health records that are not a weight', () => {
it('a record without a unit follows the profile; lb is converted', () => {
const p = parseImport(health({ value: '176.4', unit: 'lb', date: '2024-03-07' }), kg)
expect(p.converted).toBe(true)
- expect(p.bodyweight[0].w).toBe(80)
+ expect(p.bodyweight[0].w).toBe(80.01)
})
})
@@ -93,7 +93,7 @@ describe('numbers that are not numbers', () => {
expect(p.converted).toBe(false)
const mixed = parseImport(csv(row({ w: 50, u: 'kg', r: 5 }), row({ date: '2024-03-08', w: 100, u: 'lbs', r: 5 })), kg)
expect(mixed.mixedUnits).toBe(true)
- expect(mixed.workouts[1].entries[0].sets[0].w).toBe(45.4)
+ expect(mixed.workouts[1].entries[0].sets[0].w).toBe(45.36)
})
})
diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js
index 72b8d9b53..2a5c88aad 100644
--- a/frontend/src/lib/import-csv.js
+++ b/frontend/src/lib/import-csv.js
@@ -363,6 +363,12 @@ const effortNum = (raw, zeroMeansRated) => {
return Math.min(10, Math.round(n * 100) / 100)
}
const LB_TO_KG = 0.45359237
+// A converted weight is kept to the hundredth, which Weight decimals can show (#139): 45 lb is
+// 20.41 kg, and a tenth would make it 20.4, which reads back as 44.97 lb. A weight typed into the
+// app is never rounded at all, so an import shouldn't be the one place that drops precision.
+export const roundWeight = w => Math.round(w * 100) / 100
+// Hevy's CSV writes a line break inside a note as the two characters `\n`.
+const hevyNote = s => s.replace(/\\r\\n|\\n/g, '\n')
// Past these a cell is broken, not a record (the heaviest lifts ever logged stay well under).
const MAX_KG = 2000, MAX_REPS = 1000, MAX_KM = 1000, MAX_BODY_KG = 650
const p2 = n => String(n).padStart(2, '0')
@@ -552,7 +558,7 @@ export function parseWorkoutCSV(text, { unit = 'kg', customEx = [] } = {}) {
const reps = Math.round(num(cell(r, 'reps')))
const secs = num(cell(r, 'seconds'))
- const setNote = cell(r, 'note')
+ const setNote = source === 'Hevy' ? hevyNote(cell(r, 'note')) : cell(r, 'note')
// Ours keeps cardio minutes to hundredths, the way the app stores them.
const mins = secs > 0 ? Math.round(secs / 60 * (own ? 100 : 10)) / (own ? 100 : 10) : toMinutes(cell(r, 'time'))
const km = map.distanceKm !== undefined && cell(r, 'distanceKm')
@@ -652,7 +658,7 @@ export function parseWorkoutCSV(text, { unit = 'kg', customEx = [] } = {}) {
byDate.set(sessionKey, day)
}
if (!day.name) day.name = cell(r, 'workoutName') || ''
- if (!day.note) day.note = cell(r, 'workoutNote')
+ if (!day.note) day.note = source === 'Hevy' ? hevyNote(cell(r, 'workoutNote')) : cell(r, 'workoutNote')
// The end is kept as time since the start day's midnight, so a session that runs past
// midnight ends on the next day's clock plus 24 h rather than before it began.
if (map.endTime !== undefined) { const e = parseWhen(cell(r, 'endTime')); if (e && e.t != null) day.end = e.t + daysBetween(when.d, e.d) * 86400000 }
@@ -709,8 +715,8 @@ export function parseWorkoutCSV(text, { unit = 'kg', customEx = [] } = {}) {
// "185 lb" into 185 kg.
const fileUnit = sawLb && !sawKg ? 'lb' : sawKg && !sawLb ? 'kg' : ''
const mixedUnits = sawLb && sawKg
- const toKg = x => Math.round(x * LB_TO_KG * 10) / 10
- const toLb = x => Math.round(x / LB_TO_KG * 10) / 10
+ const toKg = x => roundWeight(x * LB_TO_KG)
+ const toLb = x => roundWeight(x / LB_TO_KG)
// A row without its own unit follows the file's, and a file that says nothing is taken
// to already be in the profile's unit.
const convRow = s => {
@@ -854,7 +860,7 @@ function finishBodyweight(out, unit, source, fileUnit = '') {
const w = sourceUnit && sourceUnit !== unit
? (sourceUnit === 'lb' ? b.w * LB_TO_KG : b.w / LB_TO_KG)
: b.w
- return Math.round(w * 10) / 10
+ return roundWeight(w)
}
const dates = [...out.keys()].sort()
return {
diff --git a/frontend/src/lib/import-csv.test.js b/frontend/src/lib/import-csv.test.js
index 613862830..b0af7fafc 100644
--- a/frontend/src/lib/import-csv.test.js
+++ b/frontend/src/lib/import-csv.test.js
@@ -81,6 +81,31 @@ const HEVY_HEAD = HEVY_WARMUPS.split('\n')[0]
const EXPORT_A = [HEVY_HEAD, hevyDay('Day A', '02', 'Zorb Roller', 49, 8), hevyDay('Day A', '02', 'Bench Press (Barbell)', 80, 5)].join('\n')
const EXPORT_B = [HEVY_HEAD, hevyDay('Day A', '02', 'Zorb Roller', 49, 8), hevyDay('Day B', '09', 'Zorb Roller', 30, 15)].join('\n')
+// Hevy's CSV writes a line break inside a note as the two characters `\n`, and a weight read
+// from another unit kept only a tenth, so 45 lb came in as 20.4 kg (44.97 lb).
+describe('Hevy notes and converted weights', () => {
+ const note = (desc, exNote) =>
+ `"Legs","03 Mar 2025, 18:00","03 Mar 2025, 19:00","${desc}","Squat (Barbell)",,"${exNote}",0,normal,100,5,,,`
+
+ it('turns Hevy\'s escaped line breaks back into line breaks', () => {
+ const [w] = parseWorkoutCSV([HEVY_HEAD, note('Felt slow.\\nKnee ok', 'Belt on\\r\\nLast set hard')].join('\n'), { unit: 'kg' }).workouts
+ expect(w.note).toBe('Felt slow.\nKnee ok')
+ expect(w.entries[0].note).toBe('Belt on\nLast set hard')
+ })
+
+ it('leaves another app\'s notes as they are', () => {
+ const [w] = parseWorkoutCSV('Date,Exercise,Weight,Reps,Notes\n2025-03-03,Squat,100,5,a\\nb', { unit: 'kg' }).workouts
+ expect(w.entries[0].note).toBe('a\\nb')
+ })
+
+ it('keeps a converted weight to the hundredth', () => {
+ const p = parseWorkoutCSV('Date,Exercise,Weight,Weight Unit,Reps\n2025-03-03,Squat,45,lbs,5', { unit: 'kg' })
+ expect(p.workouts[0].entries[0].sets[0].w).toBe(20.41)
+ const back = parseWorkoutCSV('Date,Exercise,Weight,Weight Unit,Reps\n2025-03-03,Squat,20.41,kg,5', { unit: 'lb' })
+ expect(back.workouts[0].entries[0].sets[0].w).toBe(45)
+ })
+})
+
describe('mergeImport and custom exercises', () => {
const fresh = () => ({ workouts: [], customEx: [], exWeights: {}, bodyweight: [] })
diff --git a/frontend/src/lib/import-effort.test.js b/frontend/src/lib/import-effort.test.js
index f7dafb393..1b893a8ee 100644
--- a/frontend/src/lib/import-effort.test.js
+++ b/frontend/src/lib/import-effort.test.js
@@ -104,7 +104,7 @@ describe('importing effort from another app', () => {
'2026-01-12,Bench Press,135,lbs,10,8',
].join('\n'), { unit: 'kg' })
const s = setsOf(p)[0]
- expect(s.w).toBe(61.2)
+ expect(s.w).toBe(61.23)
expect(s.rpe).toBe(8)
expect('u' in s).toBe(false) // the row's unit marker never reaches the set
})
diff --git a/frontend/src/lib/import-hevy.js b/frontend/src/lib/import-hevy.js
index a30799a0b..8e5a05251 100644
--- a/frontend/src/lib/import-hevy.js
+++ b/frontend/src/lib/import-hevy.js
@@ -9,7 +9,7 @@ import { EXIDX, canonicalExId } from './exercises.js'
import { uid } from './format.js'
import { isWarmupRow } from './workout-model.js'
import { HEVY_ID_MAP, HEVY_TITLE_MAP } from './hevy-id-map.js'
-import { daysBetween, importId, priorCustom } from './import-csv.js'
+import { daysBetween, importId, priorCustom, roundWeight } from './import-csv.js'
export { HEVY_ID_MAP, HEVY_TITLE_MAP }
export const HEVY_API = 'https://api.hevyapp.com'
@@ -225,8 +225,8 @@ export function hevySummaryCounts(w, r, { workouts = true, routines = true } = {
const toProfileWeight = (wKg, unit) => {
if (wKg == null || !isFinite(wKg)) return 0
- if (unit === 'lb') return Math.round(wKg / LB_TO_KG * 10) / 10
- return Math.round(wKg * 10) / 10
+ if (unit === 'lb') return roundWeight(wKg / LB_TO_KG)
+ return roundWeight(wKg)
}
/**
@@ -465,8 +465,7 @@ export function parseHevyBodyweight(measurements, { unit = 'kg' } = {}) {
if (!/^\d{4}-\d{2}-\d{2}$/.test(d)) continue
let w = Number(m.weight_kg)
if (!isFinite(w) || w <= 0) continue
- if (unit === 'lb') w = Math.round(w / LB_TO_KG * 10) / 10
- else w = Math.round(w * 10) / 10
+ w = roundWeight(unit === 'lb' ? w / LB_TO_KG : w)
const t = m.created_at ? new Date(m.created_at).getTime() : new Date(d + 'T12:00:00').getTime()
out.set(d, { d, w, t: isFinite(t) ? t : new Date(d + 'T12:00:00').getTime() })
}
diff --git a/frontend/src/lib/import-hevy.test.js b/frontend/src/lib/import-hevy.test.js
index 61273cf01..afd6d4fe8 100644
--- a/frontend/src/lib/import-hevy.test.js
+++ b/frontend/src/lib/import-hevy.test.js
@@ -135,6 +135,12 @@ describe('parseHevyWorkouts', () => {
expect(parsed.unmatchedNames).toContain('My Invented Landmine Twist')
})
+ it('keeps a weight to the hundredth: 20.41 kg is 45 lb', () => {
+ const w = { ...WORKOUT, exercises: [{ ...WORKOUT.exercises[1], sets: [{ ...WORKOUT.exercises[1].sets[1], weight_kg: 20.41 }] }] }
+ expect(parseHevyWorkouts([w], TEMPLATES, { unit: 'kg' }).workouts[0].entries[0].sets[0].w).toBe(20.41)
+ expect(parseHevyWorkouts([w], TEMPLATES, { unit: 'lb' }).workouts[0].entries[0].sets[0].w).toBe(45)
+ })
+
it('converts kg weights into a lb profile', () => {
const parsed = parseHevyWorkouts([WORKOUT], TEMPLATES, { unit: 'lb' })
const pulldown = parsed.workouts[0].entries.find(e => e.id === '6392')
@@ -170,6 +176,12 @@ describe('parseHevyBodyweight', () => {
], { unit: 'kg' })
expect(parsed.bodyweight).toEqual([{ d: '2026-08-23', w: 83.2, t: expect.any(Number) }])
})
+
+ it('keeps the hundredth, in either unit', () => {
+ const m = [{ id: 1, date: '2026-08-23', weight_kg: 83.25, created_at: '2026-08-23T18:22:48.070Z' }]
+ expect(parseHevyBodyweight(m, { unit: 'kg' }).bodyweight[0].w).toBe(83.25)
+ expect(parseHevyBodyweight(m, { unit: 'lb' }).bodyweight[0].w).toBe(183.53)
+ })
})
describe('mergeImport with Hevy payloads', () => {