This repository contains:
sensor_glucose_schema.sql
SQL statements to create an sqlite3 databaseimport_sensor_readings.py
a python3 script to import sensor readings from a CSV file exported from the CareLink websiteplot_glucose.py
a python3 script that plots an average day using all available data
For the database you only need sqlite
. To use the scripts you need:
- python3
- pandas, seaborn, matplotlib, etc. Usually installing just
seaborn
withpip
is enough.
sqlite3 glucose.db < sensor_glucose_schema.sql
$ python3 import_sensor_readings.py --db glucose.db "Lastname Firstname 04.04.2021.csv"
Inserted 6411 readings
$ python3 plot_glucose.py --help
usage: plot_glucose.py [-h] --db DB [--high-limit HIGH_LIMIT]
[--low-limit LOW_LIMIT]
Plot average day glucose chart
optional arguments:
-h, --help show this help message and exit
--db DB The sqlite3 database path
--high-limit HIGH_LIMIT
Default: 180
--low-limit LOW_LIMIT
Default: 70
$ python3 plot_glucose.py --db glucose.db
sqlite> select avg(value) from sensor_glucose where date(datetime) >= date("now", "-6 months") ;
avg(value)
----------------
147.318047106536
This query is also a view named last_6months
for convenience:
sqlite> select * from last_6months;
avg(value)
----------------
147.318047106536
If you have 14 days or more of sensor data, you can compute an estimate for your A1C. This estimate is called Glucose Management Indicator (GMI).
Definitions and data taken from this page: Glucose Management Indicator (GMI): A New Term for Estimating A1C From Continuous Glucose Monitoring, Diabetes Care 2018
select cast(gmi_x10 as float) / 10 as GMI from gmi_reference_values where (select * from last_6months) between mean_glucose_mg_dl and up_to;
GMI
----------
6.3
This query is also a view named gmi_prediction
for convenience:
sqlite> select * from gmi_prediction ;
GMI
----------
6.3
The reference values are in table gmi_reference_values
:
sqlite> select * from gmi_reference_values;
mean_glucose_mg_dl up_to gmi_x10
------------------ ---------- ----------
100 124 57
125 149 63
150 174 69
175 199 75
200 224 81
225 249 87
250 274 93
275 299 99
300 349 105
350 700 117
Pull requests are welcome.
All code and sample data are licensed under GNU AGPLv3. Copyright 2021 Manos Pitsidianakis