Parcourir la source

Save TDDs up to 14 days. Use Average of total data (14 days) instead of 7 days. Refactor variable names. Use grey color for Weighted average and total data avg.

Jon Mårtensson il y a 3 ans
Parent
commit
0346ac35ef

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
FreeAPS/Resources/javascript/bundle/determine-basal.js


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

@@ -654,7 +654,7 @@ final class BaseAPSManager: APSManager, Injectable {
             storage.transaction { storage in
                 storage.append(tdd, to: file, uniqBy: \.id)
                 uniqEvents = storage.retrieve(file, as: [TDD].self)?
-                    .filter { $0.timestamp.addingTimeInterval(7.days.timeInterval) > Date() }
+                    .filter { $0.timestamp.addingTimeInterval(14.days.timeInterval) > Date() }
                     .sorted { $0.timestamp > $1.timestamp } ?? []
 
                 var total: Decimal = 0
@@ -689,13 +689,13 @@ final class BaseAPSManager: APSManager, Injectable {
                     nrOfIndeces = 1
                 }
 
-                let average7 = total / indeces
+                let average14 = total / indeces
                 let average2hours = totalAmount / nrOfIndeces
                 let weight = preferences.weightPercentage
-                let weighted_average = weight * average2hours + (1 - weight) * average7
+                let weighted_average = weight * average2hours + (1 - weight) * average14
 
                 let averages = TDD_averages(
-                    average_7days: average7,
+                    average_total_data: average14,
                     weightedAverage: weighted_average,
                     past2hoursAverage: average2hours,
                     date: Date()

+ 5 - 0
FreeAPS/Sources/APS/CGM/HeartBeatManager.swift

@@ -45,6 +45,11 @@ class HeartBeatManager {
                 .deviceManager,
                 "UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress)"
             )
+            if let sharedTransmitterAddress = sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress) {
+                debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = \(sharedTransmitterAddress)")
+            } else {
+                debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = nil")
+            }
 
             // assign local copy of cgmTransmitterDeviceAddress to the value stored in sharedUserDefaults (possibly nil value)
             UserDefaults.standard.cgmTransmitterDeviceAddress = sharedUserDefaults

+ 4 - 4
FreeAPS/Sources/Models/TDD_averages.swift

@@ -1,18 +1,18 @@
 import Foundation
 
 struct TDD_averages: JSON, Equatable {
-    var average_7days: Decimal
+    var average_total_data: Decimal
     var weightedAverage: Decimal
     var past2hoursAverage: Decimal
     var date: Date
 
     init(
-        average_7days: Decimal,
+        average_total_data: Decimal,
         weightedAverage: Decimal,
         past2hoursAverage: Decimal,
         date: Date
     ) {
-        self.average_7days = average_7days
+        self.average_total_data = average_total_data
         self.weightedAverage = weightedAverage
         self.past2hoursAverage = past2hoursAverage
         self.date = date
@@ -21,7 +21,7 @@ struct TDD_averages: JSON, Equatable {
 
 extension TDD_averages {
     private enum CodingKeys: String, CodingKey {
-        case average_7days
+        case average_total_data
         case weightedAverage
         case past2hoursAverage
         case date

+ 1 - 1
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift

@@ -134,7 +134,7 @@ extension PreferencesEditor {
                     displayName: "Weighted Average of TDD. Weight of past 24 hours:",
                     type: .decimal(keypath: \.weightPercentage),
                     infoText: NSLocalizedString(
-                        "Has to be > 0 and <= 1.\nDefault is 0.65 (65 %) * past 24 hours. The rest will be from 7 days TDD average (0.35). To only use past 24 hours, set this to 1.\nTo avoid sudden fluctuations, an average of past 2 hours of TDD calc is used as past 24 hours TDD.",
+                        "Has to be > 0 and <= 1.\nDefault is 0.65 (65 %) * past 24 hours. The rest will be from average of total data (14 days) of all TDD calculations (0.35). To only use past 24 hours, set this to 1.\nTo avoid sudden fluctuations, an average of the past 2 hours of TDD calcs is used instead of just the current TDD (past 24 hours at this moment).",
                         comment: "Weight of past 24 hours of TDD"
                     ),
                     settable: self

+ 3 - 2
FreeAPS/Sources/Views/TagCloudView.swift

@@ -63,11 +63,12 @@ struct TagCloudView: View {
                 return .zt
             case textTag where textTag.contains("SMB Delivery Ratio:"):
                 return .uam
+            case textTag where textTag.contains("Weighted avg:"),
+                 textTag where textTag.contains("Total data avg:"):
+                return .gray
             case textTag where textTag.contains("Parabolic Fit"):
                 return .loopRed
             case textTag where textTag.contains("TDD:"),
-                 textTag where textTag.contains("Weighted avg:"),
-                 textTag where textTag.contains("Total data avg:"),
                  textTag where textTag.contains("Original formula"),
                  textTag where textTag.contains("Logarithmic formula"),
                  textTag where textTag.contains("AF:"),