Determination.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: Int?
  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. extension Determination {
  34. private enum CodingKeys: String, CodingKey {
  35. case reason
  36. case units
  37. case insulinReq
  38. case eventualBG
  39. case sensitivityRatio
  40. case rate
  41. case duration
  42. case iob = "IOB"
  43. case cob = "COB"
  44. case predictions = "predBGs"
  45. case deliverAt
  46. case carbsReq
  47. case temp
  48. case bg
  49. case reservoir
  50. case timestamp
  51. case recieved
  52. case isf = "ISF"
  53. case tdd = "TDD"
  54. case insulin
  55. case current_target
  56. case insulinForManualBolus
  57. case manualBolusErrorString
  58. case minDelta
  59. case expectedDelta
  60. case minGuardBG
  61. case minPredBG
  62. case threshold
  63. case carbRatio = "CR"
  64. }
  65. }
  66. protocol DeterminationObserver {
  67. func determinationDidUpdate(_ determination: Determination)
  68. }
  69. // needed?
  70. protocol EnactedDeterminationObserver {
  71. func enactedSDeterminationDidUpdate(_ determination: Determination)
  72. }
  73. extension Determination {
  74. var reasonParts: [String] {
  75. reason.components(separatedBy: "; ").first?.components(separatedBy: ", ") ?? []
  76. }
  77. var reasonConclusion: String {
  78. reason.components(separatedBy: "; ").last ?? ""
  79. }
  80. }