|
@@ -128,7 +128,63 @@ extension ISFEditor {
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
.padding(.horizontal)
|
|
.padding(.horizontal)
|
|
|
- .id(bottomID)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Example calculation based on first ISF
|
|
|
|
|
+ if !state.items.isEmpty {
|
|
|
|
|
+ Spacer(minLength: 20)
|
|
|
|
|
+
|
|
|
|
|
+ VStack(alignment: .leading, spacing: 8) {
|
|
|
|
|
+ Text("Example Calculation")
|
|
|
|
|
+ .font(.headline)
|
|
|
|
|
+ .padding(.horizontal)
|
|
|
|
|
+
|
|
|
|
|
+ VStack(alignment: .leading, spacing: 8) {
|
|
|
|
|
+ let aboveTarget = state.units == .mgdL ? Decimal(40) : 40.asMmolL
|
|
|
|
|
+ let firstIsfRate: Decimal = state.rateValues[state.items.first?.rateIndex ?? 0]
|
|
|
|
|
+ let isfValue = state.units == .mgdL ? firstIsfRate : firstIsfRate.asMmolL
|
|
|
|
|
+ let insulinNeeded = aboveTarget / isfValue
|
|
|
|
|
+
|
|
|
|
|
+ Text(
|
|
|
|
|
+ "If you are \(numberFormatter.string(from: aboveTarget as NSNumber) ?? "--") \(state.units.rawValue) above target:"
|
|
|
|
|
+ )
|
|
|
|
|
+ .font(.subheadline)
|
|
|
|
|
+ .padding(.horizontal)
|
|
|
|
|
+
|
|
|
|
|
+ Text(
|
|
|
|
|
+ "\(aboveTarget.description) \(state.units.rawValue) / \(isfValue.description) \(state.units.rawValue)/\(String(localized: "U", comment: "Insulin unit abbreviation")) = \(String(format: "%.1f", Double(insulinNeeded))) \(String(localized: "U", comment: "Insulin unit abbreviation"))"
|
|
|
|
|
+ )
|
|
|
|
|
+ .font(.system(.body, design: .monospaced))
|
|
|
|
|
+ .foregroundColor(.cyan)
|
|
|
|
|
+ .padding()
|
|
|
|
|
+ .frame(maxWidth: .infinity, alignment: .center)
|
|
|
|
|
+ .background(Color.chart.opacity(0.65))
|
|
|
|
|
+ .cornerRadius(10)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Spacer(minLength: 20)
|
|
|
|
|
+
|
|
|
|
|
+ // Information about ISF
|
|
|
|
|
+ VStack(alignment: .leading, spacing: 8) {
|
|
|
|
|
+ Text("What This Means")
|
|
|
|
|
+ .font(.headline)
|
|
|
|
|
+ .padding(.horizontal)
|
|
|
|
|
+
|
|
|
|
|
+ VStack(alignment: .leading, spacing: 4) {
|
|
|
|
|
+ let isfValue =
|
|
|
|
|
+ "\(state.units == .mgdL ? Decimal(50) : 50.asMmolL)\(state.units.rawValue)"
|
|
|
|
|
+ Text(
|
|
|
|
|
+ "• An ISF of \(isfValue) means 1 U lowers your glucose by \(isfValue)"
|
|
|
|
|
+ )
|
|
|
|
|
+ Text("• A lower number means you're more sensitive to insulin")
|
|
|
|
|
+ Text("• A higher number means you're less sensitive to insulin")
|
|
|
|
|
+ }
|
|
|
|
|
+ .font(.caption)
|
|
|
|
|
+ .foregroundColor(.secondary)
|
|
|
|
|
+ .padding(.horizontal)
|
|
|
|
|
+ }
|
|
|
|
|
+ .id(bottomID)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|