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

Configurable bolus threshold #712

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Common/Models/StatusExtensionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ struct StatusExtensionContext: RawRepresentable {
}

if let rawValue = rawValue["glucose"] as? [GlucoseContext.RawValue] {
glucose = rawValue.flatMap({return GlucoseContext(rawValue: $0)})
glucose = rawValue.compactMap({return GlucoseContext(rawValue: $0)})
}

if let rawValue = rawValue["predictedGlucose"] as? PredictedGlucoseContext.RawValue {
Expand All @@ -311,7 +311,7 @@ struct StatusExtensionContext: RawRepresentable {
activeInsulin = rawValue["activeInsulin"] as? Double

if let rawValue = rawValue["targetRanges"] as? [DatedRangeContext.RawValue] {
targetRanges = rawValue.flatMap({return DatedRangeContext(rawValue: $0)})
targetRanges = rawValue.compactMap({return DatedRangeContext(rawValue: $0)})
}

if let rawValue = rawValue["temporaryOverride"] as? DatedRangeContext.RawValue {
Expand Down
14 changes: 13 additions & 1 deletion Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
4FF4D1001E18374700846527 /* WatchContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF4D0FF1E18374700846527 /* WatchContext.swift */; };
4FF4D1011E18375000846527 /* WatchContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF4D0FF1E18374700846527 /* WatchContext.swift */; };
540DED971E14C75F002B2491 /* EnliteSensorDisplayable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 540DED961E14C75F002B2491 /* EnliteSensorDisplayable.swift */; };
6AB322972070BD40001EE2C0 /* BolusThreshold.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AB322962070BD40001EE2C0 /* BolusThreshold.swift */; };
6AB322992070BE8B001EE2C0 /* BolusThresholdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AB322982070BE8B001EE2C0 /* BolusThresholdViewController.swift */; };
7D7076351FE06EDE004AC8EA /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D7076371FE06EDE004AC8EA /* Localizable.strings */; };
7D70763A1FE06EDF004AC8EA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D70763C1FE06EDF004AC8EA /* InfoPlist.strings */; };
7D70763F1FE06EDF004AC8EA /* ckcomplication.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D7076411FE06EDF004AC8EA /* ckcomplication.strings */; };
Expand Down Expand Up @@ -593,6 +595,8 @@
4FC8C8001DEB93E400A1452E /* NSUserDefaults+StatusExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSUserDefaults+StatusExtension.swift"; sourceTree = "<group>"; };
4FF4D0FF1E18374700846527 /* WatchContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WatchContext.swift; sourceTree = "<group>"; };
540DED961E14C75F002B2491 /* EnliteSensorDisplayable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnliteSensorDisplayable.swift; sourceTree = "<group>"; };
6AB322962070BD40001EE2C0 /* BolusThreshold.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusThreshold.swift; sourceTree = "<group>"; };
6AB322982070BE8B001EE2C0 /* BolusThresholdViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusThresholdViewController.swift; sourceTree = "<group>"; };
7D68AAA91FE2DB0A00522C49 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
7D68AAAA1FE2DB0A00522C49 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Main.strings; sourceTree = "<group>"; };
7D68AAAB1FE2DB0A00522C49 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/MainInterface.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -762,6 +766,7 @@
43C2FAE01EB656A500364AFF /* GlucoseEffectVelocity.swift */,
4D5B7A4A1D457CCA00796CA9 /* GlucoseG4.swift */,
C178249D1E19B62300D9D25C /* GlucoseThreshold.swift */,
6AB322962070BD40001EE2C0 /* BolusThreshold.swift */,
436FACED1D0BA636004E2427 /* InsulinDataSource.swift */,
436A0DA41D236A2A00104B24 /* LoopError.swift */,
43D848B11E7DF42500DADCBC /* LoopSettings.swift */,
Expand Down Expand Up @@ -966,6 +971,7 @@
43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */,
433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */,
C178249F1E19CF9800D9D25C /* GlucoseThresholdTableViewController.swift */,
6AB322982070BE8B001EE2C0 /* BolusThresholdViewController.swift */,
4302F4E21D4EA54200F0FCAF /* InsulinDeliveryTableViewController.swift */,
435CB6221F37967800C320C7 /* InsulinModelSettingsViewController.swift */,
437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */,
Expand Down Expand Up @@ -1333,7 +1339,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "LoopKit Authors";
TargetAttributes = {
43776F8B1B8022E90074EA36 = {
Expand Down Expand Up @@ -1621,6 +1627,7 @@
43BFF0BC1E45C80600FF19A9 /* UIColor+Loop.swift in Sources */,
43C0944A1CACCC73001F6403 /* NotificationManager.swift in Sources */,
4F08DE9D1E81D0E9006741EA /* StatusChartsManager+LoopKit.swift in Sources */,
6AB322992070BE8B001EE2C0 /* BolusThresholdViewController.swift in Sources */,
434FF1EE1CF27EEF000DB779 /* UITableViewCell.swift in Sources */,
439BED2A1E76093C00B0AED5 /* CGMManager.swift in Sources */,
C18C8C511D5A351900E043FB /* NightscoutDataManager.swift in Sources */,
Expand All @@ -1639,6 +1646,7 @@
4328E0351CFC0AE100E199AA /* WatchDataManager.swift in Sources */,
43D381621EBD9759007F8C8F /* HeaderValuesTableViewCell.swift in Sources */,
43BFF0C51E465A2D00FF19A9 /* UIColor+HIG.swift in Sources */,
6AB322972070BD40001EE2C0 /* BolusThreshold.swift in Sources */,
4302F4E31D4EA54200F0FCAF /* InsulinDeliveryTableViewController.swift in Sources */,
437CCAE01D285C7B0075D2C3 /* ServiceAuthentication.swift in Sources */,
4FC8C8011DEB93E400A1452E /* NSUserDefaults+StatusExtension.swift in Sources */,
Expand Down Expand Up @@ -2003,12 +2011,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -2068,12 +2078,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -54,7 +54,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -84,7 +83,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 1 addition & 3 deletions Loop.xcodeproj/xcshareddata/xcschemes/DoseMathTests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,7 +10,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -31,7 +30,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down Expand Up @@ -41,7 +41,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -61,7 +60,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
8 changes: 3 additions & 5 deletions Loop.xcodeproj/xcshareddata/xcschemes/Loop.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 1 addition & 3 deletions Loop.xcodeproj/xcshareddata/xcschemes/LoopTests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,7 +10,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -31,7 +30,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -54,7 +54,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -84,7 +83,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 1 addition & 3 deletions Loop.xcodeproj/xcshareddata/xcschemes/WatchApp.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -54,7 +54,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -84,7 +83,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
13 changes: 11 additions & 2 deletions Loop/Extensions/NSUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ extension UserDefaults {
removeObject(forKey: "com.loudnate.Naterade.MaximumBasalRatePerHour")
removeObject(forKey: "com.loudnate.Naterade.MaximumBolus")
removeObject(forKey: "com.loopkit.Loop.MinimumBGGuard")
removeObject(forKey: "com.loopkit.Loop.MinimumBolusGuard")
removeObject(forKey: "com.loudnate.Loop.RetrospectiveCorrectionEnabled")
}

Expand All @@ -130,7 +131,14 @@ extension UserDefaults {
} else {
suspendThreshold = nil
}


let bolusThreshold: BolusThreshold?
if let rawValue = dictionary(forKey: "com.loopkit.Loop.MinimumBolusGuard") {
bolusThreshold = BolusThreshold(rawValue: rawValue)
} else {
bolusThreshold = nil
}

var maximumBasalRatePerHour: Double? = double(forKey: "com.loudnate.Naterade.MaximumBasalRatePerHour")
if maximumBasalRatePerHour! <= 0 {
maximumBasalRatePerHour = nil
Expand All @@ -147,6 +155,7 @@ extension UserDefaults {
maximumBasalRatePerHour: maximumBasalRatePerHour,
maximumBolus: maximumBolus,
suspendThreshold: suspendThreshold,
bolusThreshold: bolusThreshold,
retrospectiveCorrectionEnabled: bool(forKey: "com.loudnate.Loop.RetrospectiveCorrectionEnabled")
)
self.loopSettings = settings
Expand Down Expand Up @@ -184,7 +193,7 @@ extension UserDefaults {
guard let rawValue = array(forKey: Key.insulinCounteractionEffects.rawValue) as? [GlucoseEffectVelocity.RawValue] else {
return nil
}
return rawValue.flatMap {
return rawValue.compactMap {
GlucoseEffectVelocity(rawValue: $0)
}
}
Expand Down
5 changes: 5 additions & 0 deletions Loop/Managers/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ final class AnalyticsManager: IdentifiableClass {
if newValue.suspendThreshold != oldValue.suspendThreshold {
logEvent("Minimum BG Guard change")
}

if newValue.bolusThreshold != oldValue.bolusThreshold {
logEvent("Bolus BG Guard change")
}

}

// MARK: - Loop Events
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/CGM/CGMManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protocol CGMManagerDelegate: class {


protocol CGMManager: CustomDebugStringConvertible {
weak var delegate: CGMManagerDelegate? { get set }
var delegate: CGMManagerDelegate? { get set }

/// Whether the device is capable of waking the app
var providesBLEHeartbeat: Bool { get }
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/CGM/EnliteCGMManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class EnliteCGMManager: CGMManager {

_ = deviceManager.remoteDataManager.nightscoutService.uploader?.processGlucoseEvents(events, source: device.device.deviceURI)

if let latestSensorEvent = events.flatMap({ $0.glucoseEvent as? RelativeTimestampedGlucoseEvent }).last {
if let latestSensorEvent = events.compactMap({ $0.glucoseEvent as? RelativeTimestampedGlucoseEvent }).last {
self.sensorState = EnliteSensorDisplayable(latestSensorEvent)
}

Expand Down
Loading