diff --git a/DoseMathTests/DoseMathTests.swift b/DoseMathTests/DoseMathTests.swift index 987977205f..0273dbb4e3 100644 --- a/DoseMathTests/DoseMathTests.swift +++ b/DoseMathTests/DoseMathTests.swift @@ -89,7 +89,7 @@ class RecommendTempBasalTests: XCTestCase { return InsulinSensitivitySchedule(unit: HKUnit.milligramsPerDeciliter(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 60.0)])! } - var minimumBGGuard: GlucoseThreshold { + var suspendThreshold: GlucoseThreshold { return GlucoseThreshold(unit: HKUnit.milligramsPerDeciliter(), value: 55) } @@ -107,7 +107,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -124,7 +124,7 @@ class RecommendTempBasalTests: XCTestCase { var dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -146,7 +146,7 @@ class RecommendTempBasalTests: XCTestCase { dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -164,7 +164,7 @@ class RecommendTempBasalTests: XCTestCase { var dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -185,7 +185,7 @@ class RecommendTempBasalTests: XCTestCase { dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -212,7 +212,7 @@ class RecommendTempBasalTests: XCTestCase { var dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -226,7 +226,7 @@ class RecommendTempBasalTests: XCTestCase { dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -243,7 +243,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -261,7 +261,7 @@ class RecommendTempBasalTests: XCTestCase { var dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -282,7 +282,7 @@ class RecommendTempBasalTests: XCTestCase { dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -300,7 +300,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -318,7 +318,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -336,7 +336,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -354,7 +354,7 @@ class RecommendTempBasalTests: XCTestCase { var dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: self.insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -371,7 +371,7 @@ class RecommendTempBasalTests: XCTestCase { dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -389,7 +389,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -407,7 +407,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -424,7 +424,7 @@ class RecommendTempBasalTests: XCTestCase { let dose = glucose.recommendedTempBasal( to: glucoseTargetRange, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, basalRates: basalRateSchedule, @@ -475,7 +475,7 @@ class RecommendBolusTests: XCTestCase { return InsulinSensitivitySchedule(unit: HKUnit.milligramsPerDeciliter(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 60.0)])! } - var minimumBGGuard: GlucoseThreshold { + var suspendThreshold: GlucoseThreshold { return GlucoseThreshold(unit: HKUnit.milligramsPerDeciliter(), value: 55) } @@ -493,7 +493,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -509,7 +509,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -525,7 +525,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -541,7 +541,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -557,7 +557,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -579,7 +579,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -597,7 +597,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 1, @@ -613,7 +613,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -629,7 +629,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -645,7 +645,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -661,7 +661,7 @@ class RecommendBolusTests: XCTestCase { var dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -675,7 +675,7 @@ class RecommendBolusTests: XCTestCase { dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0.8, @@ -691,7 +691,7 @@ class RecommendBolusTests: XCTestCase { var dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: self.insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -706,7 +706,7 @@ class RecommendBolusTests: XCTestCase { dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -722,7 +722,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, at: glucose.first!.startDate, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, @@ -738,7 +738,7 @@ class RecommendBolusTests: XCTestCase { let dose = glucose.recommendedBolus( to: glucoseTargetRange, - suspendThreshold: minimumBGGuard.quantity, + suspendThreshold: suspendThreshold.quantity, sensitivity: insulinSensitivitySchedule, model: insulinModel, pendingInsulin: 0, diff --git a/Loop/Extensions/NSUserDefaults.swift b/Loop/Extensions/NSUserDefaults.swift index a6b0e832dd..415bbea12b 100644 --- a/Loop/Extensions/NSUserDefaults.swift +++ b/Loop/Extensions/NSUserDefaults.swift @@ -124,11 +124,11 @@ extension UserDefaults { glucoseTargetRangeSchedule = nil } - let minimumBGGuard: GlucoseThreshold? + let suspendThreshold: GlucoseThreshold? if let rawValue = dictionary(forKey: "com.loopkit.Loop.MinimumBGGuard") { - minimumBGGuard = GlucoseThreshold(rawValue: rawValue) + suspendThreshold = GlucoseThreshold(rawValue: rawValue) } else { - minimumBGGuard = nil + suspendThreshold = nil } var maximumBasalRatePerHour: Double? = double(forKey: "com.loudnate.Naterade.MaximumBasalRatePerHour") @@ -146,7 +146,7 @@ extension UserDefaults { glucoseTargetRangeSchedule: glucoseTargetRangeSchedule, maximumBasalRatePerHour: maximumBasalRatePerHour, maximumBolus: maximumBolus, - minimumBGGuard: minimumBGGuard, + suspendThreshold: suspendThreshold, retrospectiveCorrectionEnabled: bool(forKey: "com.loudnate.Loop.RetrospectiveCorrectionEnabled") ) self.loopSettings = settings diff --git a/Loop/Managers/AnalyticsManager.swift b/Loop/Managers/AnalyticsManager.swift index 482e734e19..999bf15b5c 100644 --- a/Loop/Managers/AnalyticsManager.swift +++ b/Loop/Managers/AnalyticsManager.swift @@ -108,7 +108,7 @@ final class AnalyticsManager: IdentifiableClass { logEvent("Maximum bolus change") } - if newValue.minimumBGGuard != oldValue.minimumBGGuard { + if newValue.suspendThreshold != oldValue.suspendThreshold { logEvent("Minimum BG Guard change") } } diff --git a/Loop/Managers/LoopDataManager.swift b/Loop/Managers/LoopDataManager.swift index 2981699635..c172c536bc 100644 --- a/Loop/Managers/LoopDataManager.swift +++ b/Loop/Managers/LoopDataManager.swift @@ -868,7 +868,7 @@ final class LoopDataManager { lastRequestedBolus == nil, // Don't recommend changes if a bolus was just set let tempBasal = predictedGlucose.recommendedTempBasal( to: glucoseTargetRange, - suspendThreshold: settings.minimumBGGuard?.quantity, + suspendThreshold: settings.suspendThreshold?.quantity, sensitivity: insulinSensitivity, model: model, basalRates: basalRates, @@ -913,7 +913,7 @@ final class LoopDataManager { let recommendation = predictedGlucose.recommendedBolus( to: glucoseTargetRange, - suspendThreshold: settings.minimumBGGuard?.quantity, + suspendThreshold: settings.suspendThreshold?.quantity, sensitivity: insulinSensitivity, model: model, pendingInsulin: pendingInsulin, diff --git a/Loop/Models/BolusRecommendation.swift b/Loop/Models/BolusRecommendation.swift index 2f44398f05..8f4fb585bb 100644 --- a/Loop/Models/BolusRecommendation.swift +++ b/Loop/Models/BolusRecommendation.swift @@ -24,7 +24,7 @@ extension BolusRecommendationNotice { case .glucoseBelowSuspendThreshold(minGlucose: let minGlucose): let glucoseFormatter = NumberFormatter.glucoseFormatter(for: unit) let bgStr = glucoseFormatter.describingGlucose(minGlucose.quantity, for: unit)! - return String(format: NSLocalizedString("Predicted glucose of %1$@ is below your suspend threshold setting.", comment: "Notice message when recommending bolus when BG is below minimum BG guard. (1: glucose value)"), bgStr) + return String(format: NSLocalizedString("Predicted glucose of %1$@ is below your suspend threshold setting.", comment: "Notice message when recommending bolus when BG is below the suspend threshold. (1: glucose value)"), bgStr) case .currentGlucoseBelowTarget(glucose: let glucose): let glucoseFormatter = NumberFormatter.glucoseFormatter(for: unit) let bgStr = glucoseFormatter.describingGlucose(glucose.quantity, for: unit)! diff --git a/Loop/Models/LoopSettings.swift b/Loop/Models/LoopSettings.swift index 972fc82105..b01a463683 100644 --- a/Loop/Models/LoopSettings.swift +++ b/Loop/Models/LoopSettings.swift @@ -19,7 +19,7 @@ struct LoopSettings { var maximumBolus: Double? - var minimumBGGuard: GlucoseThreshold? = nil + var suspendThreshold: GlucoseThreshold? = nil var retrospectiveCorrectionEnabled = true } @@ -61,7 +61,7 @@ extension LoopSettings: RawRepresentable { self.maximumBolus = rawValue["maximumBolus"] as? Double if let rawThreshold = rawValue["minimumBGGuard"] as? GlucoseThreshold.RawValue { - self.minimumBGGuard = GlucoseThreshold(rawValue: rawThreshold) + self.suspendThreshold = GlucoseThreshold(rawValue: rawThreshold) } if let retrospectiveCorrectionEnabled = rawValue["retrospectiveCorrectionEnabled"] as? Bool { @@ -79,7 +79,7 @@ extension LoopSettings: RawRepresentable { raw["glucoseTargetRangeSchedule"] = glucoseTargetRangeSchedule?.rawValue raw["maximumBasalRatePerHour"] = maximumBasalRatePerHour raw["maximumBolus"] = maximumBolus - raw["minimumBGGuard"] = minimumBGGuard?.rawValue + raw["minimumBGGuard"] = suspendThreshold?.rawValue return raw } diff --git a/Loop/View Controllers/GlucoseThresholdTableViewController.swift b/Loop/View Controllers/GlucoseThresholdTableViewController.swift index 64607f3ac3..8cbefca243 100644 --- a/Loop/View Controllers/GlucoseThresholdTableViewController.swift +++ b/Loop/View Controllers/GlucoseThresholdTableViewController.swift @@ -22,9 +22,9 @@ final class GlucoseThresholdTableViewController: TextFieldTableViewController { super.init(style: .grouped) - placeholder = NSLocalizedString("Enter minimum BG guard", comment: "The placeholder text instructing users to enter a minimum BG guard") + placeholder = NSLocalizedString("Enter suspend threshold", comment: "The placeholder text instructing users to enter a suspend treshold") keyboardType = .decimalPad - contextHelp = NSLocalizedString("When current or forecasted BG is below miminum BG guard, Loop will not recommend a bolus, and will issue temporary basal rates of 0U/hr.", comment: "Instructions on entering minimum BG threshold") + contextHelp = NSLocalizedString("When current or forecasted glucose is below the suspend threshold, Loop will not recommend a bolus, and will always recommend a temporary basal rate of 0 units per hour.", comment: "Explanation of suspend threshold") unit = glucoseUnit.glucoseUnitDisplayString diff --git a/Loop/View Controllers/SettingsTableViewController.swift b/Loop/View Controllers/SettingsTableViewController.swift index f3054fbe15..e18b5cbfda 100644 --- a/Loop/View Controllers/SettingsTableViewController.swift +++ b/Loop/View Controllers/SettingsTableViewController.swift @@ -115,7 +115,7 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu fileprivate enum ConfigurationRow: Int, CaseCountable { case glucoseTargetRange = 0 - case minimumBGGuard + case suspendThreshold case insulinModel case basalRate case carbRatio @@ -328,12 +328,12 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu } else { configCell.detailTextLabel?.text = TapToSetString } - case .minimumBGGuard: - configCell.textLabel?.text = NSLocalizedString("Minimum BG Guard", comment: "The title text for the minimum bg guard setting") + case .suspendThreshold: + configCell.textLabel?.text = NSLocalizedString("Suspend Threshold", comment: "The title text in settings") - if let minimumBGGuard = dataManager.loopManager.settings.minimumBGGuard { - let value = valueNumberFormatter.string(from: NSNumber(value: minimumBGGuard.value)) ?? "-" - configCell.detailTextLabel?.text = String(format: NSLocalizedString("%1$@ %2$@", comment: "Format string for minimum bg guard. (1: value)(2: bg unit)"), value, minimumBGGuard.unit.glucoseUnitDisplayString) + if let suspendThreshold = dataManager.loopManager.settings.suspendThreshold { + let value = valueNumberFormatter.string(from: NSNumber(value: suspendThreshold.value)) ?? "-" + configCell.detailTextLabel?.text = String(format: NSLocalizedString("%1$@ %2$@", comment: "Format string for current suspend threshold. (1: value)(2: bg unit)"), value, suspendThreshold.unit.glucoseUnitDisplayString) } else { configCell.detailTextLabel?.text = TapToSetString } @@ -591,8 +591,8 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu } } } - case .minimumBGGuard: - if let minBGGuard = dataManager.loopManager.settings.minimumBGGuard { + case .suspendThreshold: + if let minBGGuard = dataManager.loopManager.settings.suspendThreshold { let vc = GlucoseThresholdTableViewController(threshold: minBGGuard.value, glucoseUnit: minBGGuard.unit) vc.delegate = self vc.indexPath = indexPath @@ -940,12 +940,12 @@ extension SettingsTableViewController: TextFieldTableViewControllerDelegate { } case .configuration: switch ConfigurationRow(rawValue: indexPath.row)! { - case .minimumBGGuard: + case .suspendThreshold: if let controller = controller as? GlucoseThresholdTableViewController, let value = controller.value, let minBGGuard = valueNumberFormatter.number(from: value)?.doubleValue { - dataManager.loopManager.settings.minimumBGGuard = GlucoseThreshold(unit: controller.glucoseUnit, value: minBGGuard) + dataManager.loopManager.settings.suspendThreshold = GlucoseThreshold(unit: controller.glucoseUnit, value: minBGGuard) } else { - dataManager.loopManager.settings.minimumBGGuard = nil + dataManager.loopManager.settings.suspendThreshold = nil } case .maxBasal: if let value = controller.value, let rate = valueNumberFormatter.number(from: value)?.doubleValue {