Преглед изворни кода

When user uses TING, use 63 for bottom range for all stats

Deniz Cengiz пре 1 година
родитељ
комит
00421a96cd

+ 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)),