CorrectionRange.swift 798 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // CorrectionRange.swift
  3. // NightscoutUploadKit
  4. //
  5. // Created by Pete Schwamb on 5/28/18.
  6. // Copyright © 2018 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. import HealthKit
  10. public struct CorrectionRange {
  11. let minValue: Int
  12. let maxValue: Int
  13. public init(minValue: HKQuantity, maxValue: HKQuantity) {
  14. // BG values in nightscout are in mg/dL.
  15. let unit = HKUnit.milligramsPerDeciliterUnit()
  16. self.minValue = Int(round(minValue.doubleValue(for: unit)))
  17. self.maxValue = Int(round(maxValue.doubleValue(for: unit)))
  18. }
  19. public var dictionaryRepresentation: [String: Any] {
  20. var rval = [String: Any]()
  21. rval["minValue"] = minValue
  22. rval["maxValue"] = maxValue
  23. return rval
  24. }
  25. }