Determination.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. var current_target: Decimal?
  22. let insulinForManualBolus: Decimal?
  23. let manualBolusErrorString: Decimal?
  24. var minDelta: Decimal?
  25. var expectedDelta: Decimal?
  26. var minGuardBG: Decimal?
  27. var minPredBG: Decimal?
  28. var threshold: Decimal?
  29. let carbRatio: Decimal?
  30. let received: Bool?
  31. }
  32. struct Predictions: JSON, Equatable {
  33. let iob: [Int]?
  34. let zt: [Int]?
  35. let cob: [Int]?
  36. let uam: [Int]?
  37. }
  38. extension Determination {
  39. private enum CodingKeys: String, CodingKey {
  40. case id
  41. case reason
  42. case units
  43. case insulinReq
  44. case eventualBG
  45. case sensitivityRatio
  46. case rate
  47. case duration
  48. case iob = "IOB"
  49. case cob = "COB"
  50. case predictions = "predBGs"
  51. case deliverAt
  52. case carbsReq
  53. case temp
  54. case bg
  55. case reservoir
  56. case timestamp
  57. case isf = "ISF"
  58. case current_target
  59. case insulinForManualBolus
  60. case manualBolusErrorString
  61. case minDelta
  62. case expectedDelta
  63. case minGuardBG
  64. case minPredBG
  65. case threshold
  66. case carbRatio = "CR"
  67. case received
  68. }
  69. }
  70. extension Predictions {
  71. private enum CodingKeys: String, CodingKey {
  72. case iob = "IOB"
  73. case zt = "ZT"
  74. case cob = "COB"
  75. case uam = "UAM"
  76. }
  77. }
  78. protocol DeterminationObserver {
  79. func determinationDidUpdate(_ determination: Determination)
  80. }
  81. extension Determination {
  82. var reasonParts: [String] {
  83. reason.components(separatedBy: "; ").first?.components(separatedBy: ", ") ?? []
  84. }
  85. var reasonConclusion: String {
  86. reason.components(separatedBy: "; ").last ?? ""
  87. }
  88. }