Explorar el Código

1: Add branch name in config and in DailyStats.
2: Filter for 1 day time interval in json arrays

Jon Mårtensson hace 3 años
padre
commit
592d6d302e

+ 1 - 0
Config.xcconfig

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

+ 2 - 0
FreeAPS/Resources/Info.plist

@@ -67,6 +67,8 @@
 	<string>Health App is used to store blood glucose data</string>
 	<key>NSHealthUpdateUsageDescription</key>
 	<string>Health App is used to store blood glucose data</string>
+	<key>NSHumanReadableCopyright</key>
+	<string>$(BRANCH)</string>
 	<key>UIApplicationSceneManifest</key>
 	<dict>
 		<key>UIApplicationSupportsMultipleScenes</key>

+ 0 - 19
FreeAPS/Resources/json/defaults/monitor/daily_stats.json

@@ -1,19 +0,0 @@
-{
-    "date" : "Empty Default JSON",
-    "FAX_Build_Number" : "Default",
-    "FAX_Build_Version" : "Default",
-    "FAX_Build_Date" : "Default",
-    "Algorithm" : "Default",
-    "AdjustmentFactor" : 1,
-    "Pump" : "Default",
-    "CGM" : "Default",
-    "insulinType" : "Default",
-    "peakActivityTime" : 65,
-    "TDD" : 0,
-    "Carbs_24h" : 0,
-    "Hypoglucemias_Percentage" : 0,
-    "TIR_Percentage" : 100,
-    "Hyperglucemias_Percentage" : 0,
-    "BG_daily_Average_mg_dl" : 100,
-    "id" : "Default JSON"
-  }

+ 30 - 24
FreeAPS/Sources/APS/APSManager.swift

@@ -764,9 +764,8 @@ final class BaseAPSManager: APSManager, Injectable {
 
         let nsObject: AnyObject? = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as AnyObject
         let version = nsObject as! String
-
         let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String
-
+        let branch = Bundle.main.infoDictionary?["NSHumanReadableCopyright"] as? String
         let pump_ = pumpManager?.localizedTitle ?? ""
         let cgm = settingsManager.settings.cgm
         let file = OpenAPS.Monitor.dailyStats
@@ -782,43 +781,50 @@ final class BaseAPSManager: APSManager, Injectable {
 
         let dailystat = DailyStats(
             date: date_,
+            FAX_Build_Version: version,
+            FAX_Build_Number: build ?? "1",
+            FAX_Branch: branch ?? "N/A",
+            FAX_Build_Date: buildDate,
+            Algorithm: algo_,
+            AdjustmentFactor: af,
             Pump: pump_,
             CGM: cgm.rawValue,
-            TIR_Percentage: tir().TIR,
+            insulinType: insulin_type.rawValue,
+            peakActivityTime: iPa,
+            TDD: currentTDD ?? 0,
+            Carbs_24h: carbTotal,
             Hypoglucemias_Percentage: tir().hypos,
+            TIR_Percentage: tir().TIR,
             Hyperglucemias_Percentage: tir().hypers,
             BG_daily_Average_mg_dl: bgAvg,
-            TDD: currentTDD ?? 0,
-            Carbs_24h: carbTotal,
-            Algorithm: algo_,
-            AdjustmentFactor: af,
-            insulinType: insulin_type.rawValue,
-            peakActivityTime: iPa,
-            FAX_Build_Version: version,
-            FAX_Build_Number: build ?? "1",
-            FAX_Build_Date: buildDate,
             id: UUID().uuidString
         )
 
-        let file_2 = storage.retrieve(OpenAPS.Monitor.dailyStats, as: [DailyStats].self)
+        var newEntries: [DailyStats] = []
+
+        // If file is empty
         let file_3 = loadFileFromStorage(name: OpenAPS.Monitor.dailyStats)
+        var isJSONempty = false
+        if file_3.rawJSON.isEmpty {
+            print("Empty")
+            isJSONempty = true
+        }
 
-        // If empty daily_stats.json, create a first entry
-        if file_2?[0].Algorithm == "Default", Calendar.current.component(.hour, from: Date()) == 23,
-           Calendar.current.component(.minute, from: Date()) > 45
-        {
-            storage.save(dailystat, as: file)
-        } else {
-            var newEntries: [DailyStats] = []
-            let isDateOldEnough = file_2?[0].date ?? Date("2999-10-24T14:29:23.893Z")
+        let now = Date()
+        let calender = Calendar.current
 
-            if Date() > isDateOldEnough!.addingTimeInterval(1.days.timeInterval),
-               Calendar.current.component(.hour, from: Date()) == 23, Calendar.current.component(.minute, from: Date()) > 45
-            {
+        // If current local time is 23:41 or later
+        if calender.component(.hour, from: now) > 22,
+           calender.component(.minute, from: now) > 40
+        {
+            if isJSONempty {
+                storage.save(dailystat, as: file)
+            } else {
                 storage.transaction { storage in
                     storage.append(dailystat, to: file, uniqBy: \.id)
                     newEntries = storage.retrieve(file, as: [DailyStats].self)?
                         .sorted { $0.date > $1.date } ?? []
+                        .filter { $0.date.addingTimeInterval(1.days.timeInterval) < now }
                     storage.save(Array(newEntries), as: file)
                 }
             }

+ 44 - 40
FreeAPS/Sources/Models/DailyStats.swift

@@ -2,58 +2,61 @@ import Foundation
 
 struct DailyStats: JSON, Equatable {
     var date: Date
+    var FAX_Build_Version: String
+    var FAX_Build_Number: String
+    var FAX_Branch: String
+    var FAX_Build_Date: Date
+    var Algorithm: String
+    var AdjustmentFactor: Decimal
     var Pump: String
     var CGM: String
-    var TIR_Percentage: Decimal
+    var insulinType: String
+    var peakActivityTime: Decimal
+    var TDD: Decimal
+    var Carbs_24h: Decimal
     var Hypoglucemias_Percentage: Decimal
+    var TIR_Percentage: Decimal
     var Hyperglucemias_Percentage: Decimal
     var BG_daily_Average_mg_dl: Decimal
-    var TDD: Decimal
-    var Carbs_24h: Decimal
-    var Algorithm: String
-    var AdjustmentFactor: Decimal
-    var insulinType: String
-    var peakActivityTime: Decimal
-    var FAX_Build_Version: String
-    var FAX_Build_Number: String
-    var FAX_Build_Date: Date
     var id: String
 
     init(
         date: Date,
+        FAX_Build_Version: String,
+        FAX_Build_Number: String,
+        FAX_Branch: String,
+        FAX_Build_Date: Date,
+        Algorithm: String,
+        AdjustmentFactor: Decimal,
         Pump: String,
         CGM: String,
-        TIR_Percentage: Decimal,
+        insulinType: String,
+        peakActivityTime: Decimal,
+        TDD: Decimal,
+        Carbs_24h: Decimal,
         Hypoglucemias_Percentage: Decimal,
+        TIR_Percentage: Decimal,
         Hyperglucemias_Percentage: Decimal,
         BG_daily_Average_mg_dl: Decimal,
-        TDD: Decimal,
-        Carbs_24h: Decimal,
-        Algorithm: String,
-        AdjustmentFactor: Decimal,
-        insulinType: String,
-        peakActivityTime: Decimal,
-        FAX_Build_Version: String,
-        FAX_Build_Number: String,
-        FAX_Build_Date: Date,
         id: String
     ) {
         self.date = date
+        self.FAX_Build_Version = FAX_Build_Version
+        self.FAX_Build_Number = FAX_Build_Number
+        self.FAX_Branch = FAX_Branch
+        self.FAX_Build_Date = FAX_Build_Date
+        self.Algorithm = Algorithm
+        self.AdjustmentFactor = AdjustmentFactor
         self.Pump = Pump
         self.CGM = CGM
-        self.TIR_Percentage = TIR_Percentage
+        self.insulinType = insulinType
+        self.peakActivityTime = peakActivityTime
+        self.TDD = TDD
+        self.Carbs_24h = Carbs_24h
         self.Hypoglucemias_Percentage = Hypoglucemias_Percentage
+        self.TIR_Percentage = TIR_Percentage
         self.Hyperglucemias_Percentage = Hyperglucemias_Percentage
         self.BG_daily_Average_mg_dl = BG_daily_Average_mg_dl
-        self.TDD = TDD
-        self.Carbs_24h = Carbs_24h
-        self.Algorithm = Algorithm
-        self.AdjustmentFactor = AdjustmentFactor
-        self.insulinType = insulinType
-        self.peakActivityTime = peakActivityTime
-        self.FAX_Build_Version = FAX_Build_Version
-        self.FAX_Build_Number = FAX_Build_Number
-        self.FAX_Build_Date = FAX_Build_Date
         self.id = id
     }
 }
@@ -61,21 +64,22 @@ struct DailyStats: JSON, Equatable {
 extension DailyStats {
     private enum CodingKeys: String, CodingKey {
         case date
+        case FAX_Build_Version
+        case FAX_Build_Number
+        case FAX_Branch
+        case FAX_Build_Date
+        case Algorithm
+        case AdjustmentFactor
         case Pump
         case CGM
-        case TIR_Percentage
+        case insulinType
+        case peakActivityTime
+        case TDD
+        case Carbs_24h
         case Hypoglucemias_Percentage
+        case TIR_Percentage
         case Hyperglucemias_Percentage
         case BG_daily_Average_mg_dl
-        case TDD
-        case Carbs_24h
-        case Algorithm
-        case AdjustmentFactor
-        case insulinType
-        case peakActivityTime
-        case FAX_Build_Version
-        case FAX_Build_Number
-        case FAX_Build_Date
         case id
     }
 }