Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use maxBolus to set automaticDosingIOBLimit #1871

Merged
merged 33 commits into from
Feb 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5a4659c
Use maxBolus and ratio to set maxAutoIOB
marionbarker Dec 15, 2022
b022c4c
Merge branch 'dev' into wip/max-auto-iob
marionbarker Dec 18, 2022
a97e007
Merge branch 'dev' into wip/max-auto-iob
marionbarker Dec 19, 2022
2afe19a
increase ratioMaxAutoInsulinOnBoardToMaxBolus to 2.0
marionbarker Dec 19, 2022
0733eaf
remove print statements
marionbarker Dec 19, 2022
90b0470
restore LoopContants
marionbarker Dec 19, 2022
74fd253
modify name from maxAutoIOB to automaticDosingIOBLimit
marionbarker Dec 19, 2022
dd4ed94
Merge branch 'dev' into wip/max-auto-iob
marionbarker Dec 29, 2022
34bf4cb
Code cleanup in DoseMath
marionbarker Dec 29, 2022
d6698c9
configure new optional commands with default nil
marionbarker Dec 30, 2022
0c182a1
remove whitespace
marionbarker Dec 30, 2022
fc654ff
Add automaticIOBLimitTests
marionbarker Dec 30, 2022
87478d8
DoseMathTests: add new args to all automated dosing tests
marionbarker Dec 31, 2022
fae59f4
remove defaults so new parameters are required
marionbarker Dec 31, 2022
659a10d
Merge branch 'dev' into wip/max-auto-iob
marionbarker Dec 31, 2022
ea948df
Modify method for providing insulinOnBoard in LoopDataManager
marionbarker Jan 2, 2023
bdbd78f
Merge branch 'dev' into wip/max-auto-iob
marionbarker Jan 2, 2023
800eba0
AlertManagerTests: add new parameter
marionbarker Jan 2, 2023
9ac85c3
Merge branch 'dev' into wip/max-auto-iob
marionbarker Jan 2, 2023
0ef5008
match whitespace
marionbarker Jan 2, 2023
c902fbe
`insulinOnBoardValue` -> `insulinOnBoard` for logging purposes
novalegra Jan 3, 2023
8699730
Add test for autobolus clamping
novalegra Jan 3, 2023
3c7c65b
Improve readability of dose clamping logic
novalegra Jan 3, 2023
97b7d8d
Merge pull request #1 from novalegra/max-auto-iob
marionbarker Jan 3, 2023
61bea9d
DoseMathTests: use non-zero value for insulinOnBoard
marionbarker Jan 4, 2023
01c775c
DoseMathTests: move insulinOnBoard internal to test functions
marionbarker Jan 5, 2023
027d5e8
Merge branch 'wip/max-auto-iob' of https://github.com/marionbarker/Lo…
ps2 Feb 10, 2023
c6323df
Move IOB limit handling into recommendedAutomaticDose, and recommende…
ps2 Feb 18, 2023
caf2709
Temp basals limited by iob max
ps2 Feb 18, 2023
374160f
Cleanup
ps2 Feb 18, 2023
e041840
Remove unintentional edit
ps2 Feb 18, 2023
6b83d2f
Fix maxThirtyMinuteRateToKeepIOBBelowLimit calculation
marionbarker Feb 18, 2023
cf808a8
Adjust IOB clamping for temp basals to be relative to scheduled basal
ps2 Feb 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions DoseMathTests/DoseMathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,9 @@ class RecommendTempBasalTests: XCTestCase {
return 2.0 * maxBolus
}

// Tests that were in place before the addition of automaticDosingIOBLimit
// should all still succeed so long as
// insulinOnBoard < automaticDosingIOBLimit - (dose returned by test)
// The test with highest dose is a bolus of 2.3 U
var insulinOnBoard: Double = 7.69

func testNoChange() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_no_change_glucose")
let insulinOnBoard = 0.0

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -138,6 +133,7 @@ class RecommendTempBasalTests: XCTestCase {

func testNoChangeExponentialModel() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_no_change_glucose")
let insulinOnBoard = 0.0

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -157,6 +153,7 @@ class RecommendTempBasalTests: XCTestCase {

func testNoChangeAutomaticBolusing() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_no_change_glucose")
let insulinOnBoard = 0.0

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -177,6 +174,7 @@ class RecommendTempBasalTests: XCTestCase {

func testNoChangeOverrideActive() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_no_change_glucose")
let insulinOnBoard = 7.69
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these and all the below 7.69? Seems an oddly specific number, and I don't think it's obvious why from reading the tests. If you're testing some IOB based limiting or trying to test that it's not limiting, then I think setting specific values here, makes sense. But otherwise, maybe we just keep them all at 0 when we're not actually trying to trigger some IOB level specific logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine returning all prior tests back to 0.0 U IOB - I only changed that because I thought you asked me too. Sorry for the misunderstanding.

The tests where the value of the insulinOnBoard needs to vary are the 7 new tests.

Of all the previously existing tests, the highest dose was 2.3 U, so I chose 7.69 U as IOB.
With that value, the XCTAssert for all the existing tests would pass.
I got lazy pasting in the new let insulinOnBoard into each test and at one point 7.69 was in my paste buffer.
I think I added it starting here because we don't have any clamping tests with OverrideActive.


let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -198,6 +196,7 @@ class RecommendTempBasalTests: XCTestCase {

func testNoChangeOverrideActiveAutomaticBolusing() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_no_change_glucose")
let insulinOnBoard = 7.69

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -221,6 +220,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartHighEndInRange() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_high_end_in_range")
let insulinOnBoard = 7.69

var dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand Down Expand Up @@ -265,6 +265,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartHighEndInRangeAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_high_end_in_range")
let insulinOnBoard = 7.69

var dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand Down Expand Up @@ -312,6 +313,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartHighEndInRangeAutomaticBolusWithOverride() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_high_end_in_range")
let insulinOnBoard = 7.69

var dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand Down Expand Up @@ -360,6 +362,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartLowEndInRange() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_in_range")
let insulinOnBoard = 7.69

var dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand Down Expand Up @@ -403,6 +406,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartLowEndInRangeExponentialModel() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_in_range")
let insulinOnBoard = 7.69

var dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand Down Expand Up @@ -446,6 +450,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartLowEndInRangeAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_in_range")
let insulinOnBoard = 7.69

var dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand Down Expand Up @@ -492,6 +497,7 @@ class RecommendTempBasalTests: XCTestCase {

func testCorrectLowAtMin() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_correct_low_at_min")
let insulinOnBoard = 7.69

// Cancel existing dose
let lastTempBasal = DoseEntry(
Expand Down Expand Up @@ -536,6 +542,7 @@ class RecommendTempBasalTests: XCTestCase {

func testCorrectLowAtMinAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_correct_low_at_min")
let insulinOnBoard = 7.69

// Cancel existing dose
let lastTempBasal = DoseEntry(
Expand Down Expand Up @@ -583,6 +590,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartHighEndLow() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_high_end_low")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -603,6 +611,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartHighEndLowAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_high_end_low")
let insulinOnBoard = 7.69

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -625,6 +634,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartHighEndLowExponentialModel() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_high_end_low")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -645,6 +655,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartLowEndHigh() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_high")
let insulinOnBoard = 7.69

var dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand Down Expand Up @@ -689,6 +700,7 @@ class RecommendTempBasalTests: XCTestCase {

func testStartLowEndHighAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_high")
let insulinOnBoard = 7.69

var dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand Down Expand Up @@ -735,6 +747,7 @@ class RecommendTempBasalTests: XCTestCase {

func testFlatAndHigh() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_flat_and_high")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -755,6 +768,7 @@ class RecommendTempBasalTests: XCTestCase {

func testFlatAndHighAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_flat_and_high")
let insulinOnBoard = 7.69

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -776,6 +790,7 @@ class RecommendTempBasalTests: XCTestCase {

func testFlatAndHighAutomaticBolusWithOverride() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_flat_and_high")
let insulinOnBoard = 7.69

var dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand Down Expand Up @@ -827,7 +842,8 @@ class RecommendTempBasalTests: XCTestCase {

func testHighAndFalling() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_high_and_falling")

let insulinOnBoard = 7.69

let insulinModel = WalshInsulinModel(actionDuration: insulinActionDuration, delay: 0)

let dose = glucose.recommendedTempBasal(
Expand All @@ -849,6 +865,7 @@ class RecommendTempBasalTests: XCTestCase {

func testHighAndFallingAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_high_and_falling")
let insulinOnBoard = 7.69

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -870,6 +887,7 @@ class RecommendTempBasalTests: XCTestCase {

func testHighAndFallingExponentialModel() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_high_and_falling")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -890,6 +908,7 @@ class RecommendTempBasalTests: XCTestCase {

func testInRangeAndRisingAutomaticBolus() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_in_range_and_rising")
let insulinOnBoard = 7.69

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -911,6 +930,7 @@ class RecommendTempBasalTests: XCTestCase {

func testInRangeAndRising() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_in_range_and_rising")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -931,6 +951,7 @@ class RecommendTempBasalTests: XCTestCase {

func testHighAndRising() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_high_and_rising")
let insulinOnBoard = 7.69

var dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand Down Expand Up @@ -970,6 +991,7 @@ class RecommendTempBasalTests: XCTestCase {

func testVeryLowAndRising() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_very_low_end_in_range")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -990,6 +1012,7 @@ class RecommendTempBasalTests: XCTestCase {

func testRiseAfterExponentialModelDIA() {
let glucose = loadGlucoseValueFixture("far_future_high_bg_forecast_after_6_hours")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -1009,6 +1032,7 @@ class RecommendTempBasalTests: XCTestCase {

func testRiseAfterDIA() {
let glucose = loadGlucoseValueFixture("far_future_high_bg_forecast")
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -1029,6 +1053,7 @@ class RecommendTempBasalTests: XCTestCase {

func testNoInputGlucose() {
let glucose: [GlucoseFixtureValue] = []
let insulinOnBoard = 7.69

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -1050,6 +1075,7 @@ class RecommendTempBasalTests: XCTestCase {

func testFlatAndHighAutomaticBolusNoLimit() {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_flat_and_high")
let insulinOnBoard = 7.69

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -1074,7 +1100,7 @@ class RecommendTempBasalTests: XCTestCase {

// max allowed dose will be 0.5 units
let maxAutoCorrection = 0.5
insulinOnBoard = automaticDosingIOBLimit - maxAutoCorrection
let insulinOnBoard = automaticDosingIOBLimit - maxAutoCorrection

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -1101,7 +1127,7 @@ class RecommendTempBasalTests: XCTestCase {
// for this test use partialApplicationFactor of 0.5, instead of 1.0
let maxAutoCorrection = 0.5
let partialApplicationFactor = 0.5
insulinOnBoard = automaticDosingIOBLimit - maxAutoCorrection
let insulinOnBoard = automaticDosingIOBLimit - maxAutoCorrection

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand All @@ -1125,7 +1151,7 @@ class RecommendTempBasalTests: XCTestCase {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_flat_and_high")

// no automatic dose
insulinOnBoard = automaticDosingIOBLimit + 0.1
let insulinOnBoard = automaticDosingIOBLimit + 0.1

let dose = glucose.recommendedAutomaticDose(
to: glucoseTargetRange,
Expand Down Expand Up @@ -1153,7 +1179,7 @@ class RecommendTempBasalTests: XCTestCase {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_high_and_rising")

// no limit
insulinOnBoard = 0.0
let insulinOnBoard = 0.0

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -1178,7 +1204,7 @@ class RecommendTempBasalTests: XCTestCase {
// max allowed dose will be 0.5 units, temp basal twice that
let maxAutoCorrection = 0.5
let limitedBasalRate = scheduledBasalRate + 2.0 * maxAutoCorrection
insulinOnBoard = automaticDosingIOBLimit - maxAutoCorrection
let insulinOnBoard = automaticDosingIOBLimit - maxAutoCorrection

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand All @@ -1201,7 +1227,7 @@ class RecommendTempBasalTests: XCTestCase {
let glucose = loadGlucoseValueFixture("recommend_temp_basal_high_and_rising")

// no automatic dose
insulinOnBoard = automaticDosingIOBLimit + 0.1
let insulinOnBoard = automaticDosingIOBLimit + 0.1

let dose = glucose.recommendedTempBasal(
to: glucoseTargetRange,
Expand Down