From c7d2e32d7d4d1035603525ecc3222edcdc7dfb3b Mon Sep 17 00:00:00 2001 From: Mac DeCourcy Date: Tue, 7 Oct 2025 15:24:29 -0700 Subject: [PATCH] Add MeasuredDate column to all CSV files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CHANGES: - Added MeasuredDate as first column in regional.csv - Added MeasuredDate as first column in muscle_balance.csv - Updated README to document new column structure BENEFITS: ✅ Track regional changes over time (e.g., Arms fat % across scans) ✅ Easy time-series analysis with pandas/Excel ✅ Filter by date range for progress tracking ✅ Consistent date column across all 3 CSV files ✅ Enables queries like: 'Show me trunk fat % over last 6 months' EXAMPLE USAGE: import pandas as pd regional = pd.read_csv('regional.csv') arms = regional[regional['Region'] == 'Arms'] # Now you can track Arms progress over time! Each scan now adds: - 1 row to overall.csv - 6 rows to regional.csv (one per region) - 6 rows to muscle_balance.csv (one per limb comparison) --- README.md | 10 +++++++--- dexa_extract.py | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a9813b7..667774f 100644 --- a/README.md +++ b/README.md @@ -126,9 +126,10 @@ Time-series data with one row per scan. Includes all primary metrics and derived - `RMR_cal_per_day` - Resting metabolic rate ### 2. `regional.csv` -Regional body composition breakdown (Arms, Legs, Trunk, Android, Gynoid, Total). +Regional body composition breakdown (Arms, Legs, Trunk, Android, Gynoid, Total). Each scan adds 6 rows (one per region). **Columns:** +- `MeasuredDate` - Date of scan (YYYY-MM-DD) - `Region` - Body region name - `FatPercent` - Fat percentage in this region - `LeanPercent` - Lean tissue percentage in this region @@ -138,9 +139,12 @@ Regional body composition breakdown (Arms, Legs, Trunk, Android, Gynoid, Total). - `BMC_lb` - Bone mineral content in the region ### 3. `muscle_balance.csv` -Left/right limb comparison for tracking muscle symmetry. +Left/right limb comparison for tracking muscle symmetry. Each scan adds 6 rows (one per region). -**Regions:** Arms Total, Right Arm, Left Arm, Legs Total, Right Leg, Left Leg +**Columns:** +- `MeasuredDate` - Date of scan (YYYY-MM-DD) +- `Region` - Arms Total, Right Arm, Left Arm, Legs Total, Right Leg, Left Leg +- `FatPercent`, `TotalMass_lb`, `FatMass_lb`, `LeanMass_lb`, `BMC_lb` ### 4. `overall.json` Structured JSON format containing all extracted data in a hierarchical format. diff --git a/dexa_extract.py b/dexa_extract.py index d04d4b0..1a8d664 100644 --- a/dexa_extract.py +++ b/dexa_extract.py @@ -578,12 +578,13 @@ def process_single_pdf(pdf_path, height_in, weight_lb, outdir, batch_mode=False) write_or_append_csv(os.path.join(outdir, "overall.csv"), overall_row, overall_cols) # Regional table - regional_cols = ["Region","FatPercent","LeanPercent","TotalMass_lb","FatTissue_lb","LeanTissue_lb","BMC_lb"] + regional_cols = ["MeasuredDate","Region","FatPercent","LeanPercent","TotalMass_lb","FatTissue_lb","LeanTissue_lb","BMC_lb"] reg_rows = [] for name, r in d.get("regional", {}).items(): # Calculate lean percentage (lean tissue only, not including BMC - matches BodySpec report) lean_pct = round(100 * r["lean_tissue_lb"] / r["total_mass_lb"], 1) if r["total_mass_lb"] > 0 else None reg_rows.append({ + "MeasuredDate": measured_date, "Region": name, "FatPercent": r["fat_percent"], "LeanPercent": lean_pct, @@ -600,10 +601,11 @@ def process_single_pdf(pdf_path, height_in, weight_lb, outdir, batch_mode=False) df_regional.to_csv(regional_path, index=False) # Muscle balance - mb_cols = ["Region","FatPercent","TotalMass_lb","FatMass_lb","LeanMass_lb","BMC_lb"] + mb_cols = ["MeasuredDate","Region","FatPercent","TotalMass_lb","FatMass_lb","LeanMass_lb","BMC_lb"] mb_rows = [] for name, r in d.get("muscle_balance", {}).items(): mb_rows.append({ + "MeasuredDate": measured_date, "Region": name, "FatPercent": r["fat_percent"], "TotalMass_lb": r["total_mass_lb"],