Data Types API
src.core.data_types
¶
Core data type definitions for diabetes data processing.
This module defines the core data types and structures used for processing diabetes device data exports. It supports multiple file formats, different units of measurement, and various data types commonly found in diabetes management tools.
The structure allows for
- Multiple files in a single format
- Multiple data types per table
- Different file types (SQLite, CSV, etc.)
- Flexible column mapping
- Primary/secondary data distinction
FileType
¶
Bases: Enum
Supported file types for diabetes data.
Source code in src/core/data_types.py
DataType
¶
Bases: Enum
Core diabetes data types.
Source code in src/core/data_types.py
CGM = auto()
class-attribute
instance-attribute
¶
BGM = auto()
class-attribute
instance-attribute
¶
INSULIN = auto()
class-attribute
instance-attribute
¶
INSULIN_META = auto()
class-attribute
instance-attribute
¶
CARBS = auto()
class-attribute
instance-attribute
¶
NOTES = auto()
class-attribute
instance-attribute
¶
TimestampType
¶
Bases: Enum
Common types of timestamp format, ensuring correct conversion
Source code in src/core/data_types.py
UNIX_SECONDS = 'unix_seconds'
class-attribute
instance-attribute
¶
UNIX_MILLISECONDS = 'unix_milliseconds'
class-attribute
instance-attribute
¶
UNIX_MICROSECONDS = 'unix_microseconds'
class-attribute
instance-attribute
¶
ISO_8601 = 'iso_8601'
class-attribute
instance-attribute
¶
UNKNOWN = 'unknown'
class-attribute
instance-attribute
¶
ColumnRequirement
¶
Bases: Enum
Defines how column should be validated and if data reading is required
Source code in src/core/data_types.py
Unit
¶
Bases: Enum
Supported units of measurement.
Source code in src/core/data_types.py
ColumnMapping
dataclass
¶
Maps source columns to standardized data types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_name | str | Original column name in the data source | required |
data_type | Optional[DataType] | Type of data this column contains (if applicable - Any column can be used for confirming device.) | None |
unit | Optional[Unit] | Unit of measurement (if applicable) | None |
requirement | ColumnRequirement | Type of requirement - default = REQUIRED_WITH_DATA | REQUIRED_WITH_DATA |
is_primary | bool | Whether this is the primary column - default = True | True |
Examples:
Source code in src/core/data_types.py
source_name: str
instance-attribute
¶
data_type: Optional[DataType] = None
class-attribute
instance-attribute
¶
unit: Optional[Unit] = None
class-attribute
instance-attribute
¶
requirement: ColumnRequirement = ColumnRequirement.REQUIRED_WITH_DATA
class-attribute
instance-attribute
¶
is_primary: bool = True
class-attribute
instance-attribute
¶
__init__(source_name: str, data_type: Optional[DataType] = None, unit: Optional[Unit] = None, requirement: ColumnRequirement = ColumnRequirement.REQUIRED_WITH_DATA, is_primary: bool = True) -> None
¶
TableStructure
dataclass
¶
Defines the structure of a data table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Table name in the data source (empty string for CSV files) | required |
timestamp_column | str | Name of the timestamp column | required |
columns | List[ColumnMapping] | List of column mappings | required |
Examples:
Source code in src/core/data_types.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
name: str
instance-attribute
¶
timestamp_column: str
instance-attribute
¶
columns: List[ColumnMapping]
instance-attribute
¶
__init__(name: str, timestamp_column: str, columns: List[ColumnMapping]) -> None
¶
validate_columns()
¶
Validate that table has at least one column defined.
Raises:
Type | Description |
---|---|
FormatValidationError | If table has no columns defined |
Source code in src/core/data_types.py
validate_unique_source_names()
¶
Validate that all column names are unique.
Raises:
Type | Description |
---|---|
FormatValidationError | If duplicate column names are found |
Source code in src/core/data_types.py
validate_primary_columns()
¶
Validate that each data type has at most one primary column.
Raises:
Type | Description |
---|---|
FormatValidationError | If multiple primary columns exist for any data type |
Source code in src/core/data_types.py
FileConfig
dataclass
¶
Configuration for a specific file in a device format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_pattern | str | Pattern to match filename (e.g., "*.sqlite", "glucose.csv") | required |
file_type | FileType | Type of the data file | required |
tables | List[TableStructure] | List of table structures in the file | required |
Examples:
Source code in src/core/data_types.py
name_pattern: str
instance-attribute
¶
file_type: FileType
instance-attribute
¶
tables: List[TableStructure]
instance-attribute
¶
__init__(name_pattern: str, file_type: FileType, tables: List[TableStructure]) -> None
¶
__post_init__()
¶
Validate file configuration after initialization.
Raises:
Type | Description |
---|---|
FormatValidationError | If file configuration is invalid |
Source code in src/core/data_types.py
DeviceFormat
dataclass
¶
Complete format specification for a diabetes device data export.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Name of the device/format | required |
files | List[FileConfig] | List of file configurations | required |
Examples:
Source code in src/core/data_types.py
name: str
instance-attribute
¶
files: List[FileConfig]
instance-attribute
¶
__init__(name: str, files: List[FileConfig]) -> None
¶
__post_init__()
¶
Validate device format after initialization.
Raises:
Type | Description |
---|---|
FormatValidationError | If device format is invalid |
Source code in src/core/data_types.py
__str__() -> str
¶
String representation including available data types.
Source code in src/core/data_types.py
Module Location
src/core/data_types.py
Key Components¶
FileType¶
Usage
Used to specify and validate input file types during format detection.
DataType¶
Example
TimestampType¶
Important
All timestamps are converted to UTC during processing.
ColumnRequirement¶
Unit¶
ColumnMapping¶
ColumnMapping Example
TableStructure¶
Validation Methods
All validation methods raise FormatValidationError
on failure
FileConfig¶
DeviceFormat¶
Complete Format Example