Просмотр исходного кода

fix calc for super bolus and add info in popup when super bolus is ticked/chosen

polscm32 2 лет назад
Родитель
Сommit
5018e215da

+ 3 - 1
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -66,6 +66,7 @@ extension Bolus {
         @Published var sweetMeals: Bool = false
         @Published var sweetMealFactor: Decimal = 0
         @Published var useSuperBolus: Bool = false
+        @Published var superBolusInsulin: Decimal = 0
 
         @Published var meal: [CarbsEntry]?
         @Published var carbs: Decimal = 0
@@ -191,7 +192,8 @@ extension Bolus {
             if useFattyMealCorrectionFactor {
                 insulinCalculated = result * fattyMealFactor
             } else if useSuperBolus {
-                insulinCalculated = result * sweetMealFactor
+                superBolusInsulin = sweetMealFactor * currentBasal
+                insulinCalculated = wholeCalc + superBolusInsulin
             } else {
                 insulinCalculated = result
             }

+ 44 - 17
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -369,6 +369,17 @@ extension Bolus {
                             .foregroundColor(.orange)
                     }
                 }
+                if state.useSuperBolus {
+                    HStack {
+                        Text("Super Bolus")
+                            .foregroundColor(.red)
+                        Spacer()
+                        let superBolusInsulin = state.superBolusInsulin
+                        Text(superBolusInsulin.formatted())
+                        Text(" U")
+                            .foregroundColor(.secondary)
+                    }
+                }
             }
         }
 
@@ -469,26 +480,42 @@ extension Bolus {
                     Text("Result")
                         .fontWeight(.bold)
                     Spacer()
-                    let fraction = state.fraction
-                    Text(fraction.formatted())
-                    Text(" x ")
-                        .foregroundColor(.secondary)
-
-                    // if fatty meal is chosen
-                    if state.useFattyMealCorrectionFactor {
-                        let fattyMealFactor = state.fattyMealFactor
-                        Text(fattyMealFactor.formatted())
-                            .foregroundColor(.orange)
+                    
+                    if !state.useSuperBolus {
+                        let fraction = state.fraction
+                        Text(fraction.formatted())
                         Text(" x ")
                             .foregroundColor(.secondary)
-                    }
 
-                    let insulin = state.roundedWholeCalc
-                    Text(insulin.formatted()).foregroundStyle(state.roundedWholeCalc < 0 ? Color.loopRed : Color.primary)
-                    Text(" U")
-                        .foregroundColor(.secondary)
-                    Text(" = ")
-                        .foregroundColor(.secondary)
+                        // if fatty meal is chosen
+                        if state.useFattyMealCorrectionFactor {
+                            let fattyMealFactor = state.fattyMealFactor
+                            Text(fattyMealFactor.formatted())
+                                .foregroundColor(.orange)
+                            Text(" x ")
+                                .foregroundColor(.secondary)
+                        }
+
+                        let insulin = state.roundedWholeCalc
+                        Text(insulin.formatted()).foregroundStyle(state.roundedWholeCalc < 0 ? Color.loopRed : Color.primary)
+                        Text(" U")
+                            .foregroundColor(.secondary)
+                        Text(" = ")
+                            .foregroundColor(.secondary)
+                    } else {
+                        //roundedWholeCalc
+                        let insulin = state.roundedWholeCalc
+                        Text(insulin.formatted()).foregroundStyle(state.roundedWholeCalc < 0 ? Color.loopRed : Color.primary)
+                        Text(" U")
+                        //plus
+                        Text(" + ")
+                            .foregroundColor(.secondary)
+                        //superBolusInsulin
+                        let superBolusInsulin = state.superBolusInsulin
+                        Text(superBolusInsulin.formatted())
+                        Text(" U")
+                            .foregroundColor(.secondary)
+                    }
 
                     let result = state.insulinCalculated
                     // rounding