Suggestion.swift 1.4 KB

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