Glucose Analysis Tool

Two years ago my daughter was born. At this time I was off work for a few weeks and I had been strongly considering writing a tool that could provide some insight into managing my blood sugars, as I knew controlling my blood sugar was the best chance I had of being the best parent I cold be. At the time I was on multiple daily injections (MDI), leveraging heavily on Dr Bernstein’s teachings and using daily (if possible) exercise as a tools for glucose control.

Two years later the tool has pivoted many times, and at one time I was using machine learning (ML) to predict blood glucose during exercise, until I started using the Dexcom G6 continues glucose monitor (CGM) which was accurate enough to circumvented the need for the aforementioned tool.

At present I am using an automated insulin delivery (AID) device to deliver most of my insulin based on my shifting needs. This significantly reduces the mental burden required for good glycaemic control, as well as reduce some of the anxiety I was experiencing at meals times and when going to the doctor for diabetic checks. This system still requires manual input prior to exercise and constant tuning if you want to have the best experience, and so my tool has pivoted towards analysing this data and providing insight there.

Diabetic Metrics

An analysis of the last 4 years of my diabetic journey highlights a better A1C with a lower standard deviation (SD) indicating more consistency in blood sugars. Its interesting to note the much improved time-in-range (TIR-IN) metrics once I moved over to a insulin pump using an automated insulin delivery (AID) device.

PeriodHypo (below 3.9)In (3.9-10)High (above 10)AverageA1CSDGVIPGSPGRPGR-RiskExercise hoursKilometresPump / MDI
201919%77%3%7.76.50%2.61.2640.192.2Low16146MDI
20208%88%3%6.96.00%2.11.1917.341.6very-low67658MDI
20213%94%3%6.45.60%1.71.188.791.3very-low149920Pump (Loop) 20/11/2021
2022 (YTD)3%96%1%6.55.70%1.51.25.431.2very-low75496Pump (AAPS)
Table displaying the last few years worth of diabetic data.

For a description of some of these values mean please read this article.

Goals

My goal was to provide some insight into what was working and was not. To do this I needed to obtain blood sugar readings as well as nutritional and exercise data. I achieved this by creating a tool that obtains data from Nightscout, Strava and MyFitnessPal This data is then processed and enriched to provide insight. I then developed a tool to export some of this data and display it on my YouTube videos. I had it connected to Garmin to extract sleep and exercise data but the Garmin API failed and I have not had time to update the program.

My tool will then do some analysis to provide some insight at a per meal or per activity level by looking at metrics like time-in-range, average glucose, standard deviation, max glucose, min glucose and many more metrics.

Below are some example’s of some of the data I am exporting and using to make decisions.

This tool is very much still under constant development, as I am always finding new stats to display and bugs with some of my current code (at present both the Garmin API and the MyFitnessPal API have issues)

Below are some graphs and tables that I created in my Tool (The graphs are generated in DB Browser, these will at some stage be created in a JS library or Python graphing library).

Analysis of BG vs ISF, vs Sensitivity after a run.
Analysis of BG vs ISF, vs Sensitivity after gym.
Average TIR (time-in-range) and average blood glucose per exercise type for 2022.

Return-to-Range

I use this table to understand how quickly the system is able to reduce sugars into a normal blood sugar range. At the moment I am using 8 and 6.

Return-to-range analysis (by year)

In 2019 It took just over 6 hours to return to euglycemia (blood glucose < 6) after a peak, in 2023 I managed to reduce that to 3.2 hours.

The average time it takes to return to a blood glucose of 6 mmol/l after a peak.
The average time it takes to return to a blood glucose of 8 mmol/l after a peak.

Daily Sensitivity Analysis

I find this useful to determine if I am more sensitive to insulin on certain days, usually due to exercise.

Exercise Sensitivity Analysis

The exercise sensitivity data has been updated to be hourly for 12 hours post exercise. Its now calculated via SQL (insert statement) and not a Python function into a staging table.

APS Version Analysis

APS Version Battery Analysis

Exercise Stats Analysis (per exercise)

Exercise Stats Analysis (annual)

In the hopes of improving time-in-range while exercising I experimented with reducing insulin and used these values to provide insight into wether the changes were successful or not. In 2019 I was in-range only 66.6 of the time, in 2023 I am in-range 75%, with a slight improvement in glucose while exercising.

Treatments Analysis (per treatment)

Treatment Type Analysis

I use this table to understand how frequently I am interacting with the loop. This has little impact on the version of the variant of Android APS I am using.

Strava diabetic stats

I wanted to see diabetic statistics for each event in Strava, so I wrote a script to update the description field with some data I calculating in the Python tool. The script will check to see if the description field is populated and only update records that have no data in the description field.

Data to follow:

https://1drv.ms/u/s!AmpIRdFk1_yMgosDqE73Osiyl30ZAg?e=w9sIzl

Improvements

There are a number of improvements I am working on.

  • Web Interface

Featured

Day 41 – Loop progress

I have now been Looping for 41 days and I wanted to reflect on the reasons I started looping and the goals I wanted to achieve while Looping.

<ul class="<style> li {text-align: center;} p div
  • A1C of below 5.5%
  • Time-in-Range exceeding 80% (3.9mmol/l -7.8 mmol/l)
  • Reduce diabetic burden
  • Decrease food anxiety whilst increasing food options.
  • Improved time-in-range during exercise with decreased exercise anxiety
  • Lets start with A1C and Time-in-Range (TIR)

    If we look at my stats just prior to looping, I had an A1C of 5.6% and a time-in-range (TIR) of 78.5%. The GVI and PGS stats were also really decent (more on these metrics here https://bionicwookiee.com/2020/02/26/cgm-metrics-gvi-pgs/), with a GVI of 1.2 (non-diabetic) and a PGS of 29 (non-diabetic). A decent average of 6.4 mmol/l, and 3.4 % (1h4min) of time in the 3.0 mmol/l – 3.9 mmol/l range.

    Now we look at my last month while on Loop. In order to reflect the learning curve involved from switching to a pump, I broke the stats into two (2) fortnightly blocks.

    First two (2) weeks on Loop
    Last two (2) weeks on Loop

    As can be seen in the charts above, some slight improvements are seen in all metrics discussed above with a 7.6% reduction in TIR and a 4.5% (-0.3) reduction in average blood glucose. The GVI and PGS metrics reflect modest variability and good control, as opposed to the previous non-diabetic results. I spent 22min (2%) in the 3-3.9 mmol/l range, down 10min from the previous periods 32min.

    Reduce diabetic burden

    This goal is subjective and difficult to quantify. Loop does make it easy to administer insulin, enable an over-ride, track carbohydrate absorption ( I was doing this with Spike) correct a hypo/hyper and even just wake up in-range. It does come with its own challenges and hurdles to overcome, like ensuring you have an up-to-date version, checking certificate expiry, ensuring your CGM is calibrated accurately, and then the challenges of constant site changes, reservoir and battery changes, insulin mixing and exercise.

    Decrease food anxiety while increasing food options

    It definitely feels like less of a burden to experiment with food or eat more carbs, as Loop can pick up any slack due to incorrect bolus calculations, or adjustments after exercise. I used to have 3.4 % (1h4min) hypos (3.0 mmol/l – 3.9 mmol/l) in a month due to incorrect dosing after exercise, but this number has significantly reduced to 2% (22min) while using Loop, as basal can be dynamically adjusted to fluctuations in blood glucose. Post prandial (meal) hyperglycaemia has also significantly been reduced, but I think in part due to Fiasp as it starts working immediately once injected.

    MDI Average Carbs per day: 92.6 (*excluding ‘fake carbs’)

    Loop Average Carbs per day: 121 (*including ‘fake carbs’)

    *’Fake carbs’ are entered into Loop to manage the blood sugar spikes from gluconeogenesis (fat/protein synthesis into glucose)

    Improve time-in-range (TIR) during exercise with decreased exercise anxiety

    Unfortunately since switching to Loop the Python code I wrote to analyse blood glucose broke with the switch to Loop, so I only have the pre-loop analysis. I was quite happy with the control I had during exercise while on MDI.

    I have included the table I have been updating while I work on the Python code, which doesn’t seem to accurately reflect the amount of hypo events I have experienced while running. On the whole cardio has been the item on my list I have struggled with the most, and has been a significant source of anxiety. I am quite certain that after a few months I will have a strategy nailed down and the anxiety associated with exercise will wane. As can be seen in the below table, I am currently focusing on running as its the exercise I am struggling to gain control over the most. I was able to stay in range for the entire duration of all my weight sessions.

    I’ll write a follow up post in the next month before I start my Android APS experiment. Good luck fellow Loopers!!