NightscoutTreatment.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Foundation
  2. struct NigtscoutTreatment: JSON, Hashable, Equatable {
  3. var duration: Int?
  4. var rawDuration: PumpHistoryEvent?
  5. var rawRate: PumpHistoryEvent?
  6. var absolute: Decimal?
  7. var rate: Decimal?
  8. var eventType: EventType
  9. var createdAt: Date?
  10. var enteredBy: String?
  11. var bolus: PumpHistoryEvent?
  12. var insulin: Decimal?
  13. var notes: String?
  14. var carbs: Decimal?
  15. var fat: Decimal?
  16. var protein: Decimal?
  17. var foodType: String?
  18. let targetTop: Decimal?
  19. let targetBottom: Decimal?
  20. static let local = "freeaps-x"
  21. static let empty = NigtscoutTreatment(from: "{}")!
  22. static func == (lhs: NigtscoutTreatment, rhs: NigtscoutTreatment) -> Bool {
  23. (lhs.createdAt ?? Date()) == (rhs.createdAt ?? Date())
  24. }
  25. func hash(into hasher: inout Hasher) {
  26. hasher.combine(createdAt ?? Date())
  27. }
  28. }
  29. extension NigtscoutTreatment {
  30. private enum CodingKeys: String, CodingKey {
  31. case duration
  32. case rawDuration = "raw_duration"
  33. case rawRate = "raw_rate"
  34. case absolute
  35. case rate
  36. case eventType
  37. case createdAt = "created_at"
  38. case enteredBy
  39. case bolus
  40. case insulin
  41. case notes
  42. case carbs
  43. case fat
  44. case protein
  45. case foodType
  46. case targetTop
  47. case targetBottom
  48. }
  49. }