forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopSettings.swift
More file actions
91 lines (64 loc) · 2.63 KB
/
LoopSettings.swift
File metadata and controls
91 lines (64 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// LoopSettings.swift
// Loop
//
// Copyright © 2017 LoopKit Authors. All rights reserved.
//
import LoopKit
import RileyLinkBLEKit
struct LoopSettings {
var dosingEnabled = false
let dynamicCarbAbsorptionEnabled = true
var glucoseTargetRangeSchedule: GlucoseRangeSchedule?
var maximumBasalRatePerHour: Double?
var maximumBolus: Double?
var maximumInsulinOnBoard: Double?
var suspendThreshold: GlucoseThreshold? = nil
var retrospectiveCorrectionEnabled = true
let retrospectiveCorrectionInterval = TimeInterval(minutes: 30)
/// The amount of time since a given date that data should be considered valid
let recencyInterval = TimeInterval(minutes: 15)
// MARK - Display settings
let minimumChartWidthPerHour: CGFloat = 50
let statusChartMinimumHistoryDisplay: TimeInterval = .hours(1)
}
extension LoopSettings: RawRepresentable {
typealias RawValue = [String: Any]
private static let version = 1
init?(rawValue: RawValue) {
guard
let version = rawValue["version"] as? Int,
version == LoopSettings.version
else {
return nil
}
if let dosingEnabled = rawValue["dosingEnabled"] as? Bool {
self.dosingEnabled = dosingEnabled
}
if let rawValue = rawValue["glucoseTargetRangeSchedule"] as? GlucoseRangeSchedule.RawValue {
self.glucoseTargetRangeSchedule = GlucoseRangeSchedule(rawValue: rawValue)
}
self.maximumBasalRatePerHour = rawValue["maximumBasalRatePerHour"] as? Double
self.maximumInsulinOnBoard = rawValue["maximumInsulinOnBoard"] as? Double
self.maximumBolus = rawValue["maximumBolus"] as? Double
if let rawThreshold = rawValue["minimumBGGuard"] as? GlucoseThreshold.RawValue {
self.suspendThreshold = GlucoseThreshold(rawValue: rawThreshold)
}
if let retrospectiveCorrectionEnabled = rawValue["retrospectiveCorrectionEnabled"] as? Bool {
self.retrospectiveCorrectionEnabled = retrospectiveCorrectionEnabled
}
}
var rawValue: RawValue {
var raw: RawValue = [
"version": LoopSettings.version,
"dosingEnabled": dosingEnabled,
"retrospectiveCorrectionEnabled": retrospectiveCorrectionEnabled
]
raw["glucoseTargetRangeSchedule"] = glucoseTargetRangeSchedule?.rawValue
raw["maximumBasalRatePerHour"] = maximumBasalRatePerHour
raw["maximumInsulinOnBoard"] = maximumInsulinOnBoard
raw["maximumBolus"] = maximumBolus
raw["minimumBGGuard"] = suspendThreshold?.rawValue
return raw
}
}