Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ final class LoopDataManager: ObservableObject {
dosingStrategy = settingsProvider.settings.automaticDosingStrategy
}
input.recommendationType = dosingStrategy.recommendationType
dosingDecision.algorithmExperiments = algorithmExperiments(for: dosingStrategy)

guard let latestGlucose = input.glucoseHistory.last else {
throw LoopError.missingDataError(.glucose)
Expand Down Expand Up @@ -889,6 +890,7 @@ final class LoopDataManager: ObservableObject {

if let output = displayState.output {
var dosingDecision = StoredDosingDecision(date: now, reason: "updateRemoteRecommendation")
dosingDecision.algorithmExperiments = algorithmExperiments(for: currentDosingStrategy)
dosingDecision.predictedGlucose = output.predictedGlucose
dosingDecision.insulinOnBoard = displayState.activeInsulin
dosingDecision.carbsOnBoard = displayState.activeCarbs
Expand Down Expand Up @@ -1025,8 +1027,24 @@ extension LoopDataManager {
}
}

private var currentDosingStrategy: AutomaticDosingStrategy {
dosingStrategySelectionEnabled ? settingsProvider.settings.automaticDosingStrategy : .automaticBolus
}

/// Glucose based partial application only affects automatic boluses, so it is in effect only with that strategy
private func algorithmExperiments(for dosingStrategy: AutomaticDosingStrategy) -> [AlgorithmExperiment] {
var experiments: [AlgorithmExperiment] = []
if UserDefaults.standard.integralRetrospectiveCorrectionEnabled {
experiments.append(AlgorithmExperiment(identifier: "integralRetrospectiveCorrection"))
}
if UserDefaults.standard.glucoseBasedApplicationFactorEnabled && dosingStrategy == .automaticBolus {
experiments.append(AlgorithmExperiment(identifier: "glucoseBasedApplicationFactor"))
}
return experiments
}

func storeManualBolusDosingDecision(_ bolusDosingDecision: BolusDosingDecision, withDate date: Date) async {
let dosingDecision = StoredDosingDecision(id: bolusDosingDecision.id,
var dosingDecision = StoredDosingDecision(id: bolusDosingDecision.id,
date: date,
reason: bolusDosingDecision.reason.rawValue,
settings: StoredDosingDecision.Settings(settingsProvider.settings),
Expand All @@ -1045,6 +1063,7 @@ extension LoopDataManager {
predictedGlucose: bolusDosingDecision.predictedGlucose,
manualBolusRecommendation: bolusDosingDecision.manualBolusRecommendation,
manualBolusRequested: bolusDosingDecision.manualBolusRequested)
dosingDecision.algorithmExperiments = algorithmExperiments(for: currentDosingStrategy)
Task { await dosingDecisionStore.storeDosingDecision(dosingDecision) }
}

Expand Down