LoopStatus.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // LoopStatus.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 7/26/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. import HealthKit
  10. public struct LoopStatus {
  11. let name: String
  12. let version: String
  13. let timestamp: Date
  14. let iob: IOBStatus?
  15. let cob: COBStatus?
  16. let predicted: PredictedBG?
  17. let automaticDoseRecommendation: AutomaticDoseRecommendation?
  18. let recommendedBolus: Double?
  19. let enacted: LoopEnacted?
  20. let rileylinks: [RileyLinkStatus]?
  21. let failureReason: Error?
  22. let currentCorrectionRange: CorrectionRange?
  23. let forecastError: ForecastError?
  24. let testingDetails: [String: Any]?
  25. public init(name: String, version: String, timestamp: Date, iob: IOBStatus? = nil, cob: COBStatus? = nil, predicted: PredictedBG? = nil, automaticDoseRecommendation: AutomaticDoseRecommendation? = nil, recommendedBolus: Double? = nil, enacted: LoopEnacted? = nil, rileylinks: [RileyLinkStatus]? = nil, failureReason: Error? = nil, currentCorrectionRange: CorrectionRange? = nil, forecastError: ForecastError? = nil, testingDetails: [String: Any]? = nil) {
  26. self.name = name
  27. self.version = version
  28. self.timestamp = timestamp
  29. self.iob = iob
  30. self.cob = cob
  31. self.predicted = predicted
  32. self.automaticDoseRecommendation = automaticDoseRecommendation
  33. self.recommendedBolus = recommendedBolus
  34. self.enacted = enacted
  35. self.rileylinks = rileylinks
  36. self.failureReason = failureReason
  37. self.currentCorrectionRange = currentCorrectionRange
  38. self.forecastError = forecastError
  39. self.testingDetails = testingDetails
  40. }
  41. public var dictionaryRepresentation: [String: Any] {
  42. var rval = [String: Any]()
  43. rval["name"] = name
  44. rval["version"] = version
  45. rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)
  46. if let iob = iob {
  47. rval["iob"] = iob.dictionaryRepresentation
  48. }
  49. if let cob = cob {
  50. rval["cob"] = cob.dictionaryRepresentation
  51. }
  52. if let predicted = predicted {
  53. rval["predicted"] = predicted.dictionaryRepresentation
  54. }
  55. if let automaticDoseRecommendation = automaticDoseRecommendation {
  56. rval["automaticDoseRecommendation"] = automaticDoseRecommendation.dictionaryRepresentation
  57. }
  58. if let recommendedBolus = recommendedBolus {
  59. rval["recommendedBolus"] = recommendedBolus
  60. }
  61. if let enacted = enacted {
  62. rval["enacted"] = enacted.dictionaryRepresentation
  63. }
  64. if let failureReason = failureReason {
  65. rval["failureReason"] = String(describing: failureReason)
  66. }
  67. if let rileylinks = rileylinks {
  68. rval["rileylinks"] = rileylinks.map { $0.dictionaryRepresentation }
  69. }
  70. if let currentCorrectionRange = currentCorrectionRange {
  71. rval["currentCorrectionRange"] = currentCorrectionRange.dictionaryRepresentation
  72. }
  73. if let forecastError = forecastError {
  74. rval["forecastError"] = forecastError.dictionaryRepresentation
  75. }
  76. if let testingDetails = testingDetails {
  77. rval["testingDetails"] = testingDetails
  78. }
  79. return rval
  80. }
  81. }