Parcourir la source

Backfill glucose from NS

Ivan Valkou il y a 4 ans
Parent
commit
2889371642
25 fichiers modifiés avec 91 ajouts et 10 suppressions
  1. 3 0
      FreeAPS/Sources/Localizations/Main/ar.lproj/Localizable.strings
  2. 3 0
      FreeAPS/Sources/Localizations/Main/ca.lproj/Localizable.strings
  3. 3 0
      FreeAPS/Sources/Localizations/Main/da.lproj/Localizable.strings
  4. 3 0
      FreeAPS/Sources/Localizations/Main/de.lproj/Localizable.strings
  5. 3 0
      FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings
  6. 3 0
      FreeAPS/Sources/Localizations/Main/es.lproj/Localizable.strings
  7. 3 0
      FreeAPS/Sources/Localizations/Main/fi.lproj/Localizable.strings
  8. 3 0
      FreeAPS/Sources/Localizations/Main/fr.lproj/Localizable.strings
  9. 3 0
      FreeAPS/Sources/Localizations/Main/he.lproj/Localizable.strings
  10. 3 0
      FreeAPS/Sources/Localizations/Main/it.lproj/Localizable.strings
  11. 3 0
      FreeAPS/Sources/Localizations/Main/nb.lproj/Localizable.strings
  12. 3 0
      FreeAPS/Sources/Localizations/Main/nl.lproj/Localizable.strings
  13. 3 0
      FreeAPS/Sources/Localizations/Main/pl.lproj/Localizable.strings
  14. 3 0
      FreeAPS/Sources/Localizations/Main/pt-BR.lproj/Localizable.strings
  15. 3 0
      FreeAPS/Sources/Localizations/Main/pt-PT.lproj/Localizable.strings
  16. 3 0
      FreeAPS/Sources/Localizations/Main/ru.lproj/Localizable.strings
  17. 3 0
      FreeAPS/Sources/Localizations/Main/sk.lproj/Localizable.strings
  18. 3 0
      FreeAPS/Sources/Localizations/Main/sv.lproj/Localizable.strings
  19. 3 0
      FreeAPS/Sources/Localizations/Main/tr.lproj/Localizable.strings
  20. 3 0
      FreeAPS/Sources/Localizations/Main/uk.lproj/Localizable.strings
  21. 3 0
      FreeAPS/Sources/Localizations/Main/zh-Hans.lproj/Localizable.strings
  22. 18 1
      FreeAPS/Sources/Modules/NightscoutConfig/NightscoutConfigStateModel.swift
  23. 5 0
      FreeAPS/Sources/Modules/NightscoutConfig/View/NightscoutConfigRootView.swift
  24. 4 5
      FreeAPS/Sources/Services/Network/NightscoutManager.swift
  25. 1 4
      FreeAPS/Sources/Services/WatchManager/WatchManager.swift

+ 3 - 0
FreeAPS/Sources/Localizations/Main/ar.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/ca.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/da.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/de.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -854,6 +854,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/es.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/fi.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/fr.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/he.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/it.lproj/Localizable.strings

@@ -854,6 +854,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Mostra il glucosio sul badge dell'app";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/nb.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/nl.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/pl.lproj/Localizable.strings

@@ -855,6 +855,9 @@ Połączono z Nightscout!";
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/pt-BR.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/pt-PT.lproj/Localizable.strings

@@ -422,6 +422,9 @@ Enact a temp Basal or a temp target */
 /* Other CGM setting */
 "Other" = "Other";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 /*
   Infotexts from openaps.docs and androidaps.docs
   FreeAPS

+ 3 - 0
FreeAPS/Sources/Localizations/Main/ru.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Показывать глюкозу на значке приложения";
 
+/* */
+"Backfill glucose" = "Скачать глюкозу";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/sk.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/sv.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Visa glukosvärde på app-ikon";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/tr.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Uygulama rozetinde glikozu göster";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/uk.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/zh-Hans.lproj/Localizable.strings

@@ -853,6 +853,9 @@ Enact a temp Basal or a temp target */
 /* Glucose badge */
 "Show glucose on the app badge" = "Show glucose on the app badge";
 
+/* */
+"Backfill glucose" = "Backfill glucose";
+
 
 /* Headers for settings ------------------- */
 

+ 18 - 1
FreeAPS/Sources/Modules/NightscoutConfig/NightscoutConfigStateModel.swift

@@ -1,14 +1,18 @@
 import Combine
+import SwiftDate
 import SwiftUI
 
 extension NightscoutConfig {
     final class StateModel: BaseStateModel<Provider> {
-        @Injected() var keychain: Keychain!
+        @Injected() private var keychain: Keychain!
+        @Injected() private var nightscoutManager: NightscoutManager!
+        @Injected() private var glucoseStorage: GlucoseStorage!
 
         @Published var url = ""
         @Published var secret = ""
         @Published var message = ""
         @Published var connecting = false
+        @Published var backfilling = false
         @Published var isUploadEnabled = false
 
         @Published var useLocalSource = false
@@ -47,6 +51,19 @@ extension NightscoutConfig {
                 .store(in: &lifetime)
         }
 
+        func backfillGlucose() {
+            backfilling = true
+            nightscoutManager.fetchGlucose(since: Date().addingTimeInterval(-1.days.timeInterval))
+                .sink { [weak self] glucose in
+                    guard let self = self, glucose.isNotEmpty else { return }
+                    self.glucoseStorage.storeGlucose(glucose)
+                    DispatchQueue.main.async {
+                        self.backfilling = false
+                    }
+                }
+                .store(in: &lifetime)
+        }
+
         func delete() {
             keychain.removeObject(forKey: Config.urlKey)
             keychain.removeObject(forKey: Config.secretKey)

+ 5 - 0
FreeAPS/Sources/Modules/NightscoutConfig/View/NightscoutConfigRootView.swift

@@ -54,6 +54,11 @@ extension NightscoutConfig {
                         DecimalTextField("", value: $state.localPort, formatter: portFormater)
                     }
                 }
+
+                Section {
+                    Button("Backfill glucose") { state.backfillGlucose() }
+                        .disabled(state.url.isEmpty || state.connecting || state.backfilling)
+                }
             }
             .onAppear(perform: configureView)
             .navigationBarTitle("Nightscout Config")

+ 4 - 5
FreeAPS/Sources/Services/Network/NightscoutManager.swift

@@ -4,7 +4,7 @@ import Swinject
 import UIKit
 
 protocol NightscoutManager: GlucoseSource {
-    func fetchGlucose() -> AnyPublisher<[BloodGlucose], Never>
+    func fetchGlucose(since date: Date) -> AnyPublisher<[BloodGlucose], Never>
     func fetchCarbs() -> AnyPublisher<[CarbsEntry], Never>
     func fetchTempTargets() -> AnyPublisher<[TempTarget], Never>
     func fetchAnnouncements() -> AnyPublisher<[Announcement], Never>
@@ -88,7 +88,7 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         return maybeNightscout?.url
     }
 
-    func fetchGlucose() -> AnyPublisher<[BloodGlucose], Never> {
+    func fetchGlucose(since date: Date) -> AnyPublisher<[BloodGlucose], Never> {
         let useLocal = settingsManager.settings.useLocalGlucoseSource
         ping = nil
 
@@ -108,8 +108,7 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
 
         let startDate = Date()
 
-        let since = glucoseStorage.syncDate()
-        return nightscout.fetchLastGlucose(sinceDate: since)
+        return nightscout.fetchLastGlucose(sinceDate: date)
             .tryCatch({ (error) -> AnyPublisher<[BloodGlucose], Error> in
                 print(error.localizedDescription)
                 return Just([]).setFailureType(to: Error.self).eraseToAnyPublisher()
@@ -123,7 +122,7 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
     }
 
     func fetch() -> AnyPublisher<[BloodGlucose], Never> {
-        fetchGlucose()
+        fetchGlucose(since: glucoseStorage.syncDate())
     }
 
     func fetchCarbs() -> AnyPublisher<[CarbsEntry], Never> {

+ 1 - 4
FreeAPS/Sources/Services/WatchManager/WatchManager.swift

@@ -91,10 +91,7 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
             warning(.service, "Cannot encode watch state")
             return
         }
-        guard session.isReachable else {
-            warning(.service, "WCSession is not reachable")
-            return
-        }
+        guard session.isReachable else { return }
         session.sendMessageData(data, replyHandler: nil) { error in
             warning(.service, "Cannot send message to watch", error: error)
         }