diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.kt index 36bda32853..e382ed36eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.kt @@ -6,7 +6,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.TherapyEvent -import info.nightscout.androidaps.extensions.isEPSEvent5minBack +import info.nightscout.androidaps.extensions.isPSEvent5minBack import info.nightscout.androidaps.extensions.isTherapyEventEvent5minBack import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType @@ -38,13 +38,14 @@ class SensitivityAAPSPlugin @Inject constructor( private val profileFunction: ProfileFunction, private val dateUtil: DateUtil, private val repository: AppRepository -) : AbstractSensitivityPlugin(PluginDescription() - .mainType(PluginType.SENSITIVITY) - .pluginIcon(R.drawable.ic_generic_icon) - .pluginName(R.string.sensitivityaaps) - .shortName(R.string.sensitivity_shortname) - .preferencesId(R.xml.pref_absorption_aaps) - .description(R.string.description_sensitivity_aaps), +) : AbstractSensitivityPlugin( + PluginDescription() + .mainType(PluginType.SENSITIVITY) + .pluginIcon(R.drawable.ic_generic_icon) + .pluginName(R.string.sensitivityaaps) + .shortName(R.string.sensitivity_shortname) + .preferencesId(R.xml.pref_absorption_aaps) + .description(R.string.description_sensitivity_aaps), injector, aapsLogger, rh, sp ) { @@ -70,7 +71,7 @@ class SensitivityAAPSPlugin @Inject constructor( return AutosensResult() } val siteChanges = repository.getTherapyEventDataFromTime(fromTime, TherapyEvent.Type.CANNULA_CHANGE, true).blockingGet() - val profileSwitches = repository.getEffectiveProfileSwitchDataFromTime(fromTime, true).blockingGet() + val profileSwitches = repository.getProfileSwitchDataFromTime(fromTime, true).blockingGet() val deviationsArray: MutableList = ArrayList() var pastSensitivity = "" var index = 0 @@ -92,7 +93,7 @@ class SensitivityAAPSPlugin @Inject constructor( } // reset deviations after profile switch - if (profileSwitches.isEPSEvent5minBack(autosensData.time)) { + if (profileSwitches.isPSEvent5minBack(autosensData.time)) { deviationsArray.clear() pastSensitivity += "(PROFILESWITCH)" } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.kt index 85a31e70cb..56b6770796 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.kt @@ -6,7 +6,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.TherapyEvent -import info.nightscout.androidaps.extensions.isEPSEvent5minBack +import info.nightscout.androidaps.extensions.isPSEvent5minBack import info.nightscout.androidaps.extensions.isTherapyEventEvent5minBack import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType @@ -39,15 +39,16 @@ class SensitivityOref1Plugin @Inject constructor( private val profileFunction: ProfileFunction, private val dateUtil: DateUtil, private val repository: AppRepository -) : AbstractSensitivityPlugin(PluginDescription() - .mainType(PluginType.SENSITIVITY) - .pluginIcon(R.drawable.ic_generic_icon) - .pluginName(R.string.sensitivityoref1) - .shortName(R.string.sensitivity_shortname) - .enableByDefault(true) - .preferencesId(R.xml.pref_absorption_oref1) - .description(R.string.description_sensitivity_oref1) - .setDefault(), +) : AbstractSensitivityPlugin( + PluginDescription() + .mainType(PluginType.SENSITIVITY) + .pluginIcon(R.drawable.ic_generic_icon) + .pluginName(R.string.sensitivityoref1) + .shortName(R.string.sensitivity_shortname) + .enableByDefault(true) + .preferencesId(R.xml.pref_absorption_oref1) + .description(R.string.description_sensitivity_oref1) + .setDefault(), injector, aapsLogger, rh, sp ) { @@ -71,7 +72,7 @@ class SensitivityOref1Plugin @Inject constructor( return AutosensResult() } val siteChanges = repository.getTherapyEventDataFromTime(fromTime, TherapyEvent.Type.CANNULA_CHANGE, true).blockingGet() - val profileSwitches = repository.getEffectiveProfileSwitchDataFromTime(fromTime, true).blockingGet() + val profileSwitches = repository.getProfileSwitchDataFromTime(fromTime, true).blockingGet() //[0] = 8 hour //[1] = 24 hour @@ -108,7 +109,7 @@ class SensitivityOref1Plugin @Inject constructor( } // reset deviations after profile switch - if (profileSwitches.isEPSEvent5minBack(autosensData.time)) { + if (profileSwitches.isPSEvent5minBack(autosensData.time)) { deviationsArray.clear() pastSensitivity += "(PROFILESWITCH)" } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.kt index 00a5ea432e..4be4c1eacb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.kt @@ -7,7 +7,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.TherapyEvent -import info.nightscout.androidaps.extensions.isEPSEvent5minBack +import info.nightscout.androidaps.extensions.isPSEvent5minBack import info.nightscout.androidaps.extensions.isTherapyEventEvent5minBack import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType @@ -37,13 +37,14 @@ class SensitivityWeightedAveragePlugin @Inject constructor( private val profileFunction: ProfileFunction, private val dateUtil: DateUtil, private val repository: AppRepository -) : AbstractSensitivityPlugin(PluginDescription() - .mainType(PluginType.SENSITIVITY) - .pluginIcon(R.drawable.ic_generic_icon) - .pluginName(R.string.sensitivityweightedaverage) - .shortName(R.string.sensitivity_shortname) - .preferencesId(R.xml.pref_absorption_aaps) - .description(R.string.description_sensitivity_weighted_average), +) : AbstractSensitivityPlugin( + PluginDescription() + .mainType(PluginType.SENSITIVITY) + .pluginIcon(R.drawable.ic_generic_icon) + .pluginName(R.string.sensitivityweightedaverage) + .shortName(R.string.sensitivity_shortname) + .preferencesId(R.xml.pref_absorption_aaps) + .description(R.string.description_sensitivity_weighted_average), injector, aapsLogger, rh, sp ) { @@ -69,7 +70,7 @@ class SensitivityWeightedAveragePlugin @Inject constructor( return AutosensResult() } val siteChanges = repository.getTherapyEventDataFromTime(fromTime, TherapyEvent.Type.CANNULA_CHANGE, true).blockingGet() - val profileSwitches = repository.getEffectiveProfileSwitchDataFromTime(fromTime, true).blockingGet() + val profileSwitches = repository.getProfileSwitchDataFromTime(fromTime, true).blockingGet() var pastSensitivity = "" var index = 0 val data = LongSparseArray() @@ -95,7 +96,7 @@ class SensitivityWeightedAveragePlugin @Inject constructor( } // reset deviations after profile switch - if (profileSwitches.isEPSEvent5minBack(autosensData.time)) { + if (profileSwitches.isPSEvent5minBack(autosensData.time)) { data.clear() pastSensitivity += "(PROFILESWITCH)" } diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/EffectiveProfileSwitchExtension.kt b/core/src/main/java/info/nightscout/androidaps/extensions/EffectiveProfileSwitchExtension.kt index 38c7e0a208..009f143aca 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/EffectiveProfileSwitchExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/EffectiveProfileSwitchExtension.kt @@ -7,21 +7,8 @@ import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.JsonHelper -import info.nightscout.androidaps.utils.T.Companion.mins import org.json.JSONObject -fun List.isEPSEvent5minBack(time: Long): Boolean { - for (event in this) { - if (event.timestamp <= time && event.timestamp > time - mins(5).msecs()) { - if (event.originalDuration == 0L) { - //aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + dateUtil.dateAndTimeString(time) + " " + event.toString()) - return true - } - } - } - return false -} - fun EffectiveProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject = JSONObject() .put("created_at", dateUtil.toISOString(timestamp)) diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/ProfileSwitchExtension.kt b/core/src/main/java/info/nightscout/androidaps/extensions/ProfileSwitchExtension.kt index 876a544300..08664282ff 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/ProfileSwitchExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/ProfileSwitchExtension.kt @@ -5,11 +5,9 @@ import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.database.embedments.InterfaceIDs import info.nightscout.androidaps.database.entities.ProfileSwitch -import info.nightscout.androidaps.database.entities.TemporaryBasal import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter.to2Decimal import info.nightscout.androidaps.utils.JsonHelper @@ -17,6 +15,18 @@ import info.nightscout.androidaps.utils.T import org.json.JSONObject import java.util.* +fun List.isPSEvent5minBack(time: Long): Boolean { + for (event in this) { + if (event.timestamp <= time && event.timestamp > time - T.mins(5).msecs()) { + if (event.duration == 0L) { + //aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + dateUtil.dateAndTimeString(time) + " " + event.toString()) + return true + } + } + } + return false +} + fun ProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject = JSONObject() .put("created_at", dateUtil.toISOString(timestamp))