Suggestion.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import Foundation
  2. struct Suggestion: 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. var timestamp: Date?
  19. var recieved: Bool?
  20. var isNoTempRequired: Bool {
  21. reason.contains("no temp required")
  22. }
  23. }
  24. struct Predictions: JSON, Equatable {
  25. let iob: [Int]?
  26. let zt: [Int]?
  27. let cob: [Int]?
  28. let uam: [Int]?
  29. }
  30. extension Suggestion {
  31. private enum CodingKeys: String, CodingKey {
  32. case reason
  33. case units
  34. case insulinReq
  35. case eventualBG
  36. case sensitivityRatio
  37. case rate
  38. case duration
  39. case iob = "IOB"
  40. case cob = "COB"
  41. case predictions = "predBGs"
  42. case deliverAt
  43. case carbsReq
  44. case temp
  45. case bg
  46. case reservoir
  47. case timestamp
  48. case recieved
  49. }
  50. }
  51. extension Predictions {
  52. private enum CodingKeys: String, CodingKey {
  53. case iob = "IOB"
  54. case zt = "ZT"
  55. case cob = "COB"
  56. case uam = "UAM"
  57. }
  58. }
  59. protocol SuggestionObserver {
  60. func suggestionDidUpdate(_ suggestion: Suggestion)
  61. }
  62. protocol EnactedSuggestionObserver {
  63. func enactedSuggestionDidUpdate(_ suggestion: Suggestion)
  64. }