Procházet zdrojové kódy

Merge branch 'dev' into Crowdin

Jon B.M před 2 roky
rodič
revize
8a81833807

+ 2 - 2
FreeAPS.xcodeproj/project.pbxproj

@@ -2254,11 +2254,11 @@
 			buildPhases = (
 				3811DEF525CA169200A708ED /* Swiftformat */,
 				388E595425AD948C0019842D /* Sources */,
+				B99D8B8E295F34DB00420AB8 /* Run Script */,
 				388E595525AD948C0019842D /* Frameworks */,
 				388E595625AD948C0019842D /* Resources */,
 				3821ECD025DC703C00BC42AD /* Embed Frameworks */,
 				38E8753D27554D5900975559 /* Embed Watch Content */,
-				B99D8B8E295F34DB00420AB8 /* Run Script */,
 			);
 			buildRules = (
 			);
@@ -2484,7 +2484,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "#!/bin/sh\n\ngit_version=$(git log -1 --format=\"%h\")\ngit_branch=$(git symbolic-ref --short -q HEAD)\ngit_tag=$(git describe --tags --exact-match 2>/dev/null)\n\ngit_branch_or_tag=\"${git_branch:-${git_tag}}\"\ngit_branch_or_tag_version=\"${git_branch:-${git_tag}} ${git_version}\"\n\ninfo_plist=\"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n\n/usr/libexec/PlistBuddy -c \"Set :BuildBranch '${git_branch_or_tag_version}'\" \"${info_plist}\"\n";
+			shellScript = "git_version=$(git log -1 --format=\"%h\")\ngit_branch=$(git symbolic-ref --short -q HEAD)\ngit_tag=$(git describe --tags --exact-match 2>/dev/null)\n\ngit_branch_or_tag=\"${git_branch:-${git_tag}}\"\ngit_branch_or_tag_version=\"${git_branch:-${git_tag}} ${git_version}\"\n\ninfo_plist=\"${SRCROOT}/FreeAPS/Resources/Info.plist\"\n\n/usr/libexec/PlistBuddy -c \"Set :BuildBranch '${git_branch_or_tag_version}'\" \"${info_plist}\"\n";
 		};
 /* End PBXShellScriptBuildPhase section */
 

+ 0 - 6
FreeAPS/Resources/javascript/prepare/determine-basal.js

@@ -37,12 +37,6 @@ function generate(iob, currenttemp, glucose, profile, autosens = null, meal = nu
     if (basalProfile) {
         basalprofile = basalProfile;
     }
-    /*
-    var tdd_ = {};
-    if (tdd) {
-        tdd_ = tdd;
-    }
-     */
     
     var oref2_variables_ = {};
     if (oref2_variables) {

+ 10 - 3
FreeAPS/Resources/javascript/prepare/profile.js

@@ -1,7 +1,7 @@
 //для pumpprofile.json параметры: settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json
 //для profile.json параметры: settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json settings/autotune.json
 
-function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data, preferences_input = false, carbratio_input = false, temptargets_input = false, model_input = false, autotune_input = false) {
+function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data, preferences_input = false, carbratio_input = false, temptargets_input = false, model_input = false, autotune_input = false, freeaps_data) {
     if (bgtargets_data.units !== 'mg/dL') {
         if (bgtargets_data.units === 'mmol/L') {
             for (var i = 0, len = bgtargets_data.targets.length; i < len; i++) {
@@ -34,6 +34,11 @@ function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data
     if (temptargets_input) {
         temptargets_data = temptargets_input;
     }
+    
+    var freeaps = { };
+    if (freeaps_data) {
+        freeaps = freeaps_data;
+    }
 
     var model_data = { };
     if (model_input) {
@@ -81,8 +86,10 @@ function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data
 
     if (autotune_data) {
         if (autotune_data.basalprofile) { inputs.basals = autotune_data.basalprofile; }
-        if (autotune_data.isfProfile) { inputs.isf = autotune_data.isfProfile; }
-        if (autotune_data.carb_ratio) { inputs.carbratio.schedule[0].ratio = autotune_data.carb_ratio; }
+        if (!freeaps.onlyAutotuneBasals) {
+            if (autotune_data.isfProfile) { inputs.isf = autotune_data.isfProfile; }
+            if (autotune_data.carb_ratio) { inputs.carbratio.schedule[0].ratio = autotune_data.carb_ratio; }
+        }
     }
     return freeaps_profile(inputs);
 }

+ 9 - 4
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -389,6 +389,7 @@ final class OpenAPS {
                 let tempTargets = self.loadFileFromStorage(name: Settings.tempTargets)
                 let model = self.loadFileFromStorage(name: Settings.model)
                 let autotune = useAutotune ? self.loadFileFromStorage(name: Settings.autotune) : .empty
+                let freeaps = self.loadFileFromStorage(name: FreeAPS.settings)
 
                 let pumpProfile = self.makeProfile(
                     preferences: preferences,
@@ -399,7 +400,8 @@ final class OpenAPS {
                     carbRatio: cr,
                     tempTargets: tempTargets,
                     model: model,
-                    autotune: RawJSON.null
+                    autotune: RawJSON.null,
+                    freeaps: freeaps
                 )
 
                 let profile = self.makeProfile(
@@ -411,7 +413,8 @@ final class OpenAPS {
                     carbRatio: cr,
                     tempTargets: tempTargets,
                     model: model,
-                    autotune: autotune.isEmpty ? .null : autotune
+                    autotune: autotune.isEmpty ? .null : autotune,
+                    freeaps: freeaps
                 )
 
                 self.storage.save(pumpProfile, as: Settings.pumpProfile)
@@ -598,7 +601,8 @@ final class OpenAPS {
         carbRatio: JSON,
         tempTargets: JSON,
         model: JSON,
-        autotune: JSON
+        autotune: JSON,
+        freeaps: JSON
     ) -> RawJSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
@@ -616,7 +620,8 @@ final class OpenAPS {
                     carbRatio,
                     tempTargets,
                     model,
-                    autotune
+                    autotune,
+                    freeaps
                 ]
             )
         }

+ 6 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -1043,6 +1043,12 @@ Enact a temp Basal or a temp target */
 /* Debug option view Autosense */
 "Autosense" = "Autosense";
 
+/* Insulin sensitivity config header */
+"Dynamic Sensitivity" = "Dynamic Sensitivity";
+
+/* Autotune config */
+"Only Autotune Basal Insulin" = "Only Autotune Basal Insulin";
+
 /* Debug option view Pump History */
 "Pump History" = "Pump History";
 

+ 5 - 0
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -42,6 +42,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var rulerMarks: Bool = false
     var maxCarbs: Decimal = 1000
     var displayFatAndProteinOnWatch: Bool = false
+    var onlyAutotuneBasals: Bool = false
 }
 
 extension FreeAPSSettings: Decodable {
@@ -219,6 +220,10 @@ extension FreeAPSSettings: Decodable {
             settings.displayFatAndProteinOnWatch = displayFatAndProteinOnWatch
         }
 
+        if let onlyAutotuneBasals = try? container.decode(Bool.self, forKey: .onlyAutotuneBasals) {
+            settings.onlyAutotuneBasals = onlyAutotuneBasals
+        }
+
         self = settings
     }
 }

+ 7 - 3
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -10,7 +10,7 @@ extension AddCarbs {
         @State var isPromtPresented = false
         @State var saved = false
         @State private var showAlert = false
-        @State var displayNote = false
+        @FocusState private var isFocused: Bool
 
         @FetchRequest(
             entity: Presets.entity(),
@@ -56,8 +56,12 @@ extension AddCarbs {
                     }
                     HStack {
                         Text("Note").foregroundColor(.secondary)
-                        TextField("", text: $state.note).frame(maxWidth: .infinity, alignment: .trailing)
-                    }
+                        TextField("", text: $state.note).multilineTextAlignment(.trailing)
+                        if state.note != "", isFocused {
+                            Button { isFocused = false } label: { Image(systemName: "keyboard.chevron.compact.down") }
+                                .controlSize(.mini)
+                        }
+                    }.focused($isFocused)
                     HStack {
                         Button {
                             state.useFPUconversion.toggle()

+ 2 - 0
FreeAPS/Sources/Modules/AutotuneConfig/AutotuneConfigStateModel.swift

@@ -5,6 +5,7 @@ extension AutotuneConfig {
     final class StateModel: BaseStateModel<Provider> {
         @Injected() var apsManager: APSManager!
         @Published var useAutotune = false
+        @Published var onlyAutotuneBasals = false
         @Published var autotune: Autotune?
         private(set) var units: GlucoseUnits = .mmolL
         @Published var publishedDate = Date()
@@ -21,6 +22,7 @@ extension AutotuneConfig {
             units = settingsManager.settings.units
             useAutotune = settingsManager.settings.useAutotune
             publishedDate = lastAutotuneDate
+            subscribeSetting(\.onlyAutotuneBasals, on: $onlyAutotuneBasals) { onlyAutotuneBasals = $0 }
 
             $useAutotune
                 .removeDuplicates()

+ 20 - 15
FreeAPS/Sources/Modules/AutotuneConfig/View/AutotuneConfigRootView.swift

@@ -31,6 +31,9 @@ extension AutotuneConfig {
             Form {
                 Section {
                     Toggle("Use Autotune", isOn: $state.useAutotune)
+                    if state.useAutotune {
+                        Toggle("Only Autotune Basal Insulin", isOn: $state.onlyAutotuneBasals)
+                    }
                 }
 
                 Section {
@@ -44,22 +47,24 @@ extension AutotuneConfig {
                 }
 
                 if let autotune = state.autotune {
-                    Section {
-                        HStack {
-                            Text("Carb ratio")
-                            Spacer()
-                            Text(isfFormatter.string(from: autotune.carbRatio as NSNumber) ?? "0")
-                            Text("g/U").foregroundColor(.secondary)
-                        }
-                        HStack {
-                            Text("Sensitivity")
-                            Spacer()
-                            if state.units == .mmolL {
-                                Text(isfFormatter.string(from: autotune.sensitivity.asMmolL as NSNumber) ?? "0")
-                            } else {
-                                Text(isfFormatter.string(from: autotune.sensitivity as NSNumber) ?? "0")
+                    if !state.onlyAutotuneBasals {
+                        Section {
+                            HStack {
+                                Text("Carb ratio")
+                                Spacer()
+                                Text(isfFormatter.string(from: autotune.carbRatio as NSNumber) ?? "0")
+                                Text("g/U").foregroundColor(.secondary)
+                            }
+                            HStack {
+                                Text("Sensitivity")
+                                Spacer()
+                                if state.units == .mmolL {
+                                    Text(isfFormatter.string(from: autotune.sensitivity.asMmolL as NSNumber) ?? "0")
+                                } else {
+                                    Text(isfFormatter.string(from: autotune.sensitivity as NSNumber) ?? "0")
+                                }
+                                Text(state.units.rawValue + "/U").foregroundColor(.secondary)
                             }
-                            Text(state.units.rawValue + "/U").foregroundColor(.secondary)
                         }
                     }
 

+ 1 - 1
FreeAPS/Sources/Modules/CREditor/View/CREditorRootView.swift

@@ -22,7 +22,7 @@ extension CREditor {
 
         var body: some View {
             Form {
-                if let autotune = state.autotune {
+                if let autotune = state.autotune, !state.settingsManager.settings.onlyAutotuneBasals {
                     Section(header: Text("Autotune")) {
                         HStack {
                             Text("Calculated Ratio")

+ 16 - 6
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -495,7 +495,7 @@ extension Home {
                                     .background(Capsule().fill(Color.red))
                             }
                         }
-                    }
+                    }.buttonStyle(.borderless)
                     Spacer()
                     Button { state.showModal(for: .addTempTarget) }
                     label: {
@@ -504,7 +504,9 @@ extension Home {
                             .resizable()
                             .frame(width: 24, height: 24)
                             .padding(8)
-                    }.foregroundColor(.loopGreen)
+                    }
+                    .foregroundColor(.loopGreen)
+                    .buttonStyle(.borderless)
                     Spacer()
                     Button { state.showModal(for: .bolus(waitForSuggestion: false)) }
                     label: {
@@ -513,7 +515,9 @@ extension Home {
                             .resizable()
                             .frame(width: 24, height: 24)
                             .padding(8)
-                    }.foregroundColor(.insulin)
+                    }
+                    .foregroundColor(.insulin)
+                    .buttonStyle(.borderless)
                     Spacer()
                     if state.allowManualTemp {
                         Button { state.showModal(for: .manualTempBasal) }
@@ -523,7 +527,9 @@ extension Home {
                                 .resizable()
                                 .frame(width: 24, height: 24)
                                 .padding(8)
-                        }.foregroundColor(.insulin)
+                        }
+                        .foregroundColor(.insulin)
+                        .buttonStyle(.borderless)
                         Spacer()
                     }
                     Button { state.showModal(for: .statistics)
@@ -534,7 +540,9 @@ extension Home {
                             .resizable()
                             .frame(width: 24, height: 24)
                             .padding(8)
-                    }.foregroundColor(.purple)
+                    }
+                    .foregroundColor(.purple)
+                    .buttonStyle(.borderless)
                     Spacer()
                     Button { state.showModal(for: .settings) }
                     label: {
@@ -543,7 +551,9 @@ extension Home {
                             .resizable()
                             .frame(width: 24, height: 24)
                             .padding(8)
-                    }.foregroundColor(.loopGray)
+                    }
+                    .foregroundColor(.loopGray)
+                    .buttonStyle(.borderless)
                 }
                 .padding(.horizontal, 24)
                 .padding(.bottom, geo.safeAreaInsets.bottom)

+ 1 - 0
FreeAPS/Sources/Modules/ISFEditor/ISFEditorDataFlow.swift

@@ -28,4 +28,5 @@ protocol ISFEditorProvider: Provider {
     func saveProfile(_ profile: InsulinSensitivities)
     var autosense: Autosens { get }
     var autotune: Autotune? { get }
+    var suggestion: Suggestion? { get }
 }

+ 4 - 0
FreeAPS/Sources/Modules/ISFEditor/ISFEditorProvider.swift

@@ -20,6 +20,10 @@ extension ISFEditor {
                 ?? Autosens(ratio: 1, newisf: nil, timestamp: nil)
         }
 
+        var suggestion: Suggestion? {
+            storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
+        }
+
         var autotune: Autotune? {
             storage.retrieve(OpenAPS.Settings.autotune, as: Autotune.self)
         }

+ 21 - 4
FreeAPS/Sources/Modules/ISFEditor/View/ISFEditorRootView.swift

@@ -23,7 +23,7 @@ extension ISFEditor {
 
         var body: some View {
             Form {
-                if let autotune = state.autotune {
+                if let autotune = state.autotune, !state.settingsManager.settings.onlyAutotuneBasals {
                     Section(header: Text("Autotune")) {
                         HStack {
                             Text("Calculated Sensitivity")
@@ -38,16 +38,33 @@ extension ISFEditor {
                     }
                 }
                 if let newISF = state.autosensISF {
-                    Section(header: Text("Autosens")) {
+                    Section(
+                        header: !state.settingsManager.preferences
+                            .useNewFormula ? Text("Autosens") : Text("Dynamic Sensitivity")
+                    ) {
+                        let dynamicRatio = state.provider.suggestion?.sensitivityRatio ?? 0
+                        let dynamicISF = state.provider.suggestion?.isf ?? 0
                         HStack {
                             Text("Sensitivity Ratio")
                             Spacer()
-                            Text(rateFormatter.string(from: state.autosensRatio as NSNumber) ?? "1")
+                            Text(
+                                rateFormatter
+                                    .string(from: (
+                                        !state.settingsManager.preferences.useNewFormula ? state
+                                            .autosensRatio : dynamicRatio
+                                    ) as NSNumber) ?? "1"
+                            )
                         }
                         HStack {
                             Text("Calculated Sensitivity")
                             Spacer()
-                            Text(rateFormatter.string(from: newISF as NSNumber) ?? "0")
+                            Text(
+                                rateFormatter
+                                    .string(from: (
+                                        !state.settingsManager.preferences
+                                            .useNewFormula ? newISF : dynamicISF
+                                    ) as NSNumber) ?? "0"
+                            )
                             Text(state.units.rawValue + "/U").foregroundColor(.secondary)
                         }
                     }

+ 2 - 2
FreeAPSWatch WatchKit Extension/Views/CarbsView.swift

@@ -33,9 +33,9 @@ struct CarbsView: View {
             carbs
             if state.displayFatAndProteinOnWatch {
                 Spacer()
-                protein
-                Spacer()
                 fat
+                Spacer()
+                protein
             }
             buttonStack
         }