Determination.swift 2.6 KB

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