Skip to content

CGM Data Processor

A robust Python framework for processing and analysing diabetes device data

Python Project Status: Active Release Status Black isort Pylint License: MIT

📈 Process Your Diabetes Data

Analyse data from multiple diabetes management systems including XDrip+, Dexcom, and Freestyle Libre. Handle CGM readings, insulin doses, carbs, and treatment notes with confidence.

🩸 CGM Analysis

  • Gap detection
  • Configurable Interpolation
  • Quality metrics

💉 Treatment Data

  • Insulin doses
  • Carb intake
  • Event notes

🧑‍🔬 Advanced Features

  • Automated format detection
  • Data alignment
  • Flexible export options
  • Complete metadata carried through to output format

🚀 Quick Start

Install CGM Data Processor - Installation Guide

The simplest way to use the CGM Data Processor is to run python -m src.cli path/to/data/export.file from the root directory. The following arguments can be supllied:

1
2
3
4
5
python -m src.cli data.sqlite \
    --interpolation-limit 6   # Max CGM gaps to fill (6 = 30 mins)
    --bolus-limit 10.0       # Max bolus insulin units
    --max-dose 20.0          # Max valid insulin dose
    --output ./my_analysis   # Output location

The cli script, performs multiple processing steps and outputs standardised CSV data. The library can be used in many different configurations depending on your use case. For individual use cases check out our API Reference section.

Example of simple use case:

from src.core.exceptions import DataProcessingError, ReaderError
from src.core.format_registry import FormatRegistry
from src.file_parser.format_detector import FormatDetector
from src.processors import DataProcessor
from src.readers import BaseReader

# Initialise format detection
registry = FormatRegistry()
detector = FormatDetector(registry)
processor = DataProcessor()
file_path = "example_data.sqlite"

# Process file
detected_format, _, _ = detector.detect_format(file_path)
reader = BaseReader.get_reader_for_format(detected_format, file_path)
    with reader:
        table_data = reader.read_all_tables()
        if not table_data:
            raise ReaderError("No valid data found in file")
        try:
            processed_data = processor.process_tables(
                table_data=table_data,
                detected_format=detected_format,
            )
            if not processed_data:
                raise DataProcessingError("No data could be processed")

        except DataProcessingError as e:
            raise DataProcessingError(f"Failed to process data: {str(e)}") from e

💡 Key Features

  • Automated format detection for multiple data sources
  • Robust data validation and cleaning
  • Gap detection and interpolation for CGM data
  • Treatment classification and verification
  • Flexible data export options

📊 Example Output Structure

data/exports
├── 2023-06-03_to_2024-09-28_complete
   ├── aligned_data.csv
   ├── carbs.csv
   ├── cgm.csv
   ├── insulin.csv
   ├── notes.csv
   └── processing_notes.json
└── monthly
    ├── 2023-06
       ├── aligned_data.csv
       ├── carbs.csv
       ├── cgm.csv
       ├── insulin.csv
       ├── notes.csv
       └── processing_notes.json
    ├── 2023-07
       ├── aligned_data.csv
       ├── carbs.csv
       ├── cgm.csv
       ├── insulin.csv
       ├── notes.csv
       └── processing_notes.json

🛡️ Responsible Use

This tool is designed for data analysis only. Not intended for real-time monitoring or medical decision making. Always consult healthcare providers for medical advice.