Jon Mårtensson 3 лет назад
Родитель
Сommit
bcf1e7ebd3
1 измененных файлов с 11 добавлено и 14 удалено
  1. 11 14
      FreeAPS/Sources/APS/APSManager.swift

+ 11 - 14
FreeAPS/Sources/APS/APSManager.swift

@@ -667,13 +667,10 @@ final class BaseAPSManager: APSManager, Injectable {
                 }
             }
             nightscout.uploadStatus()
-
             // Update the TDD value
             tdd(enacted_: enacted)
-            // Update statistics. Only run if enabled in preferences
-            // if settingsManager.settings.displayStatistics {
+            // Update statistics
             statistics()
-            // }
         }
     }
 
@@ -771,7 +768,7 @@ final class BaseAPSManager: APSManager, Injectable {
             testIfEmpty = testFile.count
         }
         let updateThisOften = Int(settingsManager.preferences.updateInterval)
-        // Only run every 30 minutes of according to setting.
+        // Only run every 30 minutes or according to setting.
         if testIfEmpty != 0 {
             guard testFile[0].created_at.addingTimeInterval(updateThisOften.minutes.timeInterval) < Date()
             else {
@@ -983,13 +980,13 @@ final class BaseAPSManager: APSManager, Injectable {
 
             try? glucose = coredataContext.fetch(requestGFS)
 
-            firstElementTime = glucose.first?.date ?? Date()
-            lastElementTime = glucose.last?.date ?? Date()
+            // Time In Range (%) and Average Glucose. This will be refactored later after some testing.
+            let endIndex = glucose.count - 1
 
-            currentIndexTime = firstElementTime
+            firstElementTime = glucose[0].date ?? Date()
+            lastElementTime = glucose[endIndex].date ?? Date()
 
-            // Time In Range (%) and Average Glucose (24 hours). This will be refactored later after some testing.
-            let endIndex = glucose.count - 1
+            currentIndexTime = firstElementTime
 
             numberOfDays = (firstElementTime - lastElementTime).timeInterval / 8.64E4
 
@@ -1003,23 +1000,23 @@ final class BaseAPSManager: APSManager, Injectable {
                         bgArray.append(Double(glucose[j].glucose) * Double(conversionFactor))
                         bgArrayForTIR.append((Double(glucose[j].glucose), glucose[j].date!))
                         nr_bgs += 1
-                        if (firstElementTime - currentIndexTime).timeInterval / 60 <= 8.64E4 { // 1 day
+                        if (firstElementTime - currentIndexTime).timeInterval <= 8.64E4 { // 1 day
                             bg_1 = bg / nr_bgs
                             bgArray_1 = bgArrayForTIR
                             bgArray_1_ = bgArray
                             nr1 = nr_bgs
                         }
-                        if (firstElementTime - currentIndexTime).timeInterval / 60 <= 6.048E5 { // 7 days
+                        if (firstElementTime - currentIndexTime).timeInterval <= 6.048E5 { // 7 days
                             bg_7 = bg / nr_bgs
                             bgArray_7 = bgArrayForTIR
                             bgArray_7_ = bgArray
                         }
-                        if (firstElementTime - currentIndexTime).timeInterval / 60 <= 2.592E6 { // 30 days
+                        if (firstElementTime - currentIndexTime).timeInterval <= 2.592E6 { // 30 days
                             bg_30 = bg / nr_bgs
                             bgArray_30 = bgArrayForTIR
                             bgArray_30_ = bgArray
                         }
-                        if (firstElementTime - currentIndexTime).timeInterval / 60 <= 7.776E7 { // 30 days
+                        if (firstElementTime - currentIndexTime).timeInterval <= 7.776E7 { // 30 days
                             bg_90 = bg / nr_bgs
                             bgArray_90 = bgArrayForTIR
                             bgArray_90_ = bgArray