From d0f0fa0c67a00a64d6a1443020c49749d8847f5f Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Fri, 12 May 2017 19:21:56 -0500 Subject: [PATCH] renaming milligramsPerDeciliterUnit() to milligramsPerDeciliter() --- Common/Extensions/HKUnit.swift | 6 ++--- DoseMathTests/DoseMathTests.swift | 24 +++++++++---------- .../StatusViewController.swift | 4 ++-- Loop/Managers/CGM/EnliteCGMManager.swift | 2 +- Loop/Managers/DeviceDataManager.swift | 2 +- Loop/Managers/DoseMath.swift | 2 +- Loop/Managers/LoopDataManager.swift | 2 +- .../Managers/StatusExtensionDataManager.swift | 2 +- Loop/Managers/WatchDataManager.swift | 2 +- Loop/Models/BolusRecommendation.swift | 2 ++ Loop/Models/GlucoseG4.swift | 2 +- Loop/Models/ShareGlucose+GlucoseKit.swift | 2 +- .../BolusViewController.swift | 2 +- .../PredictionTableViewController.swift | 4 ++-- .../StatusTableViewController.swift | 4 ++-- LoopUI/Managers/StatusChartsManager.swift | 4 ++-- 16 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Common/Extensions/HKUnit.swift b/Common/Extensions/HKUnit.swift index b11c11a0dc..c18d256a01 100644 --- a/Common/Extensions/HKUnit.swift +++ b/Common/Extensions/HKUnit.swift @@ -21,17 +21,17 @@ extension HKUnit { } } - static func milligramsPerDeciliterUnit() -> HKUnit { + static func milligramsPerDeciliter() -> HKUnit { return HKUnit.gramUnit(with: .milli).unitDivided(by: HKUnit.literUnit(with: .deci)) } - static func millimolesPerLiterUnit() -> HKUnit { + static func millimolesPerLiter() -> HKUnit { return HKUnit.moleUnit(with: .milli, molarMass: HKUnitMolarMassBloodGlucose).unitDivided(by: HKUnit.liter()) } // A glucose-centric presentation helper for the localized unit string var glucoseUnitDisplayString: String { - if self == HKUnit.millimolesPerLiterUnit() { + if self == HKUnit.millimolesPerLiter() { return NSLocalizedString("mmol/L", comment: "The unit display string for millimoles of glucose per liter") } else { return String(describing: self) diff --git a/DoseMathTests/DoseMathTests.swift b/DoseMathTests/DoseMathTests.swift index ea584a9ff1..7f77e7179c 100644 --- a/DoseMathTests/DoseMathTests.swift +++ b/DoseMathTests/DoseMathTests.swift @@ -61,7 +61,7 @@ class RecommendTempBasalTests: XCTestCase { return fixture.map { return GlucoseFixtureValue( startDate: dateFormatter.date(from: $0["date"] as! String)!, - quantity: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: $0["amount"] as! Double) + quantity: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: $0["amount"] as! Double) ) } } @@ -81,15 +81,15 @@ class RecommendTempBasalTests: XCTestCase { } var glucoseTargetRange: GlucoseRangeSchedule { - return GlucoseRangeSchedule(unit: HKUnit.milligramsPerDeciliterUnit(), dailyItems: [RepeatingScheduleValue(startTime: TimeInterval(0), value: DoubleRange(minValue: 90, maxValue: 120))], workoutRange: nil)! + return GlucoseRangeSchedule(unit: HKUnit.milligramsPerDeciliter(), dailyItems: [RepeatingScheduleValue(startTime: TimeInterval(0), value: DoubleRange(minValue: 90, maxValue: 120))], workoutRange: nil)! } var insulinSensitivitySchedule: InsulinSensitivitySchedule { - return InsulinSensitivitySchedule(unit: HKUnit.milligramsPerDeciliterUnit(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 60.0)])! + return InsulinSensitivitySchedule(unit: HKUnit.milligramsPerDeciliter(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 60.0)])! } var minimumBGGuard: GlucoseThreshold { - return GlucoseThreshold(unit: HKUnit.milligramsPerDeciliterUnit(), value: 55) + return GlucoseThreshold(unit: HKUnit.milligramsPerDeciliter(), value: 55) } var insulinActionDuration: TimeInterval { @@ -385,7 +385,7 @@ class RecommendTempBasalTests: XCTestCase { XCTAssertEqual(TimeInterval(minutes: 30), dose!.duration) // Use mmol sensitivity value - let insulinSensitivitySchedule = InsulinSensitivitySchedule(unit: HKUnit.millimolesPerLiterUnit(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 3.33)])! + let insulinSensitivitySchedule = InsulinSensitivitySchedule(unit: HKUnit.millimolesPerLiter(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 3.33)])! dose = DoseMath.recommendTempBasalFromPredictedGlucose(glucose, atDate: glucose.first!.startDate, @@ -465,7 +465,7 @@ class RecommendBolusTests: XCTestCase { return fixture.map { return GlucoseFixtureValue( startDate: dateFormatter.date(from: $0["date"] as! String)!, - quantity: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: $0["amount"] as! Double) + quantity: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: $0["amount"] as! Double) ) } } @@ -485,15 +485,15 @@ class RecommendBolusTests: XCTestCase { } var glucoseTargetRange: GlucoseRangeSchedule { - return GlucoseRangeSchedule(unit: HKUnit.milligramsPerDeciliterUnit(), dailyItems: [RepeatingScheduleValue(startTime: TimeInterval(0), value: DoubleRange(minValue: 90, maxValue: 120))], workoutRange: nil)! + return GlucoseRangeSchedule(unit: HKUnit.milligramsPerDeciliter(), dailyItems: [RepeatingScheduleValue(startTime: TimeInterval(0), value: DoubleRange(minValue: 90, maxValue: 120))], workoutRange: nil)! } var insulinSensitivitySchedule: InsulinSensitivitySchedule { - return InsulinSensitivitySchedule(unit: HKUnit.milligramsPerDeciliterUnit(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 60.0)])! + return InsulinSensitivitySchedule(unit: HKUnit.milligramsPerDeciliter(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 60.0)])! } var minimumBGGuard: GlucoseThreshold { - return GlucoseThreshold(unit: HKUnit.milligramsPerDeciliterUnit(), value: 55) + return GlucoseThreshold(unit: HKUnit.milligramsPerDeciliter(), value: 55) } var insulinActionDuration: TimeInterval { @@ -589,13 +589,11 @@ class RecommendBolusTests: XCTestCase { XCTAssertEqual(1.325, dose.amount) if case BolusRecommendationNotice.currentGlucoseBelowTarget(let glucose, let units) = dose.notice! { - XCTAssertEqual(units, HKUnit.milligramsPerDeciliterUnit()) + XCTAssertEqual(units, HKUnit.milligramsPerDeciliter()) XCTAssertEqual(glucose.quantity.doubleValue(for: units), 60) } else { XCTFail("Expected currentGlucoseBelowTarget, but got \(dose.notice!)") } - - //XCTAssertEqual(BolusRecommendationNotice.currentGlucoseBelowTarget(glucose: GlucoseValue(56), unit: HKUnit.milligramsPerDeciliterUnit()), dose.notice!) } func testDroppingBelowRangeThenRising() { @@ -747,7 +745,7 @@ class RecommendBolusTests: XCTestCase { XCTAssertEqual(1.0, dose.amount) // Use mmol sensitivity value - let insulinSensitivitySchedule = InsulinSensitivitySchedule(unit: HKUnit.millimolesPerLiterUnit(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 10.0 / 3)])! + let insulinSensitivitySchedule = InsulinSensitivitySchedule(unit: HKUnit.millimolesPerLiter(), dailyItems: [RepeatingScheduleValue(startTime: 0.0, value: 10.0 / 3)])! dose = DoseMath.recommendBolusFromPredictedGlucose(glucose, atDate: glucose.first!.startDate, diff --git a/Loop Status Extension/StatusViewController.swift b/Loop Status Extension/StatusViewController.swift index 45533161b8..5069544e7b 100644 --- a/Loop Status Extension/StatusViewController.swift +++ b/Loop Status Extension/StatusViewController.swift @@ -50,8 +50,8 @@ class StatusViewController: UIViewController, NCWidgetProviding { ) charts.glucoseDisplayRange = ( - min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 100), - max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 175) + min: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: 100), + max: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: 175) ) return charts diff --git a/Loop/Managers/CGM/EnliteCGMManager.swift b/Loop/Managers/CGM/EnliteCGMManager.swift index 6a3dd24c6b..76371f2ceb 100644 --- a/Loop/Managers/CGM/EnliteCGMManager.swift +++ b/Loop/Managers/CGM/EnliteCGMManager.swift @@ -39,7 +39,7 @@ final class EnliteCGMManager: CGMManager { self.sensorState = EnliteSensorDisplayable(latestSensorEvent) } - let unit = HKUnit.milligramsPerDeciliterUnit() + let unit = HKUnit.milligramsPerDeciliter() let glucoseValues = events // TODO: Is the { $0.date > latestGlucoseDate } filter duplicative? .filter({ $0.glucoseEvent is SensorValueGlucoseEvent && $0.date > latestGlucoseDate }) diff --git a/Loop/Managers/DeviceDataManager.swift b/Loop/Managers/DeviceDataManager.swift index 6b2f0283ef..e58fc4181b 100644 --- a/Loop/Managers/DeviceDataManager.swift +++ b/Loop/Managers/DeviceDataManager.swift @@ -178,7 +178,7 @@ final class DeviceDataManager { // Enlite data is included if let date = glucoseDateComponents?.date { loopManager.addGlucose([( - quantity: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: Double(glucose)), + quantity: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: Double(glucose)), date: date, isDisplayOnly: false )], from: nil) diff --git a/Loop/Managers/DoseMath.swift b/Loop/Managers/DoseMath.swift index 1c146b4317..3511a7d142 100644 --- a/Loop/Managers/DoseMath.swift +++ b/Loop/Managers/DoseMath.swift @@ -31,7 +31,7 @@ struct DoseMath { - returns: The determined basal rate, in Units/hour */ private static func calculateTempBasalRateForGlucose(_ currentGlucose: HKQuantity, toTargetGlucose targetGlucose: HKQuantity, insulinSensitivity: HKQuantity, currentBasalRate: Double, maxBasalRate: Double, duration: TimeInterval) -> Double { - let unit = HKUnit.milligramsPerDeciliterUnit() + let unit = HKUnit.milligramsPerDeciliter() let doseUnits = (currentGlucose.doubleValue(for: unit) - targetGlucose.doubleValue(for: unit)) / insulinSensitivity.doubleValue(for: unit) let rate = min(maxBasalRate, max(0, doseUnits / (duration / TimeInterval(hours: 1)) + currentBasalRate)) diff --git a/Loop/Managers/LoopDataManager.swift b/Loop/Managers/LoopDataManager.swift index 75cbda5a14..f95b0f59ee 100644 --- a/Loop/Managers/LoopDataManager.swift +++ b/Loop/Managers/LoopDataManager.swift @@ -715,7 +715,7 @@ final class LoopDataManager { self.retrospectivePredictedGlucose = retrospectivePrediction guard let lastGlucose = retrospectivePrediction.last else { return } - let glucoseUnit = HKUnit.milligramsPerDeciliterUnit() + let glucoseUnit = HKUnit.milligramsPerDeciliter() let velocityUnit = glucoseUnit.unitDivided(by: HKUnit.second()) let discrepancy = change.end.quantity.doubleValue(for: glucoseUnit) - lastGlucose.quantity.doubleValue(for: glucoseUnit) // mg/dL diff --git a/Loop/Managers/StatusExtensionDataManager.swift b/Loop/Managers/StatusExtensionDataManager.swift index 1999446e53..eedc85d64e 100644 --- a/Loop/Managers/StatusExtensionDataManager.swift +++ b/Loop/Managers/StatusExtensionDataManager.swift @@ -62,7 +62,7 @@ final class StatusExtensionDataManager { ) context.predictedGlucose = PredictedGlucoseContext( values: (1...36).map { 89.123 + Double($0 * 5) }, // 3 hours of linear data - unit: HKUnit.milligramsPerDeciliterUnit(), + unit: HKUnit.milligramsPerDeciliter(), startDate: Date(), interval: TimeInterval(minutes: 5)) diff --git a/Loop/Managers/WatchDataManager.swift b/Loop/Managers/WatchDataManager.swift index e0f25e6810..6f44d2c011 100644 --- a/Loop/Managers/WatchDataManager.swift +++ b/Loop/Managers/WatchDataManager.swift @@ -62,7 +62,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate { private var lastComplicationContext: WatchContext? private let minTrendDrift: Double = 20 - private lazy var minTrendUnit = HKUnit.milligramsPerDeciliterUnit() + private lazy var minTrendUnit = HKUnit.milligramsPerDeciliter() private func sendWatchContext(_ context: WatchContext) { if let session = watchSession, session.isPaired && session.isWatchAppInstalled { diff --git a/Loop/Models/BolusRecommendation.swift b/Loop/Models/BolusRecommendation.swift index 9fdb83e3c4..e09eadde6c 100644 --- a/Loop/Models/BolusRecommendation.swift +++ b/Loop/Models/BolusRecommendation.swift @@ -10,6 +10,7 @@ import Foundation import LoopKit import HealthKit + enum BolusRecommendationNotice: CustomStringConvertible, Equatable { case glucoseBelowMinimumGuard(minGlucose: GlucoseValue, unit: HKUnit) case currentGlucoseBelowTarget(glucose: GlucoseValue, unit: HKUnit) @@ -74,6 +75,7 @@ struct BolusRecommendation { } } + extension BolusRecommendation: Comparable { static func ==(lhs: BolusRecommendation, rhs: BolusRecommendation) -> Bool { return lhs.amount == rhs.amount diff --git a/Loop/Models/GlucoseG4.swift b/Loop/Models/GlucoseG4.swift index de8b64f0ac..52e893d7a7 100644 --- a/Loop/Models/GlucoseG4.swift +++ b/Loop/Models/GlucoseG4.swift @@ -15,7 +15,7 @@ import LoopUI extension GlucoseG4: GlucoseValue { public var quantity: HKQuantity { - return HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: Double(glucose)) + return HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: Double(glucose)) } public var startDate: Date { diff --git a/Loop/Models/ShareGlucose+GlucoseKit.swift b/Loop/Models/ShareGlucose+GlucoseKit.swift index b40b2349fa..f0854785a1 100644 --- a/Loop/Models/ShareGlucose+GlucoseKit.swift +++ b/Loop/Models/ShareGlucose+GlucoseKit.swift @@ -19,7 +19,7 @@ extension ShareGlucose: GlucoseValue { } public var quantity: HKQuantity { - return HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: Double(glucose)) + return HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: Double(glucose)) } } diff --git a/Loop/View Controllers/BolusViewController.swift b/Loop/View Controllers/BolusViewController.swift index 876963ef60..53b9045857 100644 --- a/Loop/View Controllers/BolusViewController.swift +++ b/Loop/View Controllers/BolusViewController.swift @@ -63,7 +63,7 @@ final class BolusViewController: UITableViewController, IdentifiableClass, UITex // MARK: - State - var glucoseUnit: HKUnit = HKUnit.milligramsPerDeciliterUnit() + var glucoseUnit: HKUnit = HKUnit.milligramsPerDeciliter() var bolusRecommendation: BolusRecommendation? = nil { didSet { diff --git a/Loop/View Controllers/PredictionTableViewController.swift b/Loop/View Controllers/PredictionTableViewController.swift index 6b6dd76938..67cb1faa74 100644 --- a/Loop/View Controllers/PredictionTableViewController.swift +++ b/Loop/View Controllers/PredictionTableViewController.swift @@ -93,8 +93,8 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass, U let charts = StatusChartsManager(colors: .default, settings: .default) charts.glucoseDisplayRange = ( - min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 60), - max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 200) + min: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: 60), + max: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: 200) ) return charts diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index 8e4eb5d75c..b38af446b5 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -436,8 +436,8 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize let charts = StatusChartsManager(colors: .default, settings: .default) charts.glucoseDisplayRange = ( - min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 100), - max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 175) + min: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: 100), + max: HKQuantity(unit: HKUnit.milligramsPerDeciliter(), doubleValue: 175) ) return charts diff --git a/LoopUI/Managers/StatusChartsManager.swift b/LoopUI/Managers/StatusChartsManager.swift index ee8c6b650f..658ebb17f0 100644 --- a/LoopUI/Managers/StatusChartsManager.swift +++ b/LoopUI/Managers/StatusChartsManager.swift @@ -110,7 +110,7 @@ public final class StatusChartsManager { } } - public var glucoseUnit: HKUnit = HKUnit.milligramsPerDeciliterUnit() { + public var glucoseUnit: HKUnit = HKUnit.milligramsPerDeciliter() { didSet { if glucoseUnit != oldValue { // Regenerate the glucose display points @@ -695,7 +695,7 @@ public final class StatusChartsManager { private extension HKUnit { var glucoseUnitYAxisSegmentSize: Double { - if self == HKUnit.milligramsPerDeciliterUnit() { + if self == HKUnit.milligramsPerDeciliter() { return 25 } else { return 1