reset AS on PS instead of EPS

This commit is contained in:
Milos Kozak 2021-11-29 23:13:52 +01:00
parent 370b504d74
commit 102f73fbc9
5 changed files with 47 additions and 47 deletions

View file

@ -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<Double> = 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)"
}

View file

@ -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)"
}

View file

@ -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<Double>()
@ -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)"
}

View file

@ -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<EffectiveProfileSwitch>.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))

View file

@ -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<ProfileSwitch>.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))