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

Dev #387

Closed
wants to merge 37 commits into from
Closed

Dev #387

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
93111d5
Open the app when the user taps on the widget
Dec 23, 2016
bdb02ab
Use MAIN_APP_BUNDLE_IDENTIFIER instead of hardcoding "Loop" as the UR…
Dec 23, 2016
82dc3da
Improve string concatenation style
Dec 23, 2016
67f0c3d
Merge pull request #334 from bharat/tap-opens-app
ps2 Dec 25, 2016
21ace16
Fix widget battery level for x22 pumps
wkcwells Dec 27, 2016
378b525
Fix broken build.
Dec 29, 2016
51b09c1
Merge pull request #346 from bharat/fix-build
ps2 Dec 30, 2016
2058195
Merge pull request #342 from wkcwells/fix-battery-in-widget
ps2 Dec 30, 2016
0b7afad
Merge pull request #340 from LoopKit/update-rl-frameworks
ps2 Dec 30, 2016
a3558d4
Refactor HUD views into LoopUI framework (#284) (#330)
Jan 1, 2017
d540cce
Monitor changes and update the widget in real time. (#335)
Jan 2, 2017
311ba44
Use a clear fill color for the circle. (#355)
Jan 2, 2017
9566eac
Refactor files with membership in multiple targets into a Common hier…
Jan 2, 2017
9d3cfad
Disable animation on first render, since we'd be animating from a (#354)
Jan 2, 2017
9d9890b
Enforce a fixed number of fractional digits per unit type. (#356)
Jan 5, 2017
7e221ee
Add an info.plist entry to widget info.plist to make tapping on widge…
wkcwells Jan 5, 2017
aac86be
Only allow one active glucose data source (#364)
Feb 11, 2017
f1e4342
Upgrade project to 0820 (#376)
Feb 13, 2017
c262b64
Merge complications changes back into dev (they were accidentally mer…
ps2 Feb 16, 2017
a0b425b
Merge branch 'master' into dev
ps2 Feb 16, 2017
bb7cb32
Merge branch 'master' into dev
ps2 Feb 16, 2017
1775f42
Tmecklem x22 enlite cgm (#378)
ps2 Feb 19, 2017
3ba50da
remove +ve momentum from bolus calculation (#372)
thebookins Feb 19, 2017
08591de
Minimum bg guard (#365)
ps2 Feb 20, 2017
841a366
Update LoopKit and Rileylink frameworks
ps2 Feb 20, 2017
3ae1077
Merge pull request #380 from LoopKit/update-frameworks
ps2 Feb 20, 2017
93da3d4
Bump version
ps2 Feb 20, 2017
59ce749
Merge pull request #381 from LoopKit/bump-version
ps2 Feb 20, 2017
27017e6
Show bg values in warning messages in bolus ui
ps2 Feb 24, 2017
cb394ca
Do not show last loop errors in bolus view; only recommendation alerts
ps2 Feb 24, 2017
2b6e739
Show last loop error on clicking loop status
ps2 Feb 24, 2017
32764bc
Use tap gesture recognizer instead of delegate
ps2 Feb 25, 2017
6ccc578
remove extraneous line
ps2 Feb 25, 2017
ef9f943
Add recovery text for configuration alerts, and single out minimum bg…
ps2 Feb 25, 2017
1a47658
Merge pull request #384 from LoopKit/last-loop-error
ps2 Feb 25, 2017
c92e780
Merge pull request #382 from LoopKit/bolus-ui-updates
ps2 Feb 25, 2017
e8b207e
Add mmol watchapp units support. Add modularLarge complication. Chang…
walker0 Mar 2, 2017
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
Prev Previous commit
Next Next commit
remove +ve momentum from bolus calculation (#372)
* remove +ve momentum from bolus calculation

* add logging, set prediction to nil when inputs change
  • Loading branch information
thebookins authored and ps2 committed Feb 19, 2017
commit 3ba50da6a1e7eaf987b3920add8f0a31b2d40d1c
7 changes: 5 additions & 2 deletions Loop/Managers/DiagnosticLogger+LoopKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension DiagnosticLogger {
addError(String(describing: message), fromSource: source)
}

func addLoopStatus(startDate: Date, endDate: Date, glucose: GlucoseValue, effects: [String: [GlucoseEffect]], error: Error?, prediction: [GlucoseValue], predictionWithRetrospectiveEffect: Double, recommendedTempBasal: LoopDataManager.TempBasalRecommendation?) {
func addLoopStatus(startDate: Date, endDate: Date, glucose: GlucoseValue, effects: [String: [GlucoseEffect]], error: Error?, prediction: [GlucoseValue], predictionWithRetrospectiveEffect: Double, eventualBG: Double, eventualBGWithRetrospectiveEffect: Double, eventualBGWithoutMomentum: Double, recommendedTempBasal: LoopDataManager.TempBasalRecommendation?) {

let dateFormatter = DateFormatter.ISO8601StrictDateFormatter()
let unit = HKUnit.milligramsPerDeciliterUnit()
Expand Down Expand Up @@ -57,7 +57,10 @@ extension DiagnosticLogger {
"unit": unit.unitString
]
},
"prediction_retrospect_delta": predictionWithRetrospectiveEffect
"prediction_retrospect_delta": predictionWithRetrospectiveEffect,
"eventualBG": eventualBG,
"eventualBGWithRetrospectiveEffect": eventualBGWithRetrospectiveEffect,
"eventualBGWithoutMomentum": eventualBGWithoutMomentum
]

if let error = error {
Expand Down
27 changes: 25 additions & 2 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ final class LoopDataManager {
}
}

if self.predictedGlucose == nil {
if (self.predictedGlucose == nil || self.predictedGlucoseWithoutMomentum == nil) {
do {
try self.updatePredictedGlucoseAndRecommendedBasal()
} catch let error {
Expand Down Expand Up @@ -305,6 +305,7 @@ final class LoopDataManager {
private var carbEffect: [GlucoseEffect]? {
didSet {
predictedGlucose = nil
predictedGlucoseWithoutMomentum = nil

// Carb data may be back-dated, so re-calculate the retrospective glucose.
retrospectivePredictedGlucose = nil
Expand All @@ -318,6 +319,7 @@ final class LoopDataManager {
}

predictedGlucose = nil
predictedGlucoseWithoutMomentum = nil
}
}
private var insulinOnBoard: InsulinValue?
Expand All @@ -336,6 +338,7 @@ final class LoopDataManager {
recommendedTempBasal = nil
}
}
private var predictedGlucoseWithoutMomentum: [GlucoseValue]?
private var retrospectivePredictedGlucose: [GlucoseValue]? {
didSet {
retrospectiveGlucoseEffect = []
Expand Down Expand Up @@ -509,6 +512,7 @@ final class LoopDataManager {

let prediction = LoopMath.predictGlucose(glucose, momentum: momentum, effects: carbEffect, insulinEffect)
let predictionWithRetrospectiveEffect = LoopMath.predictGlucose(glucose, momentum: momentum, effects: carbEffect, insulinEffect, retrospectiveGlucoseEffect)
let predictionWithoutMomentum = LoopMath.predictGlucose(glucose, effects: carbEffect, insulinEffect)

let predictDiff: Double

Expand All @@ -521,6 +525,10 @@ final class LoopDataManager {
predictDiff = 0
}

let eventualBG: Double = prediction.last?.quantity.doubleValue(for: unit) ?? 0
let eventualBGWithRetrospectiveEffect: Double = predictionWithRetrospectiveEffect.last?.quantity.doubleValue(for: unit) ?? 0
let eventualBGWithoutMomentum: Double = predictionWithoutMomentum.last?.quantity.doubleValue(for: unit) ?? 0

defer {
deviceDataManager.logger.addLoopStatus(
startDate: startDate,
Expand All @@ -535,11 +543,15 @@ final class LoopDataManager {
error: error,
prediction: prediction,
predictionWithRetrospectiveEffect: predictDiff,
eventualBG: eventualBG,
eventualBGWithRetrospectiveEffect: eventualBGWithRetrospectiveEffect,
eventualBGWithoutMomentum: eventualBGWithoutMomentum,
recommendedTempBasal: recommendedTempBasal
)
}

self.predictedGlucose = retrospectiveCorrectionEnabled ? predictionWithRetrospectiveEffect : prediction
self.predictedGlucoseWithoutMomentum = predictionWithoutMomentum

guard let
maxBasal = deviceDataManager.maximumBasalRatePerHour,
Expand Down Expand Up @@ -597,6 +609,7 @@ final class LoopDataManager {
private func recommendBolus() throws -> Double {
guard let
glucose = self.predictedGlucose,
let glucoseWithoutMomentum = self.predictedGlucoseWithoutMomentum,
let maxBolus = self.deviceDataManager.maximumBolus,
let glucoseTargetRange = self.deviceDataManager.glucoseTargetRangeSchedule,
let insulinSensitivity = self.deviceDataManager.insulinSensitivitySchedule,
Expand All @@ -617,13 +630,23 @@ final class LoopDataManager {

let pendingBolusAmount: Double = lastBolus?.units ?? 0

return max(0, DoseMath.recommendBolusFromPredictedGlucose(glucose,
let recommendedBolusWithMomentum = max(0, DoseMath.recommendBolusFromPredictedGlucose(glucose,
lastTempBasal: self.lastTempBasal,
maxBolus: maxBolus,
glucoseTargetRange: glucoseTargetRange,
insulinSensitivity: insulinSensitivity,
basalRateSchedule: basalRates
) - pendingBolusAmount)

let recommendedBolusWithoutMomentum = max(0, DoseMath.recommendBolusFromPredictedGlucose(glucoseWithoutMomentum,
lastTempBasal: self.lastTempBasal,
maxBolus: maxBolus,
glucoseTargetRange: glucoseTargetRange,
insulinSensitivity: insulinSensitivity,
basalRateSchedule: basalRates
) - pendingBolusAmount)

return min(recommendedBolusWithMomentum, recommendedBolusWithoutMomentum)
}

func getRecommendedBolus(_ resultsHandler: @escaping (_ units: Double?, _ error: Error?) -> Void) {
Expand Down