-
Notifications
You must be signed in to change notification settings - Fork 18
/
LoopkitPatch.txt
59 lines (55 loc) · 2.91 KB
/
LoopkitPatch.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/LoopKit/InsulinKit/InsulinMath.swift b/LoopKit/InsulinKit/InsulinMath.swift
index 6efd2bd..094fee4 100644
--- a/LoopKit/InsulinKit/InsulinMath.swift
+++ b/LoopKit/InsulinKit/InsulinMath.swift
@@ -40,10 +40,23 @@ extension DoseEntry {
}
// Consider doses within the delta time window as momentary
+ //ken changes
+ //implement user set negative basal multiplier
+ var negativeBasalMultiplier = UserDefaults.standard.double(forKey: "negativeBasalMultiplier")
+ // if user has not modified settings, this value reports as 0 initially
+ // Default shows as 100%, aka, same as unmodified code
+ if negativeBasalMultiplier == 0 {
+ negativeBasalMultiplier = 1
+ }
+ var modifiednetBasalUnits = netBasalUnits
+ if netBasalUnits < 0.0 {
+ modifiednetBasalUnits = netBasalUnits * negativeBasalMultiplier
+ }
+ //this used netBasalUnits as multiplier originally
if endDate.timeIntervalSince(startDate) <= 1.05 * delta {
- return netBasalUnits * model.percentEffectRemaining(at: time)
+ return modifiednetBasalUnits * model.percentEffectRemaining(at: time)
} else {
- return netBasalUnits * continuousDeliveryInsulinOnBoard(at: date, model: model, delta: delta)
+ return modifiednetBasalUnits * continuousDeliveryInsulinOnBoard(at: date, model: model, delta: delta)
}
}
@@ -77,11 +90,23 @@ extension DoseEntry {
}
// Consider doses within the delta time window as momentary
- if endDate.timeIntervalSince(startDate) <= 1.05 * delta {
- return netBasalUnits * -insulinSensitivity * (1.0 - model.percentEffectRemaining(at: time))
- } else {
- return netBasalUnits * -insulinSensitivity * continuousDeliveryGlucoseEffect(at: date, model: model, delta: delta)
- }
+ //ken changes
+ //if net basal is negative use a mulitplier (0-1)
+ //modified in user settings
+ var negativeBasalMultiplier = UserDefaults.standard.double(forKey: "negativeBasalMultiplier")
+ if negativeBasalMultiplier == 0 {
+ negativeBasalMultiplier = 1
+ }
+ var modifiednetBasalUnits = netBasalUnits
+ if netBasalUnits < 0.0 {
+ modifiednetBasalUnits = netBasalUnits * negativeBasalMultiplier
+ }
+ //originally used netBasalUnits
+ if endDate.timeIntervalSince(startDate) <= 1.05 * delta {
+ return modifiednetBasalUnits * -insulinSensitivity * (1.0 - model.percentEffectRemaining(at: time))
+ } else {
+ return modifiednetBasalUnits * -insulinSensitivity * continuousDeliveryGlucoseEffect(at: date, model: model, delta: delta)
+ }
}
func trimmed(from start: Date? = nil, to end: Date? = nil, syncIdentifier: String? = nil) -> DoseEntry {