Pārlūkot izejas kodu

guard for empty glucose.json

Jon Mårtensson 3 gadi atpakaļ
vecāks
revīzija
170be3a2e0
2 mainītis faili ar 5 papildinājumiem un 5 dzēšanām
  1. 1 1
      Config.xcconfig
  2. 4 4
      FreeAPS/Sources/APS/APSManager.swift

+ 1 - 1
Config.xcconfig

@@ -1,7 +1,7 @@
 APP_DISPLAY_NAME = FreeAPS X
 APP_DISPLAY_NAME = FreeAPS X
 APP_VERSION = 0.2.9
 APP_VERSION = 0.2.9
 APP_BUILD_NUMBER = 1
 APP_BUILD_NUMBER = 1
-BRANCH = Test_new_json
+BRANCH = DailyStats
 DEVELOPER_TEAM = ##TEAM_ID##
 DEVELOPER_TEAM = ##TEAM_ID##
 BUNDLE_IDENTIFIER = ru.artpancreas.$(DEVELOPMENT_TEAM).FreeAPS
 BUNDLE_IDENTIFIER = ru.artpancreas.$(DEVELOPMENT_TEAM).FreeAPS
 APP_GROUP_ID = group.com.$(DEVELOPMENT_TEAM).loopkit.LoopGroup
 APP_GROUP_ID = group.com.$(DEVELOPMENT_TEAM).loopkit.LoopGroup

+ 4 - 4
FreeAPS/Sources/APS/APSManager.swift

@@ -837,13 +837,12 @@ final class BaseAPSManager: APSManager, Injectable {
         let length_ = glucose!.count
         let length_ = glucose!.count
         let endIndex = length_ - 1
         let endIndex = length_ - 1
 
 
-        let fullTime = glucose![0].date - glucose![endIndex].date
-
-        // If empty json
-        guard fullTime != 0 else {
+        guard glucose?[0].date != nil else {
+            print("glucose.json is empty")
             return (0, 0, 0)
             return (0, 0, 0)
         }
         }
 
 
+        let fullTime = glucose![0].date - glucose![endIndex].date
         var timeInHypo: Decimal = 0
         var timeInHypo: Decimal = 0
         var timeInHyper: Decimal = 0
         var timeInHyper: Decimal = 0
         var hypos: Decimal = 0
         var hypos: Decimal = 0
@@ -886,6 +885,7 @@ final class BaseAPSManager: APSManager, Injectable {
         let hyperRounded = round(Double(hypers) * 10) / 10
         let hyperRounded = round(Double(hypers) * 10) / 10
         let TIRrounded = round((100 - (hypoRounded + hyperRounded)) * 10) / 10
         let TIRrounded = round((100 - (hypoRounded + hyperRounded)) * 10) / 10
 
 
+        // For testing. See in Xcode console each loop.
         print("TIR: \(TIRrounded) %, Hypos: \(hypoRounded) %, Hypers: \(hyperRounded) %")
         print("TIR: \(TIRrounded) %, Hypos: \(hypoRounded) %, Hypers: \(hyperRounded) %")
 
 
         return (Decimal(hypoRounded), Decimal(hyperRounded), Decimal(TIRrounded))
         return (Decimal(hypoRounded), Decimal(hyperRounded), Decimal(TIRrounded))