|
|
@@ -16,8 +16,116 @@ extension AutosensSettings {
|
|
|
@EnvironmentObject var appIcons: Icons
|
|
|
@Environment(AppState.self) var appState
|
|
|
|
|
|
+ private var rateFormatter: NumberFormatter {
|
|
|
+ let formatter = NumberFormatter()
|
|
|
+ formatter.numberStyle = .decimal
|
|
|
+ formatter.maximumFractionDigits = 2
|
|
|
+ return formatter
|
|
|
+ }
|
|
|
+
|
|
|
+ var autosensVerboseHint: some View {
|
|
|
+ VStack(alignment: .leading, spacing: 15) {
|
|
|
+ Text(
|
|
|
+ "Autosens automatically adjusts insulin delivery based on how sensitive or resistant you are to insulin at the time of the current loop cycle by analyzing past data to keep blood sugar levels stable."
|
|
|
+ )
|
|
|
+
|
|
|
+ VStack(alignment: .leading, spacing: 5) {
|
|
|
+ Text("How it Works").bold()
|
|
|
+ Text(
|
|
|
+ "It looks at the last 8-24 hours of data, excluding meal-related changes, and adjusts insulin settings like basal rates and targets when needed to match your sensitivity or resistance to insulin."
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ VStack(alignment: .leading, spacing: 5) {
|
|
|
+ Text("What it Adjusts").bold()
|
|
|
+ Text(
|
|
|
+ "Autosens modifies Insulin Sensitivity Factor (ISF), basal rates, and target blood sugar levels. It doesn’t account for carbs but adjusts for insulin effectiveness based on patterns in your glucose data."
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ VStack(alignment: .leading, spacing: 5) {
|
|
|
+ Text("Key Limitations").bold()
|
|
|
+ Text(
|
|
|
+ "Autosens has safety limits determined by your Autosens Max and Autosens Min settings. These settings prevent over-adjusting."
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ Text(
|
|
|
+ "Autosens functions alongside certain settings, like Super Micro Bolus (SMB). Other settings, like Dynamic ISF, alter portions of the Autosens formula. Please review the in-app hints for the Algorithm Settings prior to enabling them to understand how they may influence it."
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var AutosensView: some View {
|
|
|
+ Section(
|
|
|
+ header: !state.settingsManager.preferences
|
|
|
+ .useNewFormula ? Text("Autosens") : Text("Dynamic Sensitivity")
|
|
|
+ ) {
|
|
|
+ VStack {
|
|
|
+ let dynamicRatio = state.determinationsFromPersistence.first?.sensitivityRatio
|
|
|
+ let dynamicISF = state.determinationsFromPersistence.first?.insulinSensitivity
|
|
|
+ let newISF = state.autosensISF
|
|
|
+ HStack {
|
|
|
+ Text("Sensitivity Ratio")
|
|
|
+ Spacer()
|
|
|
+ Text(
|
|
|
+ rateFormatter
|
|
|
+ .string(from: (
|
|
|
+ (
|
|
|
+ !state.settingsManager.preferences.useNewFormula ? state
|
|
|
+ .autosensRatio as NSDecimalNumber : dynamicRatio
|
|
|
+ ) ?? 1
|
|
|
+ ) as NSNumber) ?? "1"
|
|
|
+ )
|
|
|
+ }.padding(.vertical)
|
|
|
+ HStack {
|
|
|
+ Text("Calculated Sensitivity")
|
|
|
+ Spacer()
|
|
|
+ if state.units == .mgdL {
|
|
|
+ Text(
|
|
|
+ !state.settingsManager.preferences
|
|
|
+ .useNewFormula ? newISF!.description : (dynamicISF ?? 0).description
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ Text((
|
|
|
+ !state.settingsManager.preferences
|
|
|
+ .useNewFormula ? newISF!.formattedAsMmolL : dynamicISF?.decimalValue.formattedAsMmolL
|
|
|
+ ) ?? "0")
|
|
|
+ }
|
|
|
+ Text(state.units.rawValue + "/U").foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+
|
|
|
+ HStack(alignment: .top) {
|
|
|
+ Text(
|
|
|
+ "This adjusted ISF is temporary, will change with the next loop cycle, and should not be directly used as your profile ISF value."
|
|
|
+ )
|
|
|
+ .font(.footnote)
|
|
|
+ .foregroundColor(.secondary)
|
|
|
+ .lineLimit(nil)
|
|
|
+ Spacer()
|
|
|
+ Button(
|
|
|
+ action: {
|
|
|
+ hintLabel = "Autosens"
|
|
|
+ selectedVerboseHint = AnyView(autosensVerboseHint)
|
|
|
+ shouldDisplayHint.toggle()
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ HStack {
|
|
|
+ Image(systemName: "questionmark.circle")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ).buttonStyle(BorderlessButtonStyle())
|
|
|
+ }.padding(.top)
|
|
|
+ }.padding(.bottom)
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
+ }
|
|
|
+
|
|
|
var body: some View {
|
|
|
List {
|
|
|
+ if state.autosensISF != nil {
|
|
|
+ AutosensView
|
|
|
+ }
|
|
|
+
|
|
|
SettingInputSection(
|
|
|
decimalValue: $state.autosensMax,
|
|
|
booleanValue: $booleanPlaceholder,
|