Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
69ca2ef
Merge pull request #444 from LoopKit/master
ps2 Apr 9, 2017
d23893c
Loop data manager refactor (#446)
ps2 Apr 14, 2017
ff03199
Merge pull request #451 from LoopKit/master
ps2 Apr 20, 2017
84d345d
Eventual BG for dosing decisions should be no further out than insula…
ps2 Apr 22, 2017
56da5b3
Refactoring LoopDataManager prediction calculation (#449)
ps2 Apr 22, 2017
bacb88e
Update to RileyLink v1.0.1 and LoopKit v1.2.2 (#453)
ps2 Apr 24, 2017
503a614
Use standard forecast for bolus recommendations. (#454)
ps2 Apr 24, 2017
0bf85be
Swiftcharts update (#455)
ps2 Apr 27, 2017
a1a0340
update to rileylink_ios 1.1.0
ps2 May 12, 2017
5521476
Merge pull request #467 from LoopKit/rlkit-upgrade
ps2 May 12, 2017
d0f0fa0
renaming milligramsPerDeciliterUnit() to milligramsPerDeciliter()
ps2 May 13, 2017
e0705f4
Customizing bolus errors with new certainty distinction (#465)
ps2 May 13, 2017
1ae59e9
Merge pull request #468 from LoopKit/hkunit-rename
ps2 May 13, 2017
a93487b
Rethink the API for clients to read loop status; other cleanup.
ps2 May 13, 2017
f1411da
Update to LoopKit v1.3.0
ps2 May 14, 2017
e8dc095
Merge pull request #470 from LoopKit/loopkit-update
ps2 May 14, 2017
e01d4b2
Merge pull request #469 from LoopKit/get-loop-status
ps2 May 14, 2017
09430f3
prep version for release
ps2 May 14, 2017
39d3a79
Merge pull request #471 from LoopKit/version-bump
ps2 May 14, 2017
75da529
Merge branch 'master' into dev
ps2 May 14, 2017
08d1686
Store primes in dosestore
ps2 May 14, 2017
3e6bf0d
Merge pull request #473 from LoopKit/dose-store-primes
ps2 May 14, 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
6 changes: 3 additions & 3 deletions Common/Extensions/HKUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 11 additions & 13 deletions DoseMathTests/DoseMathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
)
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions Loop Status Extension/StatusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/DoseMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/StatusExtensionDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/WatchDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions Loop/Models/BolusRecommendation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -74,6 +75,7 @@ struct BolusRecommendation {
}
}


extension BolusRecommendation: Comparable {
static func ==(lhs: BolusRecommendation, rhs: BolusRecommendation) -> Bool {
return lhs.amount == rhs.amount
Expand Down
2 changes: 1 addition & 1 deletion Loop/Models/GlucoseG4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Loop/Models/ShareGlucose+GlucoseKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Loop/View Controllers/BolusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Loop/View Controllers/PredictionTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions LoopUI/Managers/StatusChartsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down