Suggestion.swift 1.5 KB

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