Determination.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import Foundation
  2. struct Determination: JSON, Equatable {
  3. let id: UUID?
  4. let reason: String
  5. let units: Decimal?
  6. let insulinReq: Decimal?
  7. let eventualBG: Int?
  8. let sensitivityRatio: Decimal?
  9. let rate: Decimal?
  10. let duration: Decimal?
  11. let iob: Decimal?
  12. let cob: Decimal?
  13. var predictions: Predictions?
  14. var deliverAt: Date?
  15. let carbsReq: Decimal?
  16. let temp: TempType?
  17. let bg: Decimal?
  18. let reservoir: Decimal?
  19. let isf: Decimal?
  20. var timestamp: Date?
  21. var recieved: Bool?
  22. let tdd: Decimal?
  23. let insulin: Insulin?
  24. let current_target: Decimal?
  25. let insulinForManualBolus: Decimal?
  26. let manualBolusErrorString: Decimal?
  27. let minDelta: Decimal?
  28. let expectedDelta: Decimal?
  29. let minGuardBG: Decimal?
  30. let minPredBG: Decimal?
  31. let threshold: Decimal?
  32. let carbRatio: Decimal?
  33. let received: Bool?
  34. }
  35. struct Predictions: JSON, Equatable {
  36. let iob: [Int]?
  37. let zt: [Int]?
  38. let cob: [Int]?
  39. let uam: [Int]?
  40. }
  41. struct Insulin: JSON, Equatable {
  42. let TDD: Decimal?
  43. let bolus: Decimal?
  44. let temp_basal: Decimal?
  45. let scheduled_basal: Decimal?
  46. }
  47. extension Determination {
  48. private enum CodingKeys: String, CodingKey {
  49. case id
  50. case reason
  51. case units
  52. case insulinReq
  53. case eventualBG
  54. case sensitivityRatio
  55. case rate
  56. case duration
  57. case iob = "IOB"
  58. case cob = "COB"
  59. case predictions = "predBGs"
  60. case deliverAt
  61. case carbsReq
  62. case temp
  63. case bg
  64. case reservoir
  65. case timestamp
  66. case recieved
  67. case isf = "ISF"
  68. case tdd = "TDD"
  69. case insulin
  70. case current_target
  71. case insulinForManualBolus
  72. case manualBolusErrorString
  73. case minDelta
  74. case expectedDelta
  75. case minGuardBG
  76. case minPredBG
  77. case threshold
  78. case carbRatio = "CR"
  79. case received
  80. }
  81. }
  82. extension Predictions {
  83. private enum CodingKeys: String, CodingKey {
  84. case iob = "IOB"
  85. case zt = "ZT"
  86. case cob = "COB"
  87. case uam = "UAM"
  88. }
  89. }
  90. extension Insulin {
  91. private enum CodingKeys: String, CodingKey {
  92. case TDD
  93. case bolus
  94. case temp_basal
  95. case scheduled_basal
  96. }
  97. }
  98. protocol DeterminationObserver {
  99. func determinationDidUpdate(_ determination: Determination)
  100. }
  101. extension Determination {
  102. var reasonParts: [String] {
  103. reason.components(separatedBy: "; ").first?.components(separatedBy: ", ") ?? []
  104. }
  105. var reasonConclusion: String {
  106. reason.components(separatedBy: "; ").last ?? ""
  107. }
  108. }