Contributing New Formats¶
This guide will walk you through the process of adding support for new diabetes device data formats to the project. Our system is designed to be extensible, allowing for easy addition of new data formats while maintaining consistent data handling and validation.
Overview¶
The format system consists of several key components:
- Device Formats: Define how to read and interpret data from specific diabetes devices
- File Configurations: Specify file types and patterns to match
- Table Structures: Define the layout of data tables
- Column Mappings: Map source columns to standardized data types
Quick Start¶
Here's a basic example of adding support for a new CSV format:
Step-by-Step Guide¶
1. Create a New Format File¶
Create a new Python file in the appropriate manufacturer directory under devices/
. For example: - devices/dexcom/g6_csv.py
- devices/medtronic/guardian_export.py
2. Define Core Components¶
Device Format¶
File Configuration¶
Table Structure¶
Column Mapping¶
3. Available Data Types¶
The system supports these core data types:
DataType.CGM
: Continuous glucose monitoring dataDataType.BGM
: Blood glucose meter readingsDataType.INSULIN
: Insulin dosesDataType.INSULIN_META
: Insulin metadata (e.g., brand)DataType.CARBS
: Carbohydrate intakeDataType.NOTES
: Text notes/comments
4. Column Requirements¶
Define how each column should be validated:
CONFIRMATION_ONLY
: Column must exist but data isn't readREQUIRED_WITH_DATA
: Column must exist and contain dataREQUIRED_NULLABLE
: Column must exist but can have missing valuesOPTIONAL
: Column may or may not exist
5. Units of Measurement¶
Available units:
Unit.MGDL
: Blood glucose in mg/dLUnit.MMOL
: Blood glucose in mmol/LUnit.UNITS
: Insulin unitsUnit.GRAMS
: Carbohydrates in grams
6. Multiple Data Types and Files¶
Your format can support multiple data types and files. For example:
7. Primary vs Secondary Data¶
For each data type, you can have one primary column and multiple secondary columns:
8. Validation Requirements¶
Your format must pass these validations:
- At least one file must be defined
- Each file must have at least one table
- Each table must have at least one column
- Column names within a table must be unique
- Each data type can have only one primary column per table
- CSV files must have exactly one table with an empty name
9. Testing Your Format¶
Test your format by:
- Adding it to the appropriate manufacturer directory
- Running the cli script with an example data file and debug argument:
10. Common Patterns and Best Practices¶
-
Column Requirements
- Use
CONFIRMATION_ONLY
for device identification columns - Use
REQUIRED_NULLABLE
for optional data types - Use
REQUIRED_WITH_DATA
for essential columns
- Use
-
Data Organization
- Group related columns in the same table
- Keep primary/secondary relationships clear
- Document any special handling requirements
-
File Patterns
- Use specific patterns when possible (e.g., "export.csv")
- Use wildcards carefully (e.g., "*.sqlite")
-
Error Handling
- Define clear validation requirements
- Document any format-specific quirks
- Handle missing or nullable values appropriately
Examples¶
See these existing format definitions for reference:
-
XDrip+ SQLite Format:
- Handles multiple tables
- Shows primary/secondary relationships
- Demonstrates metadata handling
-
LibreView CSV Format:
- Shows single CSV file handling
- Demonstrates multiple data types
- Shows device confirmation columns
Making Your Format More Robust¶
Handle Edge Cases¶
Add REQUIRED_NULLABLE
for columns that might be empty Document any special data formats or requirements Consider adding validation columns when needed
Improve Documentation¶
Format Verification Checklist¶
All required columns mapped
Units correctly specified
Primary/secondary relationships clear
Timestamp format documented
Edge cases handled
Requirements appropriate for each column
Documentation complete
Need Help?¶
If you need assistance:
- Check existing format definitions for examples
- Review the core data types documentation
- Open an issue for format-specific questions
- Submit a draft PR for feedback
Remember: Good format definitions are clear, well-documented, and handle edge cases appropriately.