Просмотр исходного кода

DynISF
decrease max size of glucose.json (2 days instead of 10).
Disable dynISF first 21 hours with an empty pump history, to prevent to small dynamic ratios.
Some formatting.
Version update.

Jon Mårtensson 3 лет назад
Родитель
Сommit
0988cceecf

+ 1 - 1
Config.xcconfig

@@ -1,5 +1,5 @@
 APP_DISPLAY_NAME = FreeAPS X
-APP_VERSION = 0.4.1
+APP_VERSION = 0.4.2
 APP_BUILD_NUMBER = 1
 BRANCH = bdb
 DEVELOPER_TEAM = ##TEAM_ID##

+ 4 - 4
FreeAPS.xcodeproj/project.pbxproj

@@ -16,7 +16,7 @@
 		19012CDC291D2CB900FB8210 /* LoopStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19012CDB291D2CB900FB8210 /* LoopStats.swift */; };
 		1927C8E62744606D00347C69 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1927C8E82744606D00347C69 /* InfoPlist.strings */; };
 		1935364028496F7D001E0B16 /* TDD_averages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1935363F28496F7D001E0B16 /* TDD_averages.swift */; };
-		193B6FAA291AB9AC0087410F /* TenDaysStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193B6FA9291AB9AC0087410F /* TenDaysStats.swift */; };
+		193B6FAA291AB9AC0087410F /* TwoDaysStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193B6FA9291AB9AC0087410F /* TwoDaysStats.swift */; };
 		19795118275953E50044850D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 198377D4266BFFF6004DE65E /* Localizable.strings */; };
 		198377D2266BFFF6004DE65E /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 198377D4266BFFF6004DE65E /* Localizable.strings */; };
 		199561C1275E61A50077B976 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 199561C0275E61A50077B976 /* HealthKit.framework */; };
@@ -443,7 +443,7 @@
 		1927C8FB2744612600347C69 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1927C8FE274489BA00347C69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1935363F28496F7D001E0B16 /* TDD_averages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TDD_averages.swift; sourceTree = "<group>"; };
-		193B6FA9291AB9AC0087410F /* TenDaysStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TenDaysStats.swift; sourceTree = "<group>"; };
+		193B6FA9291AB9AC0087410F /* TwoDaysStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoDaysStats.swift; sourceTree = "<group>"; };
 		198377D3266BFFF6004DE65E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
 		198377D5266C0A05004DE65E /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = "<group>"; };
 		198377D6266C0A0A004DE65E /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -1342,7 +1342,7 @@
 				1935363F28496F7D001E0B16 /* TDD_averages.swift */,
 				CE82E02628E869DF00473A9C /* AlertEntry.swift */,
 				19B0EF2028F6D66200069496 /* DailyStats.swift */,
-				193B6FA9291AB9AC0087410F /* TenDaysStats.swift */,
+				193B6FA9291AB9AC0087410F /* TwoDaysStats.swift */,
 				19012CDB291D2CB900FB8210 /* LoopStats.swift */,
 			);
 			path = Models;
@@ -2309,7 +2309,7 @@
 				389ECDFE2601061500D86C4F /* View+Snapshot.swift in Sources */,
 				38FEF3FE2738083E00574A46 /* CGMProvider.swift in Sources */,
 				38E98A3725F5509500C0CED0 /* String+Extensions.swift in Sources */,
-				193B6FAA291AB9AC0087410F /* TenDaysStats.swift in Sources */,
+				193B6FAA291AB9AC0087410F /* TwoDaysStats.swift in Sources */,
 				F90692D1274B99B60037068D /* HealthKitProvider.swift in Sources */,
 				385CEAC125F2EA52002D6D5B /* Announcement.swift in Sources */,
 				8B759CFCF47B392BB365C251 /* BasalProfileEditorDataFlow.swift in Sources */,

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/determine-basal.js


FreeAPS/Resources/json/defaults/freeaps/announcements.json → FreeAPS/Resources/json/defaults/announcements.json


FreeAPS/Resources/json/defaults/monitor/tenDaysStats.json → FreeAPS/Resources/json/defaults/monitor/twoDaysStats.json


+ 52 - 51
FreeAPS/Sources/APS/APSManager.swift

@@ -909,11 +909,9 @@ final class BaseAPSManager: APSManager, Injectable {
         var nr_bgs: Decimal = 0
         let startDate = glucose![0].date
         var end1 = false
-        var end7 = false
-        var end10 = false
+        var end2 = false
         var bg_1: Decimal = 0
-        var bg_7: Decimal = 0
-        var bg_10: Decimal = 0
+        var bg_2: Decimal = 0
         var bg_total: Decimal = 0
         var j = -1
 
@@ -930,21 +928,17 @@ final class BaseAPSManager: APSManager, Injectable {
                         oneDayGlucoseIndex = j
                         bg_1 = bg / nr_bgs
                     }
-
-                    if startDate - entry.date >= 6.045E8, !end7 {
-                        end7 = true
-                        bg_7 = bg / nr_bgs
-                    }
-
-                    if startDate - entry.date >= 8.64E8, !end10 {
-                        end10 = true
-                        bg_10 = bg / nr_bgs
+                    if startDate - entry.date >= 1.72E8, !end2 {
+                        end2 = true
+                        oneDayGlucoseIndex = j
+                        bg_2 = bg / nr_bgs
                     }
                 }
             }
         }
 
         if nr_bgs != 0 {
+            // Up tp two days
             bg_total = bg / nr_bgs
         }
 
@@ -1032,34 +1026,34 @@ final class BaseAPSManager: APSManager, Injectable {
 
         let TIR_1 = 100 - (hypos_1 + hypers_1)
 
-        // Add 10 day average to tenDaysStats.json
-        let file_10 = OpenAPS.Monitor.tenDaysStats
-        // let tensDaysStats = storage.retrieve(file_10, as: [TenDaysStats].self)
+        // Add a 2 day average to twoDaysStats.json
+        let file_10 = OpenAPS.Monitor.twoDaysStats
 
-        let tenStats = TenDaysStats(
-            createdAt: Date(), past10daysAverage: roundDecimal(bg_10, 1)
+        let twoStats = TwoDaysStats(
+            createdAt: Date(), past2daysAverage: roundDecimal(bg_2, 1)
         )
-        var uniqEvents: [TenDaysStats] = []
+        var uniqEvents: [TwoDaysStats] = []
         var test1 = uniqEvents
-        let test2: [TenDaysStats] = [tenStats]
+        let test2: [TwoDaysStats] = [twoStats]
         var countIndeces = 0
 
         storage.transaction { storage in
-            test1 = storage.retrieve(file_10, as: [TenDaysStats].self) ?? []
+            test1 = storage.retrieve(file_10, as: [TwoDaysStats].self) ?? []
             countIndeces = test1.count
         }
 
-        if daysBG >= 10 {
+        if daysBG >= 2 {
             if countIndeces == 0 {
                 storage.transaction { storage in
                     storage.save(test2, as: file_10)
+                    daysBG = Decimal(countIndeces * 2)
                 }
 
-                // Keep 10 days apart from each array
-            } else if test1[0].createdAt.addingTimeInterval(10.days.timeInterval) < Date() {
+                // Keep 2 days apart from each array
+            } else if test1[0].createdAt.addingTimeInterval(2.days.timeInterval) < Date() {
                 storage.transaction { storage in
-                    storage.append(tenStats, to: file_10, uniqBy: \.createdAt)
-                    uniqEvents = storage.retrieve(file_10, as: [TenDaysStats].self)?
+                    storage.append(twoStats, to: file_10, uniqBy: \.createdAt)
+                    uniqEvents = storage.retrieve(file_10, as: [TwoDaysStats].self)?
                         .filter { $0.createdAt.addingTimeInterval(365.days.timeInterval) > Date() }
                         .sorted { $0.createdAt > $1.createdAt } ?? []
                     storage.save(Array(uniqEvents), as: file_10)
@@ -1067,8 +1061,8 @@ final class BaseAPSManager: APSManager, Injectable {
             }
         }
 
-        // Retrieve the 10 days data array
-        let uniqEvents_1 = storage.retrieve(OpenAPS.Monitor.tenDaysStats, as: [TenDaysStats].self)?
+        // Retrieve the 2 days data array
+        let uniqEvents_1 = storage.retrieve(OpenAPS.Monitor.twoDaysStats, as: [TwoDaysStats].self)?
             .filter { $0.createdAt.addingTimeInterval(365.days.timeInterval) > Date() }
             .sorted { $0.createdAt > $1.createdAt } ?? []
 
@@ -1076,32 +1070,39 @@ final class BaseAPSManager: APSManager, Injectable {
         var total: Decimal = 0
         var thirtyDays: Decimal = 0
         var ninetyDays: Decimal = 0
+        var tenDays: Decimal = 0
 
         for uniqEvent in uniqEvents_1 {
-            if uniqEvent.past10daysAverage != 0 {
-                total += uniqEvent.past10daysAverage
+            if uniqEvent.past2daysAverage != 0 {
+                total += uniqEvent.past2daysAverage
                 index += 1
             }
-            if index == 3 {
-                thirtyDays = total / 3
+            if index == 15 {
+                thirtyDays = total / 15
+            }
+            if index == 5 {
+                tenDays = total / 5
             }
-            if index == 9 {
-                ninetyDays = total / 9
+            if index == 45 {
+                ninetyDays = total / 45
             }
         }
+        if index != 0 {
+            total /= Decimal(index)
+        } else { total = bg_total }
 
         // HbA1c estimation (%, mmol/mol)
         let NGSPa1CStatisticValue = (46.7 + bg_1) / 28.7 // NGSP (%)
         let IFCCa1CStatisticValue = 10.929 *
             (NGSPa1CStatisticValue - 2.152) // IFCC (mmol/mol)  A1C(mmol/mol) = 10.929 * (A1C(%) - 2.15)
-        // 7 days
-        let NGSPa1CStatisticValue_7 = (46.7 + bg_7) / 28.7
-        let IFCCa1CStatisticValue_7 = 10.929 * (NGSPa1CStatisticValue_7 - 2.152)
+        // 10 days
+        let NGSPa1CStatisticValue_10 = (46.7 + tenDays) / 28.7
+        let IFCCa1CStatisticValue_10 = 10.929 * (NGSPa1CStatisticValue_10 - 2.152)
         // 30 days
         let NGSPa1CStatisticValue_30 = (46.7 + thirtyDays) / 28.7
         let IFCCa1CStatisticValue_30 = 10.929 * (NGSPa1CStatisticValue_30 - 2.152)
-        // Total days (up t0 10 days)
-        let NGSPa1CStatisticValue_total = (46.7 + bg_total) / 28.7
+        // Total days
+        let NGSPa1CStatisticValue_total = (46.7 + total) / 28.7
         let IFCCa1CStatisticValue_total = 10.929 * (NGSPa1CStatisticValue_total - 2.152)
         // 90 Days
         let NGSPa1CStatisticValue_90 = (46.7 + ninetyDays) / 28.7
@@ -1109,12 +1110,12 @@ final class BaseAPSManager: APSManager, Injectable {
 
         // HbA1c string and BG string:
         var HbA1c_string_1 = ""
-        var string7Days = ""
+        var string10Days = ""
         var string30Days = ""
         var string90Days = ""
         var stringTotal = ""
         var bgString1day = ""
-        var bgString7Days = ""
+        var bgString10Days = ""
         var bgString30Days = ""
         var bgString90Days = ""
         var bgAverageTotalString = ""
@@ -1128,11 +1129,11 @@ final class BaseAPSManager: APSManager, Injectable {
             HbA1c_string_1 =
                 "Estimated HbA1c (mmol/mol, 1 day): \(roundDecimal(IFCCa1CStatisticValue, 1)). Estimated HbA1c (%, 1 day): \(roundDecimal(NGSPa1CStatisticValue, 1)). "
         }
-        if bg_7 != 0 {
-            string7Days =
-                " HbA1c 7 days (mmol/mol): \(roundDecimal(IFCCa1CStatisticValue_7, 1)). HbA1c 7 days (%): \(roundDecimal(NGSPa1CStatisticValue_7, 1))."
-            bgString7Days =
-                " Average BG (mmol/l) 7 days: \(roundDecimal(bg_7 * 0.0555, 1)). Average BG (mg/dl) 7 days: \(roundDecimal(bg_7, 0))."
+        if tenDays != 0 {
+            string10Days =
+                " HbA1c 10 days (mmol/mol): \(roundDecimal(IFCCa1CStatisticValue_10, 1)). HbA1c 7 days (%): \(roundDecimal(NGSPa1CStatisticValue_10, 1))."
+            bgString10Days =
+                " Average BG (mmol/l) 10 days: \(roundDecimal(tenDays * 0.0555, 1)). Average BG (mg/dl) 10 days: \(roundDecimal(tenDays, 0))."
         }
         if thirtyDays != 0 {
             string30Days =
@@ -1147,24 +1148,24 @@ final class BaseAPSManager: APSManager, Injectable {
                 " Average BG 90 days (mmol/l): \(roundDecimal(ninetyDays * 0.0555, 1)). Average BG 90 days (mg/dl): \(roundDecimal(ninetyDays, 0)). "
         }
 
-        if bg_total != 0, daysBG >= 2 {
+        if total != 0, daysBG >= 2 {
             stringTotal =
                 " HbA1c \(daysBG) Days (mmol/mol): \(roundDecimal(IFCCa1CStatisticValue_total, 1)). HbA1c \(daysBG) Days (mg/dl): \(roundDecimal(NGSPa1CStatisticValue_total, 1)) %."
             bgAverageTotalString =
-                " BG Median \(daysBG) Days (mmol/l): \(roundDouble(medianBG * 0.0555, 1)). BG Median \(daysBG) Days (mg/dl): \(roundDouble(medianBG, 0)). BG Average \(daysBG) Days (mmg/dl): \(roundDecimal(bg_total, 0))."
+                " BG Median 2 Days (mmol/l): \(roundDouble(medianBG * 0.0555, 1)). BG Median 2 Days (mg/dl): \(roundDouble(medianBG, 0)). BG Average \(daysBG) Days (mmg/dl): \(roundDecimal(total, 0))."
         }
 
-        let HbA1c_string = HbA1c_string_1 + string7Days + string30Days + string90Days + stringTotal
+        let HbA1c_string = HbA1c_string_1 + string10Days + string30Days + string90Days + stringTotal
 
         var tirString =
             "TIR (24 hours): \(roundDecimal(TIR_1, 0)) %. Time with Hypoglycaemia: \(roundDecimal(hypos_1, 0)) % (< 4 / 72). Time with Hyperglycaemia:  \(roundDecimal(hypers_1, 0)) % (> 10 / 180)."
 
         if daysBG >= 2 {
             tirString +=
-                " (\(daysBG) days  TIR: \(roundDecimal(TIR, 1)) %. Time with Hypoglycaemia: \(roundDecimal(hypos, 1)) % (< 4 / 72). Time with Hyperglycaemia: \(roundDecimal(hypers, 1)) % (> 10 / 180)."
+                " (2 days  TIR: \(roundDecimal(TIR, 1)) %. Time with Hypoglycaemia: \(roundDecimal(hypos, 1)) % (< 4 / 72). Time with Hyperglycaemia: \(roundDecimal(hypers, 1)) % (> 10 / 180)."
         }
 
-        let bgAverageString = bgString1day + bgString7Days + bgString30Days + bgString90Days + bgAverageTotalString
+        let bgAverageString = bgString1day + bgString10Days + bgString30Days + bgString90Days + bgAverageTotalString
 
         let loopstat = LoopCycles(
             success_rate: Decimal(round(successRate ?? 0)),

+ 1 - 1
FreeAPS/Sources/APS/OpenAPS/Constants.swift

@@ -58,7 +58,7 @@ extension OpenAPS {
         static let tdd_averages = "monitor/tdd_averages.json"
         static let alertHistory = "monitor/alerthistory.json"
         static let dailyStats = "monitor/statistics.json"
-        static let tenDaysStats = "monitor/tenDays.json"
+        static let twoDaysStats = "monitor/twoDays.json"
         static let loopStats = "monitor/loopStats.json"
     }
 

+ 1 - 1
FreeAPS/Sources/APS/Storage/GlucoseStorage.swift

@@ -38,7 +38,7 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
             self.storage.transaction { storage in
                 storage.append(glucose, to: file, uniqBy: \.dateString)
                 let uniqEvents = storage.retrieve(file, as: [BloodGlucose].self)?
-                    .filter { $0.dateString.addingTimeInterval(241.hours.timeInterval) > Date() }
+                    .filter { $0.dateString.addingTimeInterval(49.hours.timeInterval) > Date() }
                     .sorted { $0.dateString > $1.dateString } ?? []
                 let glucose = Array(uniqEvents)
                 storage.save(glucose, as: file)

+ 0 - 21
FreeAPS/Sources/Models/TenDaysStats.swift

@@ -1,21 +0,0 @@
-import Foundation
-
-struct TenDaysStats: JSON, Equatable {
-    var createdAt: Date
-    var past10daysAverage: Decimal
-
-    init(
-        createdAt: Date,
-        past10daysAverage: Decimal
-    ) {
-        self.createdAt = createdAt
-        self.past10daysAverage = past10daysAverage
-    }
-}
-
-extension TenDaysStats {
-    private enum CodingKeys: String, CodingKey {
-        case createdAt
-        case past10daysAverage
-    }
-}

+ 21 - 0
FreeAPS/Sources/Models/TwoDaysStats.swift

@@ -0,0 +1,21 @@
+import Foundation
+
+struct TwoDaysStats: JSON, Equatable {
+    var createdAt: Date
+    var past2daysAverage: Decimal
+
+    init(
+        createdAt: Date,
+        past2daysAverage: Decimal
+    ) {
+        self.createdAt = createdAt
+        self.past2daysAverage = past2daysAverage
+    }
+}
+
+extension TwoDaysStats {
+    private enum CodingKeys: String, CodingKey {
+        case createdAt
+        case past2daysAverage
+    }
+}