Determination.swift 2.6 KB

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