| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import Foundation
- struct DeterminationErrorResponse: JSON, Equatable {
- let error: String
- }
- struct Determination: JSON, Equatable {
- let id: UUID?
- var reason: String
- let units: Decimal?
- let insulinReq: Decimal?
- var eventualBG: Int?
- let sensitivityRatio: Decimal?
- var rate: Decimal?
- var duration: Decimal?
- let iob: Decimal?
- let cob: Decimal?
- var predictions: Predictions?
- var deliverAt: Date?
- let carbsReq: Decimal?
- let temp: TempType?
- var bg: Decimal?
- let reservoir: Decimal?
- var isf: Decimal?
- var timestamp: Date?
- /// `tdd` (Total Daily Dose) is included so it can be part of the
- /// enacted and suggested devicestatus data that gets uploaded to Nightscout.
- var tdd: Decimal?
- var current_target: Decimal?
- var insulinForManualBolus: Decimal?
- var manualBolusErrorString: Decimal?
- var minDelta: Decimal?
- var expectedDelta: Decimal?
- var minGuardBG: Decimal?
- var minPredBG: Decimal?
- var threshold: Decimal?
- let carbRatio: Decimal?
- let received: Bool?
- }
- struct Predictions: JSON, Equatable {
- let iob: [Int]?
- let zt: [Int]?
- let cob: [Int]?
- let uam: [Int]?
- }
- extension Determination {
- private enum CodingKeys: String, CodingKey {
- case id
- case reason
- case units
- case insulinReq
- case eventualBG
- case sensitivityRatio
- case rate
- case duration
- case iob = "IOB"
- case cob = "COB"
- case predictions = "predBGs"
- case deliverAt
- case carbsReq
- case temp
- case bg
- case reservoir
- case timestamp
- case isf = "ISF"
- case current_target
- case tdd = "TDD"
- case insulinForManualBolus
- case manualBolusErrorString
- case minDelta
- case expectedDelta
- case minGuardBG
- case minPredBG
- case threshold
- case carbRatio = "CR"
- case received
- }
- }
- extension Predictions {
- private enum CodingKeys: String, CodingKey {
- case iob = "IOB"
- case zt = "ZT"
- case cob = "COB"
- case uam = "UAM"
- }
- }
- protocol DeterminationObserver {
- func determinationDidUpdate(_ determination: Determination)
- }
- extension Determination {
- var reasonParts: [String] {
- reason.components(separatedBy: "; ").first?.components(separatedBy: ", ") ?? []
- }
- var reasonConclusion: String {
- reason.components(separatedBy: "; ").last ?? ""
- }
- }
|