HomeProvider.swift 925 B

12345678910111213141516171819202122232425262728293031
  1. import Foundation
  2. import SwiftDate
  3. extension Home {
  4. final class Provider: BaseProvider, HomeProvider {
  5. @Injected() var apsManager: APSManager!
  6. @Injected() var glucoseStorage: GlucoseStorage!
  7. @Injected() var pumpHistoryStorage: PumpHistoryStorage!
  8. var suggestion: Suggestion? {
  9. try? storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
  10. }
  11. func fetchAndLoop() {
  12. apsManager.fetchAndLoop()
  13. }
  14. func filteredGlucose(hours: Int) -> [BloodGlucose] {
  15. glucoseStorage.recent().filter {
  16. $0.dateString.addingTimeInterval(hours.hours.timeInterval) > Date()
  17. }
  18. }
  19. func pumpHistory(hours: Int) -> [PumpHistoryEvent] {
  20. pumpHistoryStorage.recent().filter {
  21. $0.timestamp.addingTimeInterval(hours.hours.timeInterval) > Date()
  22. }
  23. }
  24. }
  25. }