@@ -38,13 +38,13 @@ extension InsulinCorrection {
38
38
/// - scheduledBasalRate: The scheduled basal rate at the time the correction is delivered
39
39
/// - maxBasalRate: The maximum allowed basal rate
40
40
/// - duration: The duration of the temporary basal
41
- /// - minimumProgrammableIncrementPerUnit : The smallest fraction of a unit supported in basal delivery
41
+ /// - rateRounder : The smallest fraction of a unit supported in basal delivery
42
42
/// - Returns: A temp basal recommendation
43
43
fileprivate func asTempBasal(
44
44
scheduledBasalRate: Double ,
45
45
maxBasalRate: Double ,
46
46
duration: TimeInterval ,
47
- minimumProgrammableIncrementPerUnit : Double
47
+ rateRounder : ( ( Double ) -> Double ) ?
48
48
) -> TempBasalRecommendation {
49
49
var rate = units / ( duration / TimeInterval( hours: 1 ) ) // units/hour
50
50
switch self {
@@ -55,7 +55,8 @@ extension InsulinCorrection {
55
55
}
56
56
57
57
rate = Swift . min ( maxBasalRate, Swift . max ( 0 , rate) )
58
- rate = round ( rate * minimumProgrammableIncrementPerUnit) / minimumProgrammableIncrementPerUnit
58
+
59
+ rate = rateRounder ? ( rate) ?? rate
59
60
60
61
return TempBasalRecommendation (
61
62
unitsPerHour: rate,
@@ -83,16 +84,16 @@ extension InsulinCorrection {
83
84
/// - Parameters:
84
85
/// - pendingInsulin: The number of units expected to be delivered, but not yet reflected in the correction
85
86
/// - maxBolus: The maximum allowable bolus value in units
86
- /// - minimumProgrammableIncrementPerUnit : The smallest fraction of a unit supported in bolus delivery
87
+ /// - volumeRounder : The smallest fraction of a unit supported in bolus delivery
87
88
/// - Returns: A bolus recommendation
88
89
fileprivate func asBolus(
89
90
pendingInsulin: Double ,
90
91
maxBolus: Double ,
91
- minimumProgrammableIncrementPerUnit : Double
92
+ volumeRounder : ( ( Double ) -> Double ) ?
92
93
) -> BolusRecommendation {
93
94
var units = self . units - pendingInsulin
94
95
units = Swift . min ( maxBolus, Swift . max ( 0 , units) )
95
- units = round ( units * minimumProgrammableIncrementPerUnit ) / minimumProgrammableIncrementPerUnit
96
+ units = volumeRounder ? ( units) ?? units
96
97
97
98
return BolusRecommendation (
98
99
amount: units,
@@ -340,8 +341,8 @@ extension Collection where Element == GlucoseValue {
340
341
/// - basalRates: The schedule of basal rates
341
342
/// - maxBasalRate: The maximum allowed basal rate
342
343
/// - lastTempBasal: The previously set temp basal
344
+ /// - rateRounder: Closure that rounds recommendation to nearest supported rate. If nil, no rounding is performed
343
345
/// - duration: The duration of the temporary basal
344
- /// - minimumProgrammableIncrementPerUnit: The smallest fraction of a unit supported in basal delivery
345
346
/// - continuationInterval: The duration of time before an ongoing temp basal should be continued with a new command
346
347
/// - Returns: The recommended temporary basal rate and duration
347
348
func recommendedTempBasal(
@@ -353,8 +354,8 @@ extension Collection where Element == GlucoseValue {
353
354
basalRates: BasalRateSchedule ,
354
355
maxBasalRate: Double ,
355
356
lastTempBasal: DoseEntry ? ,
357
+ rateRounder: ( ( Double ) -> Double ) ? = nil ,
356
358
duration: TimeInterval = . minutes( 30 ) ,
357
- minimumProgrammableIncrementPerUnit: Double = 40 ,
358
359
continuationInterval: TimeInterval = . minutes( 11 )
359
360
) -> TempBasalRecommendation ? {
360
361
let correction = self . insulinCorrection (
@@ -379,7 +380,7 @@ extension Collection where Element == GlucoseValue {
379
380
scheduledBasalRate: scheduledBasalRate,
380
381
maxBasalRate: maxBasalRate,
381
382
duration: duration,
382
- minimumProgrammableIncrementPerUnit : minimumProgrammableIncrementPerUnit
383
+ rateRounder : rateRounder
383
384
)
384
385
385
386
return temp? . ifNecessary (
@@ -400,7 +401,7 @@ extension Collection where Element == GlucoseValue {
400
401
/// - model: The insulin absorption model
401
402
/// - pendingInsulin: The number of units expected to be delivered, but not yet reflected in the correction
402
403
/// - maxBolus: The maximum bolus to return
403
- /// - minimumProgrammableIncrementPerUnit: The smallest fraction of a unit supported in bolus delivery
404
+ /// - volumeRounder: Closure that rounds recommendation to nearest supported bolus volume. If nil, no rounding is performed
404
405
/// - Returns: A bolus recommendation
405
406
func recommendedBolus(
406
407
to correctionRange: GlucoseRangeSchedule ,
@@ -410,7 +411,7 @@ extension Collection where Element == GlucoseValue {
410
411
model: InsulinModel ,
411
412
pendingInsulin: Double ,
412
413
maxBolus: Double ,
413
- minimumProgrammableIncrementPerUnit : Double = 40
414
+ volumeRounder : ( ( Double ) -> Double ) ? = nil
414
415
) -> BolusRecommendation {
415
416
guard let correction = self . insulinCorrection (
416
417
to: correctionRange,
@@ -425,7 +426,7 @@ extension Collection where Element == GlucoseValue {
425
426
var bolus = correction. asBolus (
426
427
pendingInsulin: pendingInsulin,
427
428
maxBolus: maxBolus,
428
- minimumProgrammableIncrementPerUnit : minimumProgrammableIncrementPerUnit
429
+ volumeRounder : volumeRounder
429
430
)
430
431
431
432
// Handle the "current BG below target" notice here
0 commit comments