agp_tool is a Python library and CLI tool for generating Ambulatory Glucose Profiles (AGP) from continuous glucose monitoring (CGM) data. It computes clinical metrics (TIR, TITR, TAR, TBR, variability indices, risk indices) and produces visualizations including AGP plots, daily overlay graphs, and circadian heatmaps.
- In scope: CGM data parsing (xlsx, xls, csv, ods), clinical metric computation, AGP visualization, PDF export, CLI interface, library API
- Not in scope: Real-time data processing, cloud integration, mobile app support, medical device validation
agp_tool <input_file> [options]
input_file: Path to glucose data (.xlsx, .xls, .csv, .ods)- Options:
--output,--very-low-threshold,--low-threshold,--high-threshold,--very-high-threshold,--tight-low,--tight-high,--bin-minutes,--sensor-interval,--min-samples,--no-plot,--verbose,--export,--config,--patient-name,--patient-id,--doctor,--notes,--heatmap,--heatmap-cmap,--pdf,--daily-plot,--dark-mode
ReportGeneratorclass: Instantiate with input file, access metrics as attributes, generate plots via methodsgenerate_reportfunction: Thin wrapper around ReportGenerator, backward compatible
agp/__init__.py: Exports__version__,generate_report,ReportGeneratoragp/__main__.py: CLI entry point (callsagp.main:main)agp/cli.py: Click-based CLIagp/api.py: Public library API (ReportGenerator,generate_report)agp/data.py: Data loading and preprocessingagp/metrics.py: Metric computationagp/plot.py: Plot generationagp/config.py: Configuration handlingagp/report.py: Report header and summaryagp/export.py: Metrics exportagp/pdf.py: PDF generation
- Input: Excel (.xlsx, .xls), CSV, OpenDocument (.ods)
- Required columns: datetime, glucose (mg/dL)
- Output: PNG, PDF, JSON, CSV, XLSX
- Empty input file: Raise
ValueError("No data found in file") - Missing required columns: Raise
ValueError("Missing required column: ...") - All glucose values below/above thresholds: Handle zero division in percentage calculations
- Single day of data: Compute metrics with limited data quality warnings
- Duplicate timestamps: Keep first occurrence, warn if duplicates found
- Gaps >2 hours: May affect MODD/ADRR; issue warning
- Invalid glucose values (negative, extremely high): Filter out and warn
- File not found: Raise
FileNotFoundError
- O(n log n) due to sorting by time
- Memory: Load entire dataset into pandas DataFrame
- Python >= 3.9 required
- Dependencies: pandas, numpy, matplotlib, openpyxl, xlrd, odfpy, Pillow, fpdf2, click