IOBStatus.swift 862 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // IOBStatus.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 7/28/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct IOBStatus {
  10. let timestamp: Date
  11. let iob: Double? // basal iob + bolus iob: can be negative
  12. let basalIOB: Double? // does not include bolus iob
  13. public init(timestamp: Date, iob: Double? = nil, basalIOB: Double? = nil) {
  14. self.timestamp = timestamp
  15. self.iob = iob
  16. self.basalIOB = basalIOB
  17. }
  18. public var dictionaryRepresentation: [String: Any] {
  19. var rval = [String: Any]()
  20. rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)
  21. if let iob = iob {
  22. rval["iob"] = iob
  23. }
  24. if let basalIOB = basalIOB {
  25. rval["basaliob"] = basalIOB
  26. }
  27. return rval
  28. }
  29. }