Glucose Data Analysis Workflow

Executive Summary

This document describes the complete workflow for processing continuous glucose monitoring (CGM) data from LibreView exports through a series of automated Python scripts to generate comprehensive analysis reports. The system consists of five main processing stages (B1 through E1) plus automation tools.

Key Features:

  • Automated pipeline from raw CSV to professional reports
  • Standardized folder structure (B-Data-Analyzer)
  • Multiple analysis types: time series, AGP, subtypes
  • Batch processing capability
  • HTML, PDF, and QMD report generation

System Architecture

Folder Structure

The entire system follows a standardized B-Data-Analyzer folder structure:

Top Folder/
└── B-Data-Analyzer/
    β”œβ”€β”€ A-Data/                                    # Raw data storage
    β”‚   └── {name}_glucose_{mm-dd-yyyy}/           # CSV-named folder
    β”‚       β”œβ”€β”€ {name}_glucose_{mm-dd-yyyy}.csv    # Original LibreView CSV
    β”‚       β”œβ”€β”€ B1-Glucose-Data/                   # Daily CSV files
    β”‚       β”œβ”€β”€ B2-Yearly-Analysis/                # Yearly reports
    β”‚       β”œβ”€β”€ C1-Daily-CSV-to-Subtypes-Analysis/ # Subtype analysis
    β”‚       └── D1-Daily-CSV-to-AGP-Report/        # AGP reports
    β”‚
    β”œβ”€β”€ B-Engines/                                 # Processing scripts
    β”‚   β”œβ”€β”€ B1-COMPLETE-AUTO.py                    # Stage 1: CSV splitter
    β”‚   β”œβ”€β”€ B2-COMPLETE-AUTO.py                    # Stage 2: Yearly analysis
    β”‚   β”œβ”€β”€ C1-COMPLETE-AUTO.py                    # Stage 3: Subtype analysis
    β”‚   β”œβ”€β”€ D1-COMPLETE-AUTO.py                    # Stage 4: AGP analysis
    β”‚   β”œβ”€β”€ E1-COMPLETE-AUTO.py                    # Stage 5: QMD reports
    β”‚   β”œβ”€β”€ automate.xlsx                          # Automation config
    β”‚   β”œβ”€β”€ excel_automate.py                      # Automation helper
    β”‚   └── run_all.py                             # Batch processor
    β”‚
    └── R-Reports/                                 # Final output location
        └── {name}-Report-{yyyy-mm-dd--hh-mm}/     # Timestamped reports
            β”œβ”€β”€ Glucose_Analysis_Report_*.qmd
            β”œβ”€β”€ Glucose_Analysis_Report_*.html
            β”œβ”€β”€ Glucose_Analysis_Report_*.pdf
            └── index.html

Data Flow Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LibreView  β”‚
β”‚  Web Export β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚ Raw CSV Download
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Part A: User Action                      β”‚
β”‚  User downloads: {name}_glucose_{mm-dd-yyyy}.csv            β”‚
β”‚  Places in: B-Data-Analyzer/A-Data/                         β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Part B1: Daily CSV File Generator              β”‚
β”‚  Input:  {name}_glucose_{mm-dd-yyyy}.csv                    β”‚
β”‚  Output: B1-Glucose-Data/ (daily CSV files)                 β”‚
β”‚  Action: Splits raw data into individual daily files        β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚                β”‚                β”‚                   β”‚
       β–Ό                β–Ό                β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   B2:    β”‚   β”‚     C1:      β”‚  β”‚     D1:      β”‚  β”‚     E1:      β”‚
β”‚ Yearly   β”‚   β”‚   Subtype    β”‚  β”‚     AGP      β”‚  β”‚     QMD      β”‚
β”‚ Analysis β”‚   β”‚   Analysis   β”‚  β”‚   Reports    β”‚  β”‚   Reports    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                β”‚                β”‚                   β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   R-Reports/            β”‚
                    β”‚   Final Deliverables    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Processing Stages

Part A: Data Acquisition (User Manual Step)

Objective: Obtain raw glucose data from LibreView platform

Steps:

  1. Log into LibreView web portal
  2. Navigate to data export section
  3. Select date range for export
  4. Download CSV file
  5. Save to B-Data-Analyzer/A-Data/ folder
  6. Create folder named: {name}_glucose_{mm-dd-yyyy}
  7. Place CSV file inside this folder

Expected Output:

A-Data/
└── yahyanazer_glucose_1-26-2026/
    └── yahyanazer_glucose_1-26-2026.csv

File Format:

  • Name Pattern: {name}_glucose_{mm-dd-yyyy}.csv
  • Example: yahyanazer_glucose_1-26-2026.csv
  • Encoding: UTF-8
  • Structure: LibreView standard export format

Part B1: Daily CSV File Generator

Script: B1-COMPLETE-AUTO.py

Objective: Convert single LibreView CSV into individual daily CSV files

Process Flow:

  1. Read Source CSV
    • Extracts patient name from cell E1
    • Reads columns A through S
    • Identifies Historic Glucose and Scan Glucose columns
  2. Build Glucose Selected
    • Prioritizes Historic Glucose over Scan Glucose
    • Combines both sources into single column
    • Parses timestamps to datetime format
  3. Select Date Range
    • Prompts user for begin/end year-month
    • Or reads from automate.xlsx in automation mode
  4. Generate Daily Files
    • Creates one CSV file per day
    • Format: Data-YYYY-MM-DD.csv
    • Columns: timestamp, glucose_mg_dL
    • Timestamp format: YYYY-MM-DD HH:MM:SS
  5. Create Summary Report
    • Generates B1-Summary-Report.html
    • Lists all created files
    • Shows data preview

Input:

A-Data/yahyanazer_glucose_1-26-2026/
└── yahyanazer_glucose_1-26-2026.csv

Output:

A-Data/yahyanazer_glucose_1-26-2026/
└── B1-Glucose-Data/
    β”œβ”€β”€ Data-2022-01-01.csv
    β”œβ”€β”€ Data-2022-01-02.csv
    β”œβ”€β”€ ...
    └── B1-Summary-Report.html

Automation Configuration:

Input1: Path to CSV file
Input2: Begin date (YYYY-MM)
Input3: End date (YYYY-MM)

Part B2: Yearly Analysis Reports

Script: B2-COMPLETE-AUTO.py

Objective: Generate comprehensive yearly glucose analysis with interactive charts

Analysis Components:

  1. All Data Over Time
    • Complete timeline of all glucose readings
    • Trend visualization
    • Pattern identification
  2. Daily Overlay (24-Hour Spaghetti Plot)
    • All days overlaid on 24-hour axis
    • Identifies typical daily patterns
    • Shows variability across days
  3. Subtype Metrics Bar Chart
    • Four Type 2 diabetes classifications
    • CGM performance metrics
    • Time in Range (TIR) analysis
  4. Glucose Histogram
    • Distribution of glucose values
    • Normal curve overlay
    • Frequency analysis
  5. Summary Statistics
    • Mean, median, standard deviation
    • Percentiles (5th, 25th, 75th, 95th)
    • Coefficient of variation
    • Estimated A1C/GMI

Output Structure:

Each analysis is generated for: - Each year in the dataset - Overall (all data combined)

Input:

A-Data/yahyanazer_glucose_1-26-2026/
└── yahyanazer_glucose_1-26-2026.csv

Output:

A-Data/yahyanazer_glucose_1-26-2026/
└── B2-Yearly-Analysis/
    β”œβ”€β”€ Glucose-Report-{name}-{timestamp}.html
    β”œβ”€β”€ 2022-01-AllDataOverTime.png
    β”œβ”€β”€ 2022-02-DailyOverlay.png
    β”œβ”€β”€ 2022-03-SubtypeMetrics.png
    β”œβ”€β”€ 2022-04-Histogram.png
    β”œβ”€β”€ 2022-05-SummaryStats.png
    β”œβ”€β”€ Overall-01-AllDataOverTime.png
    β”œβ”€β”€ Overall-02-DailyOverlay.png
    └── ... (all PNG charts)

Automation Configuration:

Input1: Path to CSV file
Input2: (not used)
Input3: (not used)

Part C1: Subtype Analysis

Script: C1-COMPLETE-AUTO.py

Objective: Analyze glucose patterns to identify Type 2 diabetes subtypes

Analysis Categories:

  1. Muscle Insulin Resistance
    • Post-meal glucose spikes
    • Delayed glucose clearance
    • Exercise response patterns
  2. Hepatic Insulin Resistance
    • Fasting glucose levels
    • Dawn phenomenon
    • Overnight glucose production
  3. Beta Cell Dysfunction
    • Initial insulin response
    • Peak timing analysis
    • Glucose recovery patterns
  4. Impaired Incretin Action
    • Meal-related glucose dynamics
    • GLP-1 response indicators
    • Post-prandial patterns

Processing:

  1. Reads daily CSV files from B1-Glucose-Data
  2. Analyzes each day independently
  3. Detects meal events automatically
  4. Calculates subtype scores
  5. Generates individual day reports
  6. Creates aggregate summary

Input:

A-Data/yahyanazer_glucose_1-26-2026/
└── B1-Glucose-Data/
    β”œβ”€β”€ Data-2022-01-01.csv
    β”œβ”€β”€ Data-2022-01-02.csv
    └── ...

Output:

A-Data/yahyanazer_glucose_1-26-2026/
└── C1-Daily-CSV-to-Subtypes-Analysis/
    β”œβ”€β”€ CGM-Report-Data-2022-01-01/
    β”‚   β”œβ”€β”€ meal_events.csv
    β”‚   β”œβ”€β”€ subtype_scores.json
    β”‚   └── analysis_report.html
    β”œβ”€β”€ CGM-Report-Data-2022-01-02/
    β”œβ”€β”€ ...
    β”œβ”€β”€ report-{timestamp}.csv
    └── report-timeseries-{timestamp}.csv

Automation Configuration:

Input1: Path to B1-Glucose-Data folder
Input2: (not used)
Input3: (not used)

Part D1: AGP (Ambulatory Glucose Profile) Reports

Script: D1-COMPLETE-AUTO.py

Objective: Generate standard AGP reports following clinical guidelines

AGP Components:

  1. AGP Profile Chart
    • Median glucose line (50th percentile)
    • Interquartile range (25th-75th percentile)
    • 5th-95th percentile range
    • 24-hour overlay format
  2. Daily Glucose Profiles
    • Individual days overlaid
    • Pattern visualization
    • Variability assessment
  3. Time in Range (TIR) Bar
    • Very Low: <54 mg/dL
    • Low: 54-70 mg/dL
    • Target: 70-180 mg/dL
    • High: 180-250 mg/dL
    • Very High: >250 mg/dL
  4. Statistics Summary
    • GMI (Glucose Management Indicator)
    • Average glucose
    • Glucose variability (CV%)
    • Time in ranges
  5. A1C/GMI Trends
    • 90-day rolling averages
    • Daily A1C estimates
    • Trend visualization
    • Historical progression

Input:

A-Data/yahyanazer_glucose_1-26-2026/
└── B1-Glucose-Data/
    β”œβ”€β”€ Data-2022-01-01.csv
    β”œβ”€β”€ Data-2022-01-02.csv
    └── ...

Output:

A-Data/yahyanazer_glucose_1-26-2026/
└── D1-Daily-CSV-to-AGP-Report/
    β”œβ”€β”€ AGP-Report-{timestamp}.html
    β”œβ”€β”€ 2022-01-AGP-Profile.png
    β”œβ”€β”€ 2022-02-Daily-Profiles.png
    β”œβ”€β”€ 2022-03-TIR-Bar.png
    β”œβ”€β”€ 2022-04-Statistics.png
    β”œβ”€β”€ 2022-05-A1C-Trends.png
    β”œβ”€β”€ Overall-01-AGP-Profile.png
    └── ... (all PNG charts)

Automation Configuration:

Input1: Path to B1-Glucose-Data folder
Input2: (not used)
Input3: (not used)

Part E1: QMD Report Generator

Script: E1-COMPLETE-AUTO.py

Objective: Create comprehensive final reports combining all analyses

Report Generation Process:

  1. Scan Source Folders
    • B2-Yearly-Analysis (PNG charts)
    • C1-Daily-CSV-to-Subtypes-Analysis (results)
    • D1-Daily-CSV-to-AGP-Report (PNG charts)
  2. Extract Years
    • Identifies all years in data
    • Includes β€œOverall” analysis
    • Sorts chronologically
  3. Generate QMD Content
    • Creates Quarto markdown document
    • Embeds all PNG charts
    • Organizes by year
    • Adds descriptions and context
  4. Render Outputs
    • Converts QMD to HTML
    • Converts QMD to PDF
    • Creates navigation index.html
    • Preserves source QMD
  5. Copy Source Data
    • Includes B2, C1, D1 folders
    • Creates self-contained package
    • Enables offline viewing

Name Extraction:

From input folder: yahyanazer_glucose_1-26-2026 Extract base name: yahyanazer_glucose Create report folder: yahyanazer_glucose-Report-2026-01-28--19-34

Input:

A-Data/yahyanazer_glucose_1-26-2026/
β”œβ”€β”€ B2-Yearly-Analysis/
β”œβ”€β”€ C1-Daily-CSV-to-Subtypes-Analysis/
└── D1-Daily-CSV-to-AGP-Report/

Output:

R-Reports/yahyanazer_glucose-Report-2026-01-28--19-34/
β”œβ”€β”€ Glucose_Analysis_Report_2026-01-28--19-34.qmd
β”œβ”€β”€ Glucose_Analysis_Report_2026-01-28--19-34.html
β”œβ”€β”€ Glucose_Analysis_Report_2026-01-28--19-34.pdf
β”œβ”€β”€ index.html
β”œβ”€β”€ B2-Yearly-Analysis/ (copied)
β”œβ”€β”€ C1-Daily-CSV-to-Subtypes-Analysis/ (copied)
└── D1-Daily-CSV-to-AGP-Report/ (copied)

Automation Configuration:

Input1: Path to CSV-named folder
Input2: (not used)
Input3: (not used)

Automation System

automate.xlsx Configuration

The automation system uses an Excel file to configure batch processing.

Excel Structure:

Run Program Input1 Input2 Input3
TRUE B1-COMPLETE-AUTO.py C:…_glucose_1-26-2026.csv 2022-01 2025-12
TRUE B2-COMPLETE-AUTO.py C:…_glucose_1-26-2026.csv
TRUE C1-COMPLETE-AUTO.py C:…-Glucose-Data
TRUE D1-COMPLETE-AUTO.py C:…-Glucose-Data
TRUE E1-COMPLETE-AUTO.py C:…_glucose_1-26-2026

Column Definitions:

  • Run: TRUE/FALSE - enable/disable program
  • Program: Script filename
  • Input1: Primary input path
  • Input2: Secondary input (optional)
  • Input3: Tertiary input (optional)

Helper Module: excel_automate.py

Provides automation support functions: - check_automation(script_path) - Reads Excel config - validate_file_exists(path, description) - Validates file paths - validate_folder_exists(path, description) - Validates folder paths

Batch Processing: run_all.py

Objective: Execute all enabled programs in sequence

Features:

  1. Sequential Execution
    • Runs programs in order listed
    • Waits for each to complete
    • Captures output and errors
  2. Progress Reporting
    • Real-time console output
    • Success/failure status
    • Execution time tracking
  3. HTML Summary Report
    • Saved in Reports/ folder
    • Lists all programs
    • Shows statistics
    • Includes error details
  4. Error Handling
    • Continues on failures
    • Logs all errors
    • Returns appropriate exit codes

Usage:

python run_all.py

Output:

Reports/
└── Batch-Report-2026-01-30-14-30-00.html
    - Summary statistics
    - Program results
    - Error logs
    - Execution times

Usage Workflows

Workflow 1: Manual Processing (GUI Mode)

Use Case: Interactive processing with user prompts

Steps:

  1. Prepare Data

    Place CSV in: B-Data-Analyzer/A-Data/{name}_glucose_{date}/
  2. Run B1 (Daily CSV Generator)

    python B1-COMPLETE-AUTO.py
    • Select CSV file when prompted
    • Choose date range
    • Wait for completion
  3. Run B2 (Yearly Analysis)

    python B2-COMPLETE-AUTO.py
    • Select same CSV file
    • Wait for charts generation
  4. Run C1 (Subtype Analysis)

    python C1-COMPLETE-AUTO.py
    • Select B1-Glucose-Data folder
    • Enter estimate_average (default: 100)
    • Wait for analysis
  5. Run D1 (AGP Reports)

    python D1-COMPLETE-AUTO.py
    • Select B1-Glucose-Data folder
    • Wait for AGP generation
  6. Run E1 (Final Reports)

    python E1-COMPLETE-AUTO.py
    • Select CSV-named folder
    • Wait for QMD rendering
    • Report opens in browser

Result:

R-Reports/{name}-Report-{timestamp}/
└── All final deliverables

Workflow 2: Automated Processing (Excel Mode)

Use Case: Batch processing without user interaction

Steps:

  1. Configure automate.xlsx

    • Set Run=TRUE for desired programs
    • Fill in Input1, Input2, Input3 paths
    • Save Excel file
  2. Run Batch Processor

    python run_all.py
  3. Review Results

    • Check console output
    • Open batch report in Reports/
    • Verify R-Reports/ output

Advantages:

  • No manual intervention required
  • Process multiple patients in sequence
  • Reproducible results
  • Audit trail via batch reports

Workflow 3: Individual Stage Processing

Use Case: Run specific analysis stages only

Examples:

Update AGP reports only:

python D1-COMPLETE-AUTO.py
# Select B1-Glucose-Data folder

Regenerate final report:

python E1-COMPLETE-AUTO.py
# Select CSV-named folder containing B2, C1, D1

Reprocess with different date range:

python B1-COMPLETE-AUTO.py
# Select CSV, choose new date range
# Then re-run C1, D1, E1 as needed

Technical Requirements

Software Requirements

Python Environment:

  • Python 3.8 or higher
  • UTF-8 encoding support

Required Libraries:

# Core
pandas
numpy
matplotlib
scipy

# GUI (for manual mode)
tkinter

# Document generation (for E1)
quarto (external command-line tool)

# Automation
openpyxl  # For reading Excel files

Installation:

pip install pandas numpy matplotlib scipy openpyxl --break-system-packages

Hardware Requirements

  • Minimum:
    • 4 GB RAM
    • 500 MB disk space
    • Dual-core processor
  • Recommended:
    • 8 GB RAM
    • 2 GB disk space
    • Quad-core processor

Operating System

  • Windows 10/11
  • macOS 10.15+
  • Linux (Ubuntu 20.04+)

Data Specifications

Input Data Format (LibreView CSV)

Required Columns:

  • Device Timestamp: Date/time of reading
  • Historic Glucose mg/dL: Retrospective readings
  • Scan Glucose mg/dL: On-demand readings
  • Patient Info (Cell E1): Patient name/identifier

Expected Structure:

Row 1: Metadata (including patient name in E1)
Row 2: Column headers
Row 3+: Data rows

Encoding:

  • UTF-8 with or without BOM
  • CRLF or LF line endings

Output Data Formats

Daily CSV Files (B1):

timestamp,glucose_mg_dL
2022-01-01 00:15:00,120
2022-01-01 00:30:00,118

Analysis Reports:

  • HTML: Self-contained with embedded CSS/JS
  • PDF: Requires Quarto installation
  • PNG Charts: 1200x800 pixels, 300 DPI
  • JSON: Structured analysis results

Quality Assurance

Data Validation

B1 Stage:

B2-D1 Stages:

E1 Stage:

Error Handling

All scripts include: - Try-catch blocks for common errors - Informative error messages - Graceful degradation - Debug output (when enabled) - User-friendly GUI error dialogs

Troubleshooting

Common Issues

Issue 1: β€œNo CSV selected” or β€œNo folder selected”

Cause: User canceled file/folder picker dialog

Solution: - Run script again - Select appropriate file/folder - Or use automation mode to skip GUI

Issue 2: β€œNo valid timestamps found”

Cause: CSV format unexpected or corrupted

Solution: - Verify CSV is from LibreView export - Check file encoding (should be UTF-8) - Ensure row 2 contains column headers - Look for β€œDevice Timestamp” column

Issue 3: Charts not generating in B2/D1

Cause: matplotlib not installed or display issues

Solution:

pip install matplotlib --break-system-packages

Issue 4: QMD not rendering to PDF

Cause: Quarto not installed

Solution: - Install Quarto from https://quarto.org - Add to system PATH - Restart terminal/command prompt

Issue 5: β€œB-Data-Analyzer folder not found”

Cause: E1 cannot locate parent folder structure

Solution: - Ensure folder structure follows specification - Script will use fallback location - Check console for actual output path

Best Practices

Data Organization

  1. Consistent Naming
    • Always use pattern: {name}_glucose_{mm-dd-yyyy}
    • Example: johndoe_glucose_1-26-2026
  2. Backup Original Data
    • Keep copy of raw CSV files
    • Store outside B-Data-Analyzer structure
    • Document data source and export date
  3. Regular Processing
    • Process new data monthly or quarterly
    • Archive old reports in separate location
    • Maintain change log

Automation Setup

  1. Test Individual Scripts First
    • Run each script manually before automation
    • Verify output quality
    • Adjust parameters as needed
  2. Use Relative Paths When Possible
    • Store scripts and data on same drive
    • Easier migration between systems
  3. Monitor Batch Reports
    • Review HTML reports after each batch run
    • Check for errors or warnings
    • Validate output completeness

Report Review

  1. Sanity Check Outputs
    • Verify date ranges are correct
    • Check for data gaps
    • Review glucose value ranges
  2. Clinical Validation
    • Compare with known A1C values
    • Verify TIR percentages reasonable
    • Look for data quality issues
  3. Documentation
    • Note any anomalies or issues
    • Document data quality concerns
    • Keep processing logs

Appendix A: File Naming Conventions

Input Files

  • LibreView CSV: {name}_glucose_{mm-dd-yyyy}.csv
    • Example: yahyanazer_glucose_1-26-2026.csv

Output Folders

  • CSV Folder: {name}_glucose_{mm-dd-yyyy}
    • Example: yahyanazer_glucose_1-26-2026
  • Report Folder: {name}-Report-{yyyy-mm-dd--hh-mm}
    • Example: yahyanazer_glucose-Report-2026-01-28--19-34

Output Files

  • Daily CSV: Data-{yyyy-mm-dd}.csv
    • Example: Data-2022-01-15.csv
  • PNG Charts: {Year}-{Number}-{ChartType}.png
    • Example: 2022-01-AllDataOverTime.png
  • Reports: Glucose_Analysis_Report_{timestamp}.{ext}
    • Example: Glucose_Analysis_Report_2026-01-28--19-34.html

Appendix B: Excel Automation Examples

Example 1: Single Patient Processing

Run Program Input1 Input2 Input3
TRUE B1-COMPLETE-AUTO.py C:-Data-Analyzer-Data_glucose_1-15-2026.csv 2023-01 2026-01
TRUE B2-COMPLETE-AUTO.py C:-Data-Analyzer-Data_glucose_1-15-2026.csv
TRUE C1-COMPLETE-AUTO.py C:-Data-Analyzer-Data_glucose_1-15-2026-Glucose-Data
TRUE D1-COMPLETE-AUTO.py C:-Data-Analyzer-Data_glucose_1-15-2026-Glucose-Data
TRUE E1-COMPLETE-AUTO.py C:-Data-Analyzer-Data_glucose_1-15-2026

Example 2: Multiple Patients (Sequential)

Run Program Input1 Input2 Input3
TRUE B1-COMPLETE-AUTO.py C:…_glucose_1-15-2026.csv 2023-01 2026-01
TRUE B2-COMPLETE-AUTO.py C:…_glucose_1-15-2026.csv
TRUE E1-COMPLETE-AUTO.py C:…_glucose_1-15-2026
TRUE B1-COMPLETE-AUTO.py C:…_glucose_1-20-2026.csv 2023-01 2026-01
TRUE B2-COMPLETE-AUTO.py C:…_glucose_1-20-2026.csv
TRUE E1-COMPLETE-AUTO.py C:…_glucose_1-20-2026

Appendix C: Quick Reference Commands

Installation

# Install Python dependencies
pip install pandas numpy matplotlib scipy openpyxl --break-system-packages

# Install Quarto (for PDF generation)
# Download from: https://quarto.org/docs/get-started/

Manual Execution

# Run individual scripts
python B1-COMPLETE-AUTO.py
python B2-COMPLETE-AUTO.py
python C1-COMPLETE-AUTO.py
python D1-COMPLETE-AUTO.py
python E1-COMPLETE-AUTO.py

Batch Execution

# Run all enabled programs
python run_all.py

Debug Mode

# Enable in script header
DEBUG = True

Appendix D: Contact and Support

Author

Yahya Nazer, PhD - Website: Diabetes-Type2.com - Email: Available on website - Specialization: Industrial Automation, Data Analysis, Diabetes Management

Project Information

  • Project: Glucose Data Analysis Automation System
  • Version: 2.0
  • Last Updated: January 30, 2026
  • Repository: B-Data-Analyzer

Documentation

  • This workflow document (QMD)
  • Individual script docstrings
  • Code comments
  • README files

Revision History

Version Date Changes
1.0 2025-01 Initial workflow implementation
2.0 2026-01-30 Updated folder structure to B-Data-Analyzer/R-Reports
Added E1 base name extraction
Standardized all folder names
Added automation support to all scripts

Appendix E: Detection Algorithm

How the Program Identifies 4 Subtypes of Type 2 Diabetes (Heuristic)

This program analyzes CGM (Continuous Glucose Monitoring) data to infer which of four physiological patterns your glucose responses most resemble:

  1. Muscle insulin resistance (Muscle IR)
  2. Hepatic (liver) insulin resistance (Hepatic IR)
  3. Ξ²-cell dysfunction
  4. Impaired incretin action

Inputs & Assumptions

  • CSV columns (required):
    • timestamp – ISO-like datetime string (local or UTC; script localizes to a chosen TZ).
    • glucose_mg_dL – glucose in mg/dL (if mmol/L, convert Γ—18 or run script with mmol option in extended versions).
  • Sampling: Any cadence is accepted; data are resampled to 5-minute intervals with light interpolation.
  • Meals: If no meal markers exist, meals are auto-detected from rapid rises in CGM.

Processing Pipeline (High-Level)

  1. Load & normalize
    • Parse timestamps; localize/convert timezone.
    • Ensure glucose is in mg/dL.
    • Resample to 5-minute grid; fill small gaps.
  2. Meal detection (heuristic)
    • Flag a meal if there’s a rise β‰₯ 30 mg/dL within ~45 minutes or an average slope β‰₯ 0.35 mg/dL/min, enforcing β‰₯90 minutes between detected meals.
  3. Per-meal metrics For each detected (or provided) meal, compute:
    • Baseline (median in the 30 min pre-meal window)
    • Peak and Ξ” = peak βˆ’ baseline
    • Time-to-peak (minutes from meal to peak)
    • Time above 140 mg/dL and time above 180 mg/dL
    • Time to return to (baseline + 10 mg/dL)
    • AUC(0–180 min) above baseline
  4. Overnight fasting metrics
    • Median and mean between 03:00–06:00 local time (proxy for hepatic output).
  5. Subtype scoring (heuristics)
    • Compute four scores (0–1), then normalize them to sum β‰ˆ 1.
    • The top score is reported as the primary pattern; overlapping patterns are common.

Heuristic Criteria (What the Program Looks For)

Thresholds below are rules of thumb chosen to match typical physiology and to be robust to noisy consumer CGM data. They can be tuned.

1) Muscle Insulin Resistance (Muscle IR)

Idea: Glucose disposal by muscle is sluggish β†’ late peaks and slow clearance.

  • Signals used - Share of meals with time-to-peak > 60 min
  • Share with return to baseline+10 > 180 min
  • Share with time > 140 mg/dL > 120 min - Score contribution
  • 0.4(late_peak_share) + 0.4(slow_return_share) + 0.2*(long_140_share)

2) Hepatic (Liver) Insulin Resistance

Idea: Liver continues to release glucose (gluconeogenesis) β†’ elevated fasting and pre-meal baselines. - Signals used

  • Overnight fasting median: - β‰₯130 β†’ +1.00 - 120–129 β†’ +0.75 - 110–119 β†’ +0.50 - 100–109 β†’ +0.25
  • Share of meals with baseline β‰₯ 110 mg/dL β†’ +0.6*(high_baseline_share)
  • Score contribution - Sum of fasting bump + baseline bump

3) Ξ²-Cell Dysfunction

Idea: Insulin secretion is insufficient/slow β†’ very tall, early spikes.

  • Signals used - Share with Ξ” β‰₯ 80 mg/dL (large excursion)
  • Share with time-to-peak ≀ 45 min (early sharp rise)
  • Share with peak β‰₯ 200 mg/dL
  • Score contribution
  • 0.5*(large_spike_share) + 0.3*(early_peak_share) + 0.2*(very_high_peak_share)

4) Impaired Incretin Action

Idea: Gut hormones (GLP-1/GIP) aren’t amplifying post-meal insulin β†’ prolonged, lingering spikes despite moderate peaks.

  • Signals used - Share with time > 180 mg/dL > 45 min
  • Share with return to baseline+10 > 150 min
  • Share with AUC(0–180) β‰₯ 8000 mgΒ·dLΒ·min - Score contribution
  • 0.4*(long_180_share) + 0.4*(long_return_share) + 0.2*(high_auc_share)

Normalization: After computing all contributions, scores are normalized to sum β‰ˆ 1. If all contributions are zero, each subtype defaults to 0.25.

Outputs

  • cgm_meal_metrics.csv – one row per meal with all metrics above.
  • cgm_subtype_summary.json – fasting metrics, normalized subtype scores, and suggested top pattern.
  • cgm_subtype_report.html – visual report (overall trace, meal markers, bar chart of scores).

The program also names the output folder as

CGM-Report-<CSVName>-<yyyy-mm-dd--hh-mm> and opens the HTML report automatically.

Interpreting the Results

  • Scores reflect patterns, not diagnoses. It’s common to see mixed features (e.g., Muscle IR and Ξ²-cell).
  • High fasting/pre-meal β†’ likely Hepatic IR.
  • Tall, early peaks β†’ likely Ξ²-cell dysfunction.
  • Late peaks & long return β†’ likely Muscle IR.
  • Spikes that linger (high AUC) β†’ likely Incretin impairment.

Use these insights to tailor lifestyle & diet strategies, and discuss with a healthcare professional.

Limitations & Caveats

  • Heuristic thresholds: chosen to be practical; feel free to tune for your cohort.
  • Meal detection noise: auto-detection can mislabel snacks/graze patterns; providing real meal markers improves accuracy.
  • Sensor artifacts: compression lows, missed scans, and calibration shifts can distort metrics.
  • Context matters: meds (e.g., GLP-1 RAs), sleep, stress, and activity strongly influence curves.

Quick Pseudocode


if no meal flags: meals := rising_edge_detector(glucose, riseβ‰₯30 within \~45 min OR slopeβ‰₯0.35) enforce 90 min between meals

for meal in meals: baseline := median(glucose in \[βˆ’30, 0\] min) peak := max(glucose in \[0, +240\] min) delta := peak βˆ’ baseline t_peak := minutes to peak t\>140, t\>180 := durations above thresholds t_return := minutes until glucose ≀ baseline+10 auc0_180 := AUC(glucose βˆ’ baseline, 0..180) with negatives clipped to 0

fasting := median/mean(glucose between 03:00–06:00)

scores := 0 for each subtype scores += rules for hepatic (fasting + high baseline share) scores += rules for muscle (late peak, slow return, long 140) scores += rules for beta-cell (large delta, early peak, high peak) scores += rules for incretin (long 180, long return, high AUC) normalize scores to sum β‰ˆ 1