|
|
@@ -34,7 +34,33 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
(lhs.createdAt ?? Date()) == (rhs.createdAt ?? Date())
|
|
|
}
|
|
|
|
|
|
- static func from(event: PumpHistoryEvent, tempBasalDuration: PumpHistoryEvent? = nil) -> Self? {
|
|
|
+ func hash(into hasher: inout Hasher) {
|
|
|
+ hasher.combine(createdAt ?? Date())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension NightscoutTreatment {
|
|
|
+ private enum CodingKeys: String, CodingKey {
|
|
|
+ case duration
|
|
|
+ case rawDuration = "raw_duration"
|
|
|
+ case rawRate = "raw_rate"
|
|
|
+ case absolute
|
|
|
+ case rate
|
|
|
+ case eventType
|
|
|
+ case createdAt = "created_at"
|
|
|
+ case enteredBy
|
|
|
+ case bolus
|
|
|
+ case insulin
|
|
|
+ case notes
|
|
|
+ case carbs
|
|
|
+ case fat
|
|
|
+ case protein
|
|
|
+ case foodType
|
|
|
+ case targetTop
|
|
|
+ case targetBottom
|
|
|
+ }
|
|
|
+
|
|
|
+ init?(event: PumpHistoryEvent, tempBasalDuration: PumpHistoryEvent? = nil) {
|
|
|
var basalDurationEvent: PumpHistoryEvent?
|
|
|
if tempBasalDuration != nil, tempBasalDuration?.timestamp == event.timestamp, event.type == .tempBasal,
|
|
|
tempBasalDuration?.type == .tempBasalDuration
|
|
|
@@ -43,7 +69,7 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
}
|
|
|
switch event.type {
|
|
|
case .tempBasal:
|
|
|
- return NightscoutTreatment(
|
|
|
+ self.init(
|
|
|
duration: basalDurationEvent?.durationMin,
|
|
|
rawDuration: basalDurationEvent,
|
|
|
rawRate: event,
|
|
|
@@ -63,7 +89,7 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
)
|
|
|
case .bolus:
|
|
|
let eventType = determineBolusEventType(for: event)
|
|
|
- return NightscoutTreatment(
|
|
|
+ self.init(
|
|
|
duration: event.duration,
|
|
|
rawDuration: nil,
|
|
|
rawRate: nil,
|
|
|
@@ -82,7 +108,7 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
targetBottom: nil
|
|
|
)
|
|
|
case .journalCarbs:
|
|
|
- return NightscoutTreatment(
|
|
|
+ self.init(
|
|
|
duration: nil,
|
|
|
rawDuration: nil,
|
|
|
rawRate: nil,
|
|
|
@@ -101,7 +127,7 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
targetBottom: nil
|
|
|
)
|
|
|
case .prime:
|
|
|
- return NightscoutTreatment(
|
|
|
+ self.init(
|
|
|
duration: event.duration,
|
|
|
rawDuration: nil,
|
|
|
rawRate: nil,
|
|
|
@@ -120,7 +146,7 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
targetBottom: nil
|
|
|
)
|
|
|
case .rewind:
|
|
|
- return NightscoutTreatment(
|
|
|
+ self.init(
|
|
|
duration: nil,
|
|
|
rawDuration: nil,
|
|
|
rawRate: nil,
|
|
|
@@ -139,7 +165,7 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
targetBottom: nil
|
|
|
)
|
|
|
case .pumpAlarm:
|
|
|
- return NightscoutTreatment(
|
|
|
+ self.init(
|
|
|
duration: 30, // minutes
|
|
|
rawDuration: nil,
|
|
|
rawRate: nil,
|
|
|
@@ -161,30 +187,4 @@ struct NightscoutTreatment: JSON, Hashable, Equatable {
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func hash(into hasher: inout Hasher) {
|
|
|
- hasher.combine(createdAt ?? Date())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension NightscoutTreatment {
|
|
|
- private enum CodingKeys: String, CodingKey {
|
|
|
- case duration
|
|
|
- case rawDuration = "raw_duration"
|
|
|
- case rawRate = "raw_rate"
|
|
|
- case absolute
|
|
|
- case rate
|
|
|
- case eventType
|
|
|
- case createdAt = "created_at"
|
|
|
- case enteredBy
|
|
|
- case bolus
|
|
|
- case insulin
|
|
|
- case notes
|
|
|
- case carbs
|
|
|
- case fat
|
|
|
- case protein
|
|
|
- case foodType
|
|
|
- case targetTop
|
|
|
- case targetBottom
|
|
|
- }
|
|
|
}
|