From 28b9d178e72752b63eaecee8c4d515edcf38cfb3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 23 Nov 2022 22:27:51 +0100 Subject: [PATCH] remove sensitivity dependencies --- .../activities/HistoryBrowseActivity.kt | 2 +- .../activities/HistoryBrowserData.kt | 2 +- .../nightscout/androidaps/di/AppModule.kt | 3 ++ .../IobCobCalculatorPlugin.kt | 2 +- .../iob/iobCobCalculator/IobCobOref1Worker.kt | 10 ++--- .../iob/iobCobCalculator/IobCobOrefWorker.kt | 12 ++---- .../events/EventIobCalculationProgress.kt | 2 +- ...Workflow.kt => CalculationWorkflowImpl.kt} | 40 ++++------------- .../workflow/PrepareBasalDataWorker.kt | 1 + .../PrepareIobAutosensGraphDataWorker.kt | 1 + .../PrepareTemporaryTargetDataWorker.kt | 1 + .../workflow/PrepareTreatmentsDataWorker.kt | 1 + .../androidaps/workflow/UpdateGraphWorker.kt | 1 + .../AbstractSensitivityPluginTest.kt | 2 + core/core-main/build.gradle | 2 +- .../core/workflow/CalculationWorkflow.kt | 43 +++++++++++++++++++ .../nightscout/interfaces/aps/Sensitivity.kt | 2 + .../sensitivity/SensitivityAAPSPlugin.kt | 2 + .../sensitivity/SensitivityOref1Plugin.kt | 2 + .../SensitivityWeightedAveragePlugin.kt | 2 + 20 files changed, 82 insertions(+), 51 deletions(-) rename app/src/main/java/info/nightscout/androidaps/workflow/{CalculationWorkflow.kt => CalculationWorkflowImpl.kt} (90%) create mode 100644 core/core-main/src/main/java/info/nightscout/core/workflow/CalculationWorkflow.kt diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt index f4dd193276..24325621b1 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt @@ -17,9 +17,9 @@ import info.nightscout.androidaps.plugins.general.overview.OverviewMenus import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress -import info.nightscout.androidaps.workflow.CalculationWorkflow import info.nightscout.core.activities.NoSplashAppCompatActivity import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.DefaultValueHelper diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowserData.kt b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowserData.kt index af6571bcaa..5881d27196 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowserData.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowserData.kt @@ -2,9 +2,9 @@ package info.nightscout.androidaps.activities import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.workflow.CalculationWorkflow import info.nightscout.core.graph.OverviewData import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.implementation.overview.OverviewDataImpl import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt index f9bb1b017b..1f7cc74501 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt @@ -13,7 +13,9 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImpl import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsImpl import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin +import info.nightscout.androidaps.workflow.CalculationWorkflowImpl import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.implementation.constraints.ConstraintsImpl import info.nightscout.interfaces.Config @@ -107,6 +109,7 @@ open class AppModule { @Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator @Binds fun bindDataSyncSelectorInterface(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector @Binds fun bindActivityNamesInterface(activityNames: ActivityNamesImpl): ActivityNames + @Binds fun bindCalculationWorkflowInterface(calculationWorkflow: CalculationWorkflowImpl): CalculationWorkflow } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt index 4885ba4283..d329d1e4b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt @@ -7,7 +7,6 @@ import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.extensions.convertedToAbsolute import info.nightscout.androidaps.extensions.iobCalc import info.nightscout.androidaps.extensions.toTemporaryBasal -import info.nightscout.androidaps.workflow.CalculationWorkflow import info.nightscout.core.graph.OverviewData import info.nightscout.core.iob.combine import info.nightscout.core.iob.copy @@ -15,6 +14,7 @@ import info.nightscout.core.iob.determineBasalJson import info.nightscout.core.iob.plus import info.nightscout.core.iob.round import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.ExtendedBolus import info.nightscout.database.entities.TemporaryBasal diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt index 9eff73ecf4..8ddde447f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt @@ -10,10 +10,10 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.extensions.target import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress -import info.nightscout.androidaps.workflow.CalculationWorkflow import info.nightscout.core.events.EventNewNotification import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config @@ -31,8 +31,6 @@ import info.nightscout.rx.events.Event import info.nightscout.rx.events.EventAutosensCalculationFinished import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag -import info.nightscout.sensitivity.SensitivityAAPSPlugin -import info.nightscout.sensitivity.SensitivityWeightedAveragePlugin import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil @@ -56,8 +54,6 @@ class IobCobOref1Worker( @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var context: Context - @Inject lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin - @Inject lateinit var sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var config: Config @Inject lateinit var profiler: Profiler @@ -202,7 +198,7 @@ class IobCobOref1Worker( val recentCarbTreatments = repository.getCarbsDataFromTimeToTimeExpanded(bgTime - T.mins(5).msecs(), bgTime, true).blockingGet() for (recentCarbTreatment in recentCarbTreatments) { autosensData.carbsFromBolus += recentCarbTreatment.amount - val isAAPSOrWeighted = sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled() + val isAAPSOrWeighted = activePlugin.activeSensitivity.isMinCarbsAbsorptionDynamic autosensData.activeCarbsList.add(fromCarbs(recentCarbTreatment, isAAPSOrWeighted, profileFunction, aapsLogger, dateUtil, sp)) autosensData.pastSensitivity += "[" + DecimalFormatter.to0Decimal(recentCarbTreatment.amount) + "g]" } @@ -227,7 +223,7 @@ class IobCobOref1Worker( autosensData.type = previous.type autosensData.uam = previous.uam } - val isAAPSOrWeighted = sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled() + val isAAPSOrWeighted = activePlugin.activeSensitivity.isMinCarbsAbsorptionDynamic autosensData.removeOldCarbs(bgTime, isAAPSOrWeighted) autosensData.cob += autosensData.carbsFromBolus autosensData.mealCarbs += autosensData.carbsFromBolus diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOrefWorker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOrefWorker.kt index ed9a466b66..98931733e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOrefWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOrefWorker.kt @@ -9,10 +9,10 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress -import info.nightscout.androidaps.workflow.CalculationWorkflow import info.nightscout.core.events.EventNewNotification import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants @@ -29,8 +29,6 @@ import info.nightscout.rx.events.Event import info.nightscout.rx.events.EventAutosensCalculationFinished import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag -import info.nightscout.sensitivity.SensitivityAAPSPlugin -import info.nightscout.sensitivity.SensitivityWeightedAveragePlugin import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil @@ -52,8 +50,6 @@ class IobCobOrefWorker @Inject internal constructor( @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var context: Context - @Inject lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin - @Inject lateinit var sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var config: Config @Inject lateinit var profiler: Profiler @@ -197,7 +193,7 @@ class IobCobOrefWorker @Inject internal constructor( val recentCarbTreatments = repository.getCarbsDataFromTimeToTimeExpanded(bgTime - T.mins(5).msecs(), bgTime, true).blockingGet() for (recentCarbTreatment in recentCarbTreatments) { autosensData.carbsFromBolus += recentCarbTreatment.amount - val isAAPSOrWeighted = sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled() + val isAAPSOrWeighted = activePlugin.activeSensitivity.isMinCarbsAbsorptionDynamic autosensData.activeCarbsList.add(fromCarbs(recentCarbTreatment, isAAPSOrWeighted, profileFunction, aapsLogger, dateUtil, sp)) autosensData.pastSensitivity += "[" + DecimalFormatter.to0Decimal(recentCarbTreatment.amount) + "g]" } @@ -206,7 +202,7 @@ class IobCobOrefWorker @Inject internal constructor( if (previous != null && previous.cob > 0) { // calculate sum of min carb impact from all active treatments var totalMinCarbsImpact = 0.0 - if (sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled()) { + if (activePlugin.activeSensitivity.isMinCarbsAbsorptionDynamic) { //when the impact depends on a max time, sum them up as smaller carb sizes make them smaller for (ii in autosensData.activeCarbsList.indices) { val c = autosensData.activeCarbsList[ii] @@ -227,7 +223,7 @@ class IobCobOrefWorker @Inject internal constructor( autosensData.deductAbsorbedCarbs() autosensData.usedMinCarbsImpact = totalMinCarbsImpact } - val isAAPSOrWeighted = sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled() + val isAAPSOrWeighted = activePlugin.activeSensitivity.isMinCarbsAbsorptionDynamic autosensData.removeOldCarbs(bgTime, isAAPSOrWeighted) autosensData.cob += autosensData.carbsFromBolus autosensData.deviation = deviation diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.kt b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.kt index aef9156319..2e5ccddd12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events -import info.nightscout.androidaps.workflow.CalculationWorkflow +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.rx.events.Event class EventIobCalculationProgress(val pass: CalculationWorkflow.ProgressData, val progressPct: Int, val cause: Event?) : Event() \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt b/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt rename to app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt index 422347a555..3ed12c23a4 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt @@ -16,6 +16,9 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOrefWorker import info.nightscout.core.graph.OverviewData import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow +import info.nightscout.core.workflow.CalculationWorkflow.Companion.JOB +import info.nightscout.core.workflow.CalculationWorkflow.Companion.MAIN_CALCULATION import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.rx.AapsSchedulers @@ -28,7 +31,6 @@ import info.nightscout.rx.events.EventPreferenceChange import info.nightscout.rx.events.EventTherapyEventChange import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag -import info.nightscout.sensitivity.SensitivityOref1Plugin import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.utils.DateUtil import io.reactivex.rxjava3.disposables.CompositeDisposable @@ -37,7 +39,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class CalculationWorkflow @Inject constructor( +class CalculationWorkflowImpl @Inject constructor( aapsSchedulers: AapsSchedulers, rh: ResourceHelper, rxBus: RxBus, @@ -46,17 +48,9 @@ class CalculationWorkflow @Inject constructor( private val aapsLogger: AAPSLogger, private val fabricPrivacy: FabricPrivacy, private val dateUtil: DateUtil, - private val sensitivityOref1Plugin: SensitivityOref1Plugin, private val dataWorkerStorage: DataWorkerStorage, private val activePlugin: ActivePlugin -) { - - companion object { - - const val MAIN_CALCULATION = "calculation" - const val HISTORY_CALCULATION = "history_calculation" - const val JOB = "job" - } +) : CalculationWorkflow { private var disposable: CompositeDisposable = CompositeDisposable() @@ -65,26 +59,10 @@ class CalculationWorkflow @Inject constructor( private val overviewData: OverviewData get() = (iobCobCalculator as IobCobCalculatorPlugin).overviewData - enum class ProgressData(private val pass: Int, val percentOfTotal: Int) { - PREPARE_BASAL_DATA(0, 5), - PREPARE_TEMPORARY_TARGET_DATA(1, 5), - PREPARE_TREATMENTS_DATA(2, 5), - IOB_COB_OREF(3, 74), - PREPARE_IOB_AUTOSENS_DATA(4, 10), - DRAW(5, 1); - - fun finalPercent(progress: Int): Int { - var total = 0 - for (i in values()) if (i.pass < pass) total += i.percentOfTotal - total += (percentOfTotal.toDouble() * progress / 100.0).toInt() - return total - } - } - init { // Verify definition var sumPercent = 0 - for (pass in ProgressData.values()) sumPercent += pass.percentOfTotal + for (pass in CalculationWorkflow.ProgressData.values()) sumPercent += pass.percentOfTotal require(sumPercent == 100) disposable += rxBus @@ -131,7 +109,7 @@ class CalculationWorkflow @Inject constructor( } - fun stopCalculation(job: String, from: String) { + override fun stopCalculation(job: String, from: String) { aapsLogger.debug(LTag.AUTOSENS, "Stopping calculation thread: $from") WorkManager.getInstance(context).cancelUniqueWork(job) val workStatus = WorkManager.getInstance(context).getWorkInfosForUniqueWork(job).get() @@ -140,7 +118,7 @@ class CalculationWorkflow @Inject constructor( aapsLogger.debug(LTag.AUTOSENS, "Calculation thread stopped: $from") } - fun runCalculation( + override fun runCalculation( job: String, iobCobCalculator: IobCobCalculator, overviewData: OverviewData, @@ -195,7 +173,7 @@ class CalculationWorkflow @Inject constructor( .build() ) .then( - if (sensitivityOref1Plugin.isEnabled()) + if (activePlugin.activeSensitivity.isOref1) OneTimeWorkRequest.Builder(IobCobOref1Worker::class.java) .setInputData(dataWorkerStorage.storeInputData(IobCobOref1Worker.IobCobOref1WorkerData(injector, iobCobCalculator, from, end, limitDataToOldestAvailable, cause))) .build() diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareBasalDataWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareBasalDataWorker.kt index 333c62d807..4ae82c114e 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareBasalDataWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareBasalDataWorker.kt @@ -13,6 +13,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCa import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.data.ScaledDataPoint import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.rx.bus.RxBus diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt index c4b7555cec..b8cee66a13 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt @@ -23,6 +23,7 @@ import info.nightscout.core.graph.data.ScaledDataPoint import info.nightscout.core.iob.combine import info.nightscout.core.iob.copy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.AutosensResult diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt index db7bb5c7cc..8ef17e6e1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt @@ -12,6 +12,7 @@ import info.nightscout.androidaps.extensions.target import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress import info.nightscout.core.graph.OverviewData import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.Loop diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTreatmentsDataWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTreatmentsDataWorker.kt index 8a3345a86f..3e301a8704 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTreatmentsDataWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTreatmentsDataWorker.kt @@ -15,6 +15,7 @@ import info.nightscout.core.graph.data.ExtendedBolusDataPoint import info.nightscout.core.graph.data.PointsWithLabelGraphSeries import info.nightscout.core.graph.data.TherapyEventDataPoint import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt index 9a61557e6b..6a7bd0818b 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt @@ -7,6 +7,7 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress +import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.rx.bus.RxBus import javax.inject.Inject diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt index fe83cb0932..a06b0edfe1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt @@ -32,6 +32,8 @@ class AbstractSensitivityPluginTest : TestBase() { get() = Sensitivity.SensitivityType.UNKNOWN override fun maxAbsorptionHours(): Double = 8.0 + override val isMinCarbsAbsorptionDynamic: Boolean = true + override val isOref1: Boolean = true override fun configuration(): JSONObject = JSONObject() diff --git a/core/core-main/build.gradle b/core/core-main/build.gradle index bb4a98a5ee..3eec4adfe2 100644 --- a/core/core-main/build.gradle +++ b/core/core-main/build.gradle @@ -14,12 +14,12 @@ apply from: "${project.rootDir}/core/core-main/test_dependencies.gradle" apply from: "${project.rootDir}/core/core-main/jacoco_global.gradle" dependencies { - implementation project(':graphview') implementation project(':app-wear-shared:rx') implementation project(':app-wear-shared:shared') implementation project(':database:entities') implementation project(':database:impl') implementation project(':interfaces') + implementation project(':core:graph') implementation project(':core:ui') implementation project(':core:utils') diff --git a/core/core-main/src/main/java/info/nightscout/core/workflow/CalculationWorkflow.kt b/core/core-main/src/main/java/info/nightscout/core/workflow/CalculationWorkflow.kt new file mode 100644 index 0000000000..33fad48d37 --- /dev/null +++ b/core/core-main/src/main/java/info/nightscout/core/workflow/CalculationWorkflow.kt @@ -0,0 +1,43 @@ +package info.nightscout.core.workflow + +import info.nightscout.core.graph.OverviewData +import info.nightscout.interfaces.iob.IobCobCalculator +import info.nightscout.rx.events.Event + +interface CalculationWorkflow { + companion object { + + const val MAIN_CALCULATION = "calculation" + const val HISTORY_CALCULATION = "history_calculation" + const val JOB = "job" + } + + enum class ProgressData(private val pass: Int, val percentOfTotal: Int) { + PREPARE_BASAL_DATA(0, 5), + PREPARE_TEMPORARY_TARGET_DATA(1, 5), + PREPARE_TREATMENTS_DATA(2, 5), + IOB_COB_OREF(3, 74), + PREPARE_IOB_AUTOSENS_DATA(4, 10), + DRAW(5, 1); + + fun finalPercent(progress: Int): Int { + var total = 0 + for (i in values()) if (i.pass < pass) total += i.percentOfTotal + total += (percentOfTotal.toDouble() * progress / 100.0).toInt() + return total + } + } + + fun stopCalculation(job: String, from: String) + fun runCalculation( + job: String, + iobCobCalculator: IobCobCalculator, + overviewData: OverviewData, + from: String, + end: Long, + bgDataReload: Boolean, + limitDataToOldestAvailable: Boolean, + cause: Event?, + runLoop: Boolean + ) +} \ No newline at end of file diff --git a/interfaces/src/main/java/info/nightscout/interfaces/aps/Sensitivity.kt b/interfaces/src/main/java/info/nightscout/interfaces/aps/Sensitivity.kt index 56d07d12a0..e6bc828726 100644 --- a/interfaces/src/main/java/info/nightscout/interfaces/aps/Sensitivity.kt +++ b/interfaces/src/main/java/info/nightscout/interfaces/aps/Sensitivity.kt @@ -21,6 +21,8 @@ interface Sensitivity : ConfigExportImport { fun detectSensitivity(ads: AutosensDataStore, fromTime: Long, toTime: Long): AutosensResult fun maxAbsorptionHours(): Double + val isMinCarbsAbsorptionDynamic: Boolean + val isOref1: Boolean companion object { const val MIN_HOURS = 1.0 diff --git a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt index 693778a08b..97ee837b6a 100644 --- a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt +++ b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt @@ -140,6 +140,8 @@ class SensitivityAAPSPlugin @Inject constructor( } override fun maxAbsorptionHours(): Double = sp.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME) + override val isMinCarbsAbsorptionDynamic: Boolean = true + override val isOref1: Boolean = false override val id: SensitivityType get() = SensitivityType.SENSITIVITY_AAPS diff --git a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt index 6c3d24e0db..38df71bc72 100644 --- a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt +++ b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt @@ -205,6 +205,8 @@ class SensitivityOref1Plugin @Inject constructor( } override fun maxAbsorptionHours(): Double = sp.getDouble(R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME) + override val isMinCarbsAbsorptionDynamic: Boolean = false + override val isOref1: Boolean = true override fun configuration(): JSONObject { val c = JSONObject() diff --git a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt index e93080e3e6..63ab4ed9f7 100644 --- a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt +++ b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt @@ -160,6 +160,8 @@ class SensitivityWeightedAveragePlugin @Inject constructor( } override fun maxAbsorptionHours(): Double = sp.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME) + override val isMinCarbsAbsorptionDynamic: Boolean = true + override val isOref1: Boolean = false override val id: SensitivityType get() = SensitivityType.SENSITIVITY_WEIGHTED