NightscoutTreatment.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. let targetTop: Decimal?
  16. let targetBottom: Decimal?
  17. static let local = "freeaps-x"
  18. static let empty = NigtscoutTreatment(from: "{}")!
  19. static func == (lhs: NigtscoutTreatment, rhs: NigtscoutTreatment) -> Bool {
  20. (lhs.createdAt ?? Date()) == (rhs.createdAt ?? Date())
  21. }
  22. func hash(into hasher: inout Hasher) {
  23. hasher.combine(createdAt ?? Date())
  24. }
  25. }
  26. extension NigtscoutTreatment {
  27. private enum CodingKeys: String, CodingKey {
  28. case duration
  29. case rawDuration = "raw_duration"
  30. case rawRate = "raw_rate"
  31. case absolute
  32. case rate
  33. case eventType
  34. case createdAt = "created_at"
  35. case enteredBy
  36. case bolus
  37. case insulin
  38. case notes
  39. case carbs
  40. case targetTop
  41. case targetBottom
  42. }
  43. }