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: each file says what it holds, weigh-ins and measurements under the body file (#647)
Duarte Santosaba1f8f0786a
diff --git a/frontend/src/components/CsvExportSheet.jsx b/frontend/src/components/CsvExportSheet.jsxindex a5c52e5c4..093d5c48a 100644--- a/frontend/src/components/CsvExportSheet.jsx+++ b/frontend/src/components/CsvExportSheet.jsx@@ -54,12 +54,17 @@ export function CsvExportSheet({ close }) {<input type="date" className="timef" value={to} min={from} max={today} onChange={e => setTo(e.target.value)} /></Row></div>}<div className="small dim" style={{ margin: '10px 2px 14px' }} data-csv-summary>- {(range === 'all' ? t('All') : r.from === r.to ? fmtDate(r.from, true, true) : fmtDate(r.from, false, true) + ' – ' + fmtDate(r.to, false, true))- + ' · ' + tn('{0} workout', '{0} workouts', counts.workouts) + ' · ' + tn('{0} set', '{0} sets', counts.sets)}+ {range === 'all' ? t('All') : r.from === r.to ? fmtDate(r.from, true, true) : fmtDate(r.from, false, true) + ' – ' + fmtDate(r.to, false, true)}</div>+ {/* Each file says what it holds: sets don't go into the body file, weigh-ins don't go into the workouts one. */}<Button variant="primary" icon="share" onClick={() => save('workouts')}>{t('Workouts (CSV)')}</Button>- <div style={{ height: 8 }} />+ <div className="small dim" style={{ margin: '4px 2px 12px' }} data-csv-count="workouts">+ {tn('{0} workout', '{0} workouts', counts.workouts) + ' · ' + tn('{0} set', '{0} sets', counts.sets)}+ </div><Button icon="share" onClick={() => save('body')}>{t('Body weight & measurements (CSV)')}</Button>+ <div className="small dim" style={{ margin: '4px 2px 0' }} data-csv-count="body">+ {tn('{0} weigh-in', '{0} weigh-ins', counts.weighIns) + ' · ' + tn('{0} measurement', '{0} measurements', counts.measurements)}+ </div></>}diff --git a/frontend/src/components/CsvExportSheet.test.jsx b/frontend/src/components/CsvExportSheet.test.jsxindex ef9aa5928..300b626d1 100644--- a/frontend/src/components/CsvExportSheet.test.jsx+++ b/frontend/src/components/CsvExportSheet.test.jsx@@ -42,15 +42,25 @@ afterEach(() => { act(() => root.unmount()); host.remove() })const button = text => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text)const summary = () => host.querySelector('[data-csv-summary]').textContent+const count = kind => host.querySelector(`[data-csv-count="${kind}"]`).textContentconst flush = () => act(async () => { await Promise.resolve() })describe('CsvExportSheet', () => {it('starts on everything and counts workouts and sets', () => {expect(button('All').getAttribute('aria-pressed')).toBe('true')- expect(summary()).toContain('2 workouts')- expect(summary()).toContain('4 sets')+ expect(summary()).toBe('All')+ expect(count('workouts')).toBe('2 workouts · 4 sets')act(() => button('4 weeks').click())- expect(summary()).toContain('1 workout')+ expect(count('workouts')).toContain('1 workout')+ })++ it('counts weigh-ins and measurements under the body file, not sets', () => {+ mocks.S = { ...mocks.S, bodyweight: [{ d: iso(1), w: 80 }, { d: iso(300), w: 82 }], measurements: [{ d: iso(3), waist: 80 }] }+ act(() => root.render(<CsvExportSheet close={close} />))+ expect(count('body')).toBe('2 weigh-ins · 1 measurement')+ expect(count('body')).not.toContain('set')+ act(() => button('4 weeks').click())+ expect(count('body')).toBe('1 weigh-in · 1 measurement')})it('shares the workouts file on the phone, named by the day', async () => {diff --git a/frontend/src/lib/export-csv.js b/frontend/src/lib/export-csv.jsindex 84d77e37b..2a568dfae 100644--- a/frontend/src/lib/export-csv.js+++ b/frontend/src/lib/export-csv.js@@ -132,8 +132,14 @@ export function bodyCSV(S, { from = null, to = null } = {}) {return csvText(header, rows)}-/** How many rows each file would have, for the sheet's summary line. */-export const csvCounts = (S, range) => ({- workouts: workoutsIn(S, range?.from, range?.to).length,- sets: workoutRows(S, range).length,-})+/** What each file would hold, for the line under its button: workouts and sets, weigh-ins and measurements. */+export function csvCounts(S, range) {+ const from = range?.from, to = range?.to+ const inside = d => d && (!from || d >= from) && (!to || d <= to)+ return {+ workouts: workoutsIn(S, from, to).length,+ sets: workoutRows(S, range).length,+ weighIns: (S.bodyweight || []).filter(b => inside(b?.d) && b.w > 0).length,+ measurements: (S.measurements || []).filter(m => inside(m?.d)).length,+ }+}