Blood test spreadsheets: ferritin, Hb, iron in the health section

- sources/labs.py reads .xlsx/.csv sheets with a Date column; columns are
  recognised by header (ferritin, Hb, serum iron, transferrin saturation),
  with the lab's reference range and the user's Min/Max target. Formula
  cells are skipped.
- Importing a sheet from disk remembers it in settings "lab_files"; every
  dashboard build reads it again. Editable in the app's settings.
- Dashboard: ferritin chart (log scale, main lab as a line, a second lab
  as points, target range dashed), results table and a finding.
- openpyxl added as a dependency and to the installer bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Riaan Doorduin
2026-11-15 13:20:25 +02:00
parent c6a1eb199d
commit 0d3da5f2df
11 changed files with 224 additions and 16 deletions

View File

@@ -57,11 +57,11 @@ One folder per person, chosen by the user:
| Path | Contents |
|---|---|
| `settings.json` | name, birth year, sex, home time zone, optional `copy_dashboard_to` paths |
| `settings.json` | name, birth year, sex, home time zone, optional `copy_dashboard_to` paths and `lab_files` (blood test spreadsheets) |
| `myGarmin.db` | the SQLite database (below) |
| `originals/garmin_fit/` | activity FIT files, named by local start time (`2024-05-01-07-30-00.fit`) |
| `originals/garmin_health/`, `garmin_courses/` | health FITs (monitoring, sleep, HRV…) and courses, kept for later use |
| `originals/tcx/`, `alpinequest/`, `gpx/`, `strava/` | the other sources, under their original names |
| `originals/tcx/`, `alpinequest/`, `gpx/`, `strava/`, `labs/` | the other sources, under their original names |
| `races.csv` | optional, typed by the user: `date,event,time[,km,age_grade,position,pb]` |
| `dashboard.html`, `all_activities.csv` | built outputs |
| `exports/tracks_gpx.zip`, `exports/tracks_trk.zip` | built outputs, one track per outing, in year folders |
@@ -137,7 +137,8 @@ erDiagram
training load and status, race predictions, endurance and hill score). New values are merged in, so a later source can
complete or correct a day.
- **health_series:** values that are not daily: `vo2` (per sport), `fage` (fitness age), `bp` (blood pressure, with any
haemoglobin value found in the note), `lthr` (lactate-threshold heart rate).
haemoglobin value found in the note), `lthr` (lactate-threshold heart rate), `lab` (blood test results: ferritin,
haemoglobin, serum iron, transferrin saturation, each with its lab, reference range and the user's target range).
## Getting data in
@@ -213,6 +214,14 @@ Uses the unofficial `python-garminconnect` library (read-only). Garmin has no pe
- **Health:** every day from the last stored day minus 3 days up to today. The last days are re-fetched because Garmin completes them later. The fields are the same as from the export, so both sources fill the same records.
- **Pacing:** calls are spaced 0.3 s apart. A failing call is logged and skipped.
### Blood test spreadsheets (`sources/labs.py`)
For results the user keeps in Excel (.xlsx) or a .csv, e.g. ferritin during treatment for iron overload.
- **Layout:** a header row with a `Date` column. Other columns are recognised by their header: ferritin (or a µg/L or ng/mL unit), haemoglobin/Hb, serum iron, transferrin saturation. A range in brackets, such as `(30-400)`, is the lab's reference range; what is left of the header is the lab's name. Columns headed `Min` and `Max` are the user's own target range.
- **Only typed-in numbers count.** Cells with a formula (estimates, differences) are skipped, so a sheet can keep its own calculations.
- **Two lab methods** in two columns stay separate series: the dashboard draws the one with most results as a line and the other as points.
- **Kept in sync:** importing a sheet from disk adds its path to `lab_files` in the settings. Every dashboard build reads those sheets again and replaces their earlier results, so edits and deleted rows show. A sheet that is missing (moved, drive offline) keeps its last results; change the path in the app's settings.
- A sheet found inside a folder or zip is imported once and kept under `originals/labs/`.
## Time zones (`timeutil.py`)
Every activity keeps its UTC start and the offset to local time. The offset comes from:
1. the file itself (FIT `local_timestamp`, rounded to 15 min); else
@@ -251,6 +260,8 @@ flowchart LR
5. `all_activities.csv` lists **every** row, including duplicates and flagged ones, with the reason, for checking in Excel.
6. The dashboard is also copied to any `copy_dashboard_to` paths in the settings.
Before step 1, the blood test sheets in `lab_files` are read again.
## Exports (`export.py`)
- **Which tracks:** the same as on the dashboard, but only with GPS. One file per outing, so duplicate recordings never appear twice.
- **Full resolution:** points are re-read from each original file (FIT, TCX, GPX, AlpineQuest or Strava).