|
|
@@ -8,6 +8,7 @@ struct GlucoseSectorChart: View {
|
|
|
let lowLimit: Decimal
|
|
|
let units: GlucoseUnits
|
|
|
let glucose: [GlucoseStored]
|
|
|
+ let timeInRangeType: TimeInRangeType
|
|
|
|
|
|
@State private var selectedCount: Int?
|
|
|
@State private var selectedRange: GlucoseRange?
|
|
|
@@ -28,8 +29,9 @@ struct GlucoseSectorChart: View {
|
|
|
let total = Decimal(glucose.count)
|
|
|
// Count readings between high limit and 250 mg/dL (high)
|
|
|
let high = glucose.filter { $0.glucose > Int(highLimit) }.count
|
|
|
- // Count readings between low limit and 140 mg/dL (tight control)
|
|
|
- let tight = glucose.filter { $0.glucose >= Int(lowLimit) && $0.glucose <= 140 }.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)
|
|
|
@@ -54,7 +56,11 @@ struct GlucoseSectorChart: View {
|
|
|
}
|
|
|
|
|
|
VStack(alignment: .leading, spacing: 5) {
|
|
|
- Text("\(formatValue(lowLimit))-\(formatValue(140))").font(.subheadline).foregroundStyle(Color.secondary)
|
|
|
+ Text(
|
|
|
+ "\(formatValue(Decimal(timeInRangeType.bottomThreshold)))-\(formatValue(Decimal(timeInRangeType.topThreshold)))"
|
|
|
+ )
|
|
|
+ .font(.subheadline)
|
|
|
+ .foregroundStyle(Color.secondary)
|
|
|
Text(tightPercentage.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1))) + "%")
|
|
|
.foregroundStyle(Color.green)
|
|
|
}
|
|
|
@@ -219,7 +225,8 @@ struct GlucoseSectorChart: View {
|
|
|
)
|
|
|
|
|
|
case .inRange:
|
|
|
- let tight = glucose.filter { $0.glucose >= Int(lowLimit) && $0.glucose <= 140 }.count
|
|
|
+ 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 glucoseValuesAsInt = glucoseValues.map { Int($0.glucose) }
|
|
|
let (average, median, standardDeviation) = calculateDetailedStatistics(for: glucoseValuesAsInt)
|
|
|
@@ -233,7 +240,9 @@ struct GlucoseSectorChart: View {
|
|
|
formatPercentage(Decimal(glucoseValues.count) / total * 100)
|
|
|
),
|
|
|
(
|
|
|
- String(localized: "Tight (\(formatValue(lowLimit))-\(formatValue(140)))"),
|
|
|
+ String(
|
|
|
+ localized: "\(timeInRangeType == .timeInTightRange ? "TITR" : "TING") (\(formatValue(Decimal(timeInRangeType.bottomThreshold)))-\(formatValue(Decimal(timeInRangeType.topThreshold))))"
|
|
|
+ ),
|
|
|
formatPercentage(Decimal(tight) / total * 100)
|
|
|
),
|
|
|
(String(localized: "Average"), formatValue(average)),
|