Procházet zdrojové kódy

Merge branch 'dev' of https://github.com/nightscout/Trio-dev into fix-bolus-calc-limits

polscm32 před 1 rokem
rodič
revize
3bc5dfe727

+ 1 - 1
CGMBLEKit

@@ -1 +1 @@
-Subproject commit b786e8b5531cb08c259103c472dcd6a6752728f8
+Subproject commit cd8f6faec67b30231987b79daf0117dfcbb54741

+ 1 - 1
G7SensorKit

@@ -1 +1 @@
-Subproject commit bdfcfe83fbb9fab515a2456a4be9991420ed44bb
+Subproject commit 425a6b06b1d77d7bcdab7571b906c65618931f2e

+ 29 - 29
Trio/Sources/Modules/DynamicSettings/View/DynamicSettingsRootView.swift

@@ -169,35 +169,6 @@ extension DynamicSettings {
                                 )
                             }
                         )
-
-                        SettingInputSection(
-                            decimalValue: $state.weightPercentage,
-                            booleanValue: $booleanPlaceholder,
-                            shouldDisplayHint: $shouldDisplayHint,
-                            selectedVerboseHint: Binding(
-                                get: { selectedVerboseHint },
-                                set: {
-                                    selectedVerboseHint = $0.map { AnyView($0) }
-                                    hintLabel = String(localized: "Weighted Average of TDD")
-                                }
-                            ),
-                            units: state.units,
-                            type: .decimal("weightPercentage"),
-                            label: String(localized: "Weighted Average of TDD"),
-                            miniHint: String(localized: "Weight of 24-hr TDD against 10-day TDD."),
-                            verboseHint:
-                            VStack(alignment: .leading, spacing: 10) {
-                                Text("Default: 35%").bold()
-                                Text(
-                                    "This setting adjusts how much weight is given to your recent total daily insulin dose when calculating Dynamic ISF and Dynamic CR."
-                                )
-                                Text(
-                                    "At the default setting, 35% of the calculation is based on the last 24 hours of insulin use, with the remaining 65% considering the last 10 days of data."
-                                )
-                                Text("Setting this to 100% means only the past 24 hours will be used.")
-                                Text("A lower value smooths out these variations for more stability.")
-                            }
-                        )
                     } else {
                         SettingInputSection(
                             decimalValue: $state.adjustmentFactorSigmoid,
@@ -234,6 +205,35 @@ extension DynamicSettings {
                     }
 
                     SettingInputSection(
+                        decimalValue: $state.weightPercentage,
+                        booleanValue: $booleanPlaceholder,
+                        shouldDisplayHint: $shouldDisplayHint,
+                        selectedVerboseHint: Binding(
+                            get: { selectedVerboseHint },
+                            set: {
+                                selectedVerboseHint = $0.map { AnyView($0) }
+                                hintLabel = String(localized: "Weighted Average of TDD")
+                            }
+                        ),
+                        units: state.units,
+                        type: .decimal("weightPercentage"),
+                        label: String(localized: "Weighted Average of TDD"),
+                        miniHint: String(localized: "Weight of 24-hr TDD against 10-day TDD."),
+                        verboseHint:
+                        VStack(alignment: .leading, spacing: 10) {
+                            Text("Default: 35%").bold()
+                            Text(
+                                "This setting adjusts how much weight is given to your recent total daily insulin dose when calculating Dynamic ISF and Dynamic CR."
+                            )
+                            Text(
+                                "At the default setting, 35% of the calculation is based on the last 24 hours of insulin use, with the remaining 65% considering the last 10 days of data."
+                            )
+                            Text("Setting this to 100% means only the past 24 hours will be used.")
+                            Text("A lower value smooths out these variations for more stability.")
+                        }
+                    )
+
+                    SettingInputSection(
                         decimalValue: $decimalPlaceholder,
                         booleanValue: $state.tddAdjBasal,
                         shouldDisplayHint: $shouldDisplayHint,

+ 0 - 2
Trio/Sources/Modules/NightscoutConfig/NightscoutConfigStateModel.swift

@@ -26,7 +26,6 @@ extension NightscoutConfig {
         @Published var isUploadEnabled = false // Allow uploads
         @Published var isDownloadEnabled = false // Allow downloads
         @Published var uploadGlucose = true // Upload Glucose
-        @Published var changeUploadGlucose = true // if plugin, need to be change in CGM configuration
         @Published var useLocalSource = false
         @Published var localPort: Decimal = 0
         @Published var units: GlucoseUnits = .mgdL
@@ -55,7 +54,6 @@ extension NightscoutConfig {
             dia = settingsManager.pumpSettings.insulinActionCurve
             maxBasal = settingsManager.pumpSettings.maxBasal
             maxBolus = settingsManager.pumpSettings.maxBolus
-            changeUploadGlucose = (cgmManager.cgmGlucoseSourceType != CGMType.plugin)
 
             subscribeSetting(\.isUploadEnabled, on: $isUploadEnabled) { isUploadEnabled = $0 }
             subscribeSetting(\.isDownloadEnabled, on: $isDownloadEnabled) { isDownloadEnabled = $0 }

+ 20 - 22
Trio/Sources/Modules/NightscoutConfig/View/NightscoutUploadView.swift

@@ -47,29 +47,27 @@ struct NightscoutUploadView: View {
                 }
             )
 
-            if state.changeUploadGlucose {
-                SettingInputSection(
-                    decimalValue: $decimalPlaceholder,
-                    booleanValue: $state.uploadGlucose,
-                    shouldDisplayHint: $shouldDisplayHint,
-                    selectedVerboseHint: Binding(
-                        get: { selectedVerboseHint },
-                        set: {
-                            selectedVerboseHint = $0.map { AnyView($0) }
-                            hintLabel = String(localized: "Upload Glucose")
-                            shouldDisplayHint = true
-                        }
-                    ),
-                    units: state.units,
-                    type: .boolean,
-                    label: String(localized: "Upload Glucose"),
-                    miniHint: String(localized: "Enable uploading of CGM readings to Nightscout."),
-                    verboseHint: VStack(alignment: .leading, spacing: 10) {
-                        Text("Default: OFF").bold()
-                        Text("Enabling this setting allows CGM readings from Trio to be used in Nightscout.")
+            SettingInputSection(
+                decimalValue: $decimalPlaceholder,
+                booleanValue: $state.uploadGlucose,
+                shouldDisplayHint: $shouldDisplayHint,
+                selectedVerboseHint: Binding(
+                    get: { selectedVerboseHint },
+                    set: {
+                        selectedVerboseHint = $0.map { AnyView($0) }
+                        hintLabel = String(localized: "Upload Glucose")
+                        shouldDisplayHint = true
                     }
-                )
-            }
+                ),
+                units: state.units,
+                type: .boolean,
+                label: String(localized: "Upload Glucose"),
+                miniHint: String(localized: "Enable uploading of CGM readings to Nightscout."),
+                verboseHint: VStack(alignment: .leading, spacing: 10) {
+                    Text("Default: OFF").bold()
+                    Text("Enabling this setting allows CGM readings from Trio to be used in Nightscout.")
+                }
+            )
         }
         .listSectionSpacing(sectionSpacing)
         .sheet(isPresented: $shouldDisplayHint) {

+ 0 - 3
Trio/Sources/Modules/Stat/View/StatRootView.swift

@@ -143,7 +143,6 @@ extension Stat {
                 VStack(spacing: Constants.spacing) {
                     GlucoseSectorChart(
                         highLimit: state.highLimit,
-                        lowLimit: state.lowLimit,
                         units: state.units,
                         glucose: state.glucoseFromPersistence,
                         timeInRangeType: state.timeInRangeType
@@ -152,8 +151,6 @@ extension Stat {
                     Divider()
 
                     GlucoseMetricsView(
-                        highLimit: state.highLimit,
-                        lowLimit: state.lowLimit,
                         units: state.units,
                         eA1cDisplayUnit: state.eA1cDisplayUnit,
                         glucose: state.glucoseFromPersistence

+ 0 - 4
Trio/Sources/Modules/Stat/View/ViewElements/Glucose/GlucoseMetricsView.swift

@@ -4,10 +4,6 @@ import SwiftUI
 
 /// A SwiftUI view displaying various glucose-related statistics based on stored glucose readings.
 struct GlucoseMetricsView: View {
-    /// The upper glucose limit for evaluation.
-    let highLimit: Decimal
-    /// The lower glucose limit for evaluation.
-    let lowLimit: Decimal
     /// The unit of measurement for blood glucose values (e.g., mg/dL or mmol/L).
     let units: GlucoseUnits
     /// The display unit for estimated HbA1c values.

+ 21 - 14
Trio/Sources/Modules/Stat/View/ViewElements/Glucose/GlucoseSectorChart.swift

@@ -5,7 +5,6 @@ import SwiftUI
 
 struct GlucoseSectorChart: View {
     let highLimit: Decimal
-    let lowLimit: Decimal
     let units: GlucoseUnits
     let glucose: [GlucoseStored]
     let timeInRangeType: TimeInRangeType
@@ -27,15 +26,15 @@ struct GlucoseSectorChart: View {
         HStack(alignment: .center, spacing: 20) {
             // Calculate total number of glucose readings
             let total = Decimal(glucose.count)
-            // Count readings between high limit and 250 mg/dL (high)
+            // Count readings greater than high limit (180 mg/dL)
             let high = glucose.filter { $0.glucose > Int(highLimit) }.count
             // Count readings between low limit (TITR: 70 mg/dL, TING 63 mg/dL) and 140 mg/dL (tight control)
             let tight = glucose
                 .filter { $0.glucose >= timeInRangeType.bottomThreshold && $0.glucose <= timeInRangeType.topThreshold }.count
             // Count readings between 140 and high limit (normal range)
-            let normal = glucose.filter { $0.glucose >= Int(lowLimit) && $0.glucose <= Int(highLimit) }.count
-            // Count readings between 54 and low limit (low)
-            let low = glucose.filter { $0.glucose < Int(lowLimit) }.count
+            let normal = glucose.filter { $0.glucose >= timeInRangeType.bottomThreshold && $0.glucose <= Int(highLimit) }.count
+            // Count readings less than low limit (low)
+            let low = glucose.filter { $0.glucose < timeInRangeType.bottomThreshold }.count
 
             let justGlucoseArray = glucose.compactMap({ each in Int(each.glucose as Int16) })
             let sumReadings = justGlucoseArray.reduce(0, +)
@@ -50,7 +49,8 @@ struct GlucoseSectorChart: View {
 
             VStack(alignment: .leading, spacing: 10) {
                 VStack(alignment: .leading, spacing: 5) {
-                    Text("\(formatValue(lowLimit))-\(formatValue(highLimit))").font(.subheadline).foregroundStyle(Color.secondary)
+                    Text("\(formatValue(Decimal(timeInRangeType.bottomThreshold)))-\(formatValue(highLimit))").font(.subheadline)
+                        .foregroundStyle(Color.secondary)
                     Text(inRangePercentage.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1))) + "%")
                         .foregroundStyle(Color.loopGreen)
                 }
@@ -68,13 +68,18 @@ struct GlucoseSectorChart: View {
 
             VStack(alignment: .leading, spacing: 10) {
                 VStack(alignment: .leading, spacing: 5) {
-                    Text("> \(formatValue(highLimit))").font(.subheadline).foregroundStyle(Color.secondary)
+                    Text("> \(formatValue(highLimit))").font(.subheadline)
+                        .foregroundStyle(Color.secondary)
                     Text(highPercentage.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1))) + "%")
                         .foregroundStyle(Color.orange)
                 }
 
                 VStack(alignment: .leading, spacing: 5) {
-                    Text("< \(formatValue(lowLimit))").font(.subheadline).foregroundStyle(Color.secondary)
+                    Text(
+                        "< \(formatValue(Decimal(timeInRangeType.bottomThreshold)))"
+                    )
+                    .font(.subheadline)
+                    .foregroundStyle(Color.secondary)
                     Text(lowPercentage.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1))) + "%")
                         .foregroundStyle(Color.loopRed)
                 }
@@ -156,7 +161,7 @@ struct GlucoseSectorChart: View {
         // Count readings above high limit
         let highCount = glucose.filter { $0.glucose > Int(highLimit) }.count
         // Count readings below low limit
-        let lowCount = glucose.filter { $0.glucose < Int(lowLimit) }.count
+        let lowCount = glucose.filter { $0.glucose < timeInRangeType.bottomThreshold }.count
         // Calculate in-range readings by subtracting high and low counts from total
         let inRangeCount = total - highCount - lowCount
 
@@ -227,7 +232,7 @@ struct GlucoseSectorChart: View {
         case .inRange:
             let tight = glucose
                 .filter { $0.glucose >= Int(timeInRangeType.bottomThreshold) && $0.glucose <= timeInRangeType.topThreshold }.count
-            let glucoseValues = glucose.filter { $0.glucose >= Int(lowLimit) && $0.glucose <= Int(highLimit) }
+            let glucoseValues = glucose.filter { $0.glucose >= timeInRangeType.bottomThreshold && $0.glucose <= Int(highLimit) }
             let glucoseValuesAsInt = glucoseValues.map { Int($0.glucose) }
             let (average, median, standardDeviation) = calculateDetailedStatistics(for: glucoseValuesAsInt)
 
@@ -236,7 +241,9 @@ struct GlucoseSectorChart: View {
                 color: .green,
                 items: [
                     (
-                        String(localized: "Normal (\(formatValue(lowLimit))-\(formatValue(highLimit)))"),
+                        String(
+                            localized: "Normal (\(formatValue(Decimal(timeInRangeType.bottomThreshold)))-\(formatValue(highLimit)))"
+                        ),
                         formatPercentage(Decimal(glucoseValues.count) / total * 100)
                     ),
                     (
@@ -253,9 +260,9 @@ struct GlucoseSectorChart: View {
 
         case .low:
             let veryLow = glucose.filter { $0.glucose <= 54 }.count
-            let low = glucose.filter { $0.glucose > 54 && $0.glucose < Int(lowLimit) }.count
+            let low = glucose.filter { $0.glucose > 54 && $0.glucose < timeInRangeType.bottomThreshold }.count
 
-            let lowGlucoseValues = glucose.filter { $0.glucose < Int(lowLimit) }
+            let lowGlucoseValues = glucose.filter { $0.glucose < timeInRangeType.bottomThreshold }
             let lowGlucoseValuesAsInt = lowGlucoseValues.map { Int($0.glucose) }
             let (average, median, standardDeviation) = calculateDetailedStatistics(for: lowGlucoseValuesAsInt)
 
@@ -264,7 +271,7 @@ struct GlucoseSectorChart: View {
                 color: .red,
                 items: [
                     (
-                        String(localized: "Low (\(formatValue(54))-\(formatValue(lowLimit)))"),
+                        String(localized: "Low (\(formatValue(54))-\(formatValue(Decimal(timeInRangeType.bottomThreshold))))"),
                         formatPercentage(Decimal(low) / total * 100)
                     ),
                     (String(localized: "Very Low (<\(formatValue(54)))"), formatPercentage(Decimal(veryLow) / total * 100)),