polscm32 aka Marvout 1 год назад
Родитель
Сommit
d45934dfe3

+ 10 - 7
FreeAPS/Sources/Modules/Stat/View/ViewElements/GlucosePercentileChart.swift

@@ -94,8 +94,11 @@ struct GlucosePercentileChart: View {
                 AxisMarks(position: .trailing) { value in
                     if let glucose = value.as(Double.self) {
                         AxisValueLabel {
-                            Text(glucose.formatted(.number.precision(.fractionLength(0))))
-                                .font(.footnote)
+                            Text(
+                                units == .mmolL ? glucose.asMmolL.formatted(.number.precision(.fractionLength(0))) : glucose
+                                    .formatted(.number.precision(.fractionLength(0)))
+                            )
+                            .font(.footnote)
                         }
                         AxisGridLine()
                     }
@@ -206,31 +209,31 @@ struct AGPSelectionPopover: View {
             Grid(alignment: .leading, horizontalSpacing: 8) {
                 GridRow {
                     Text("90%:")
-                    Text(stats.percentile90.formatted(.number))
+                    Text(units == .mmolL ? stats.percentile90.asMmolL.formatted(.number) : stats.percentile90.formatted(.number))
                     Text(units.rawValue)
                         .foregroundStyle(.secondary)
                 }
                 GridRow {
                     Text("75%:")
-                    Text(stats.percentile75.formatted(.number))
+                    Text(units == .mmolL ? stats.percentile75.asMmolL.formatted(.number) : stats.percentile75.formatted(.number))
                     Text(units.rawValue)
                         .foregroundStyle(.secondary)
                 }
                 GridRow {
                     Text("Median:")
-                    Text(stats.median.formatted(.number))
+                    Text(units == .mmolL ? stats.median.asMmolL.formatted(.number) : stats.median.formatted(.number))
                     Text(units.rawValue)
                         .foregroundStyle(.secondary)
                 }
                 GridRow {
                     Text("25%:")
-                    Text(stats.percentile25.formatted(.number))
+                    Text(units == .mmolL ? stats.percentile25.asMmolL.formatted(.number) : stats.percentile25.formatted(.number))
                     Text(units.rawValue)
                         .foregroundStyle(.secondary)
                 }
                 GridRow {
                     Text("10%:")
-                    Text(stats.percentile10.formatted(.number))
+                    Text(units == .mmolL ? stats.percentile10.asMmolL.formatted(.number) : stats.percentile10.formatted(.number))
                     Text(units.rawValue)
                         .foregroundStyle(.secondary)
                 }

+ 22 - 6
FreeAPS/Sources/Modules/Stat/View/ViewElements/SectorChart.swift

@@ -147,12 +147,17 @@ struct SectorChart: View {
             let veryHigh = glucose.filter { $0.glucose > 250 }.count
             // Count readings between high limit and 250 mg/dL (high)
             let high = glucose.filter { $0.glucose > Int(highLimit) && $0.glucose <= 250 }.count
+
+            // Format glucose values
+            let highLimitMmol = Decimal(Int(highLimit)).asMmolL
+            let veryHighThresholdMmol = Decimal(250).asMmolL
+
             return RangeDetail(
                 title: "High Glucose",
                 color: .orange,
                 items: [
-                    ("Very High (>250)", Decimal(veryHigh) / total * 100),
-                    ("High (\(Int(highLimit))-250)", Decimal(high) / total * 100)
+                    ("Very High (>\(veryHighThresholdMmol) \(units.rawValue))", Decimal(veryHigh) / total * 100),
+                    ("High (\(highLimitMmol)-\(veryHighThresholdMmol) \(units.rawValue))", Decimal(high) / total * 100)
                 ]
             )
         case .inRange:
@@ -160,12 +165,18 @@ struct SectorChart: View {
             let tight = glucose.filter { $0.glucose >= Int(lowLimit) && $0.glucose <= 140 }.count
             // Count readings between 140 and high limit (normal range)
             let normal = glucose.filter { $0.glucose > 140 && $0.glucose <= Int(highLimit) }.count
+
+            // Format glucose values
+            let lowLimitMmol = Decimal(Int(lowLimit)).asMmolL
+            let highLimitMmol = Decimal(Int(highLimit)).asMmolL
+            let tightThresholdMmol = Decimal(140).asMmolL
+
             return RangeDetail(
                 title: "In Range",
                 color: .green,
                 items: [
-                    ("Tight (70-140)", Decimal(tight) / total * 100),
-                    ("Normal (140-\(Int(highLimit)))", Decimal(normal) / total * 100)
+                    ("Tight (\(lowLimitMmol)-\(tightThresholdMmol) \(units.rawValue)", Decimal(tight) / total * 100),
+                    ("Normal (\(tightThresholdMmol)-\(highLimitMmol) \(units.rawValue)", Decimal(normal) / total * 100)
                 ]
             )
         case .low:
@@ -173,12 +184,17 @@ struct SectorChart: View {
             let veryLow = glucose.filter { $0.glucose <= 54 }.count
             // Count readings between 54 and low limit (low)
             let low = glucose.filter { $0.glucose > 54 && $0.glucose < Int(lowLimit) }.count
+
+            // Format glucose values
+            let lowLimitMmol = Decimal(Int(lowLimit)).asMmolL
+            let veryLowThresholdMmol = Decimal(54).asMmolL
+
             return RangeDetail(
                 title: "Low Glucose",
                 color: .red,
                 items: [
-                    ("Very Low (<54)", Decimal(veryLow) / total * 100),
-                    ("Low (54-\(Int(lowLimit)))", Decimal(low) / total * 100)
+                    ("Very Low (<\(veryLowThresholdMmol) \(units.rawValue))", Decimal(veryLow) / total * 100),
+                    ("Low (\(veryLowThresholdMmol)-\(lowLimitMmol) \(units.rawValue))", Decimal(low) / total * 100)
                 ]
             )
         }