move out of :core:main

This commit is contained in:
Milos Kozak 2022-12-09 11:47:57 +01:00
parent d34bcbf74f
commit 8791e93cc9
35 changed files with 146 additions and 125 deletions

View file

@ -132,7 +132,7 @@
</provider> </provider>
<service <service
android:name="info.nightscout.core.services.AlarmSoundService" android:name="info.nightscout.ui.services.AlarmSoundService"
android:enabled="true" android:enabled="true"
android:exported="true" /> android:exported="true" />
<uses-library <uses-library

View file

@ -14,8 +14,8 @@ import info.nightscout.androidaps.activities.MyPreferenceFragment
import info.nightscout.androidaps.activities.PreferencesActivity import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.configuration.activities.SingleFragmentActivity import info.nightscout.configuration.activities.SingleFragmentActivity
import info.nightscout.core.events.EventNewNotification import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.services.AlarmSoundService import info.nightscout.ui.services.AlarmSoundService
import info.nightscout.core.services.AlarmSoundServiceHelper import info.nightscout.ui.services.AlarmSoundServiceHelper
import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.nsclient.NSAlarm import info.nightscout.interfaces.nsclient.NSAlarm

View file

@ -8,6 +8,7 @@ import info.nightscout.interfaces.iob.IobTotal
import org.json.JSONObject import org.json.JSONObject
interface APSResult { interface APSResult {
var date: Long
var json: JSONObject? var json: JSONObject?
var reason: String var reason: String
var rate: Double var rate: Double

View file

@ -18,8 +18,13 @@ interface AutosensData {
var pastSensitivity: String var pastSensitivity: String
var deviation: Double var deviation: Double
var validDeviation: Boolean var validDeviation: Boolean
var activeCarbsList: MutableList<CarbsInPast>
var absorbed: Double
var carbsFromBolus: Double var carbsFromBolus: Double
var cob: Double var cob: Double
var bgi: Double
var delta: Double
var avgDelta: Double
var slopeFromMaxDeviation: Double var slopeFromMaxDeviation: Double
var slopeFromMinDeviation: Double var slopeFromMinDeviation: Double
var usedMinCarbsImpact: Double var usedMinCarbsImpact: Double
@ -37,4 +42,6 @@ interface AutosensData {
var autosensResult: AutosensResult var autosensResult: AutosensResult
fun cloneCarbsList(): MutableList<CarbsInPast> fun cloneCarbsList(): MutableList<CarbsInPast>
fun deductAbsorbedCarbs()
fun removeOldCarbs(toTime: Long, isAAPSOrWeighted: Boolean)
} }

View file

@ -57,4 +57,6 @@ interface Loop {
runningConfiguration: RunningConfiguration, runningConfiguration: RunningConfiguration,
version: String version: String
): DeviceStatus? ): DeviceStatus?
fun provideEmptyAPSResultObject(): APSResult
} }

View file

@ -104,4 +104,6 @@ interface IobCobCalculator {
* @return IobTotal * @return IobTotal
*/ */
fun calculateIobFromTempBasalsIncludingConvertedExtended(): IobTotal fun calculateIobFromTempBasalsIncludingConvertedExtended(): IobTotal
fun provideEmptyAutosensDataObject(): AutosensData
} }

View file

@ -2,8 +2,6 @@ package info.nightscout.core.di
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.core.aps.APSResultObject
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject
import info.nightscout.core.wizard.BolusWizard import info.nightscout.core.wizard.BolusWizard
import info.nightscout.core.wizard.QuickWizardEntry import info.nightscout.core.wizard.QuickWizardEntry
import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.pump.PumpEnactResult
@ -13,8 +11,6 @@ import info.nightscout.interfaces.pump.PumpEnactResult
abstract class CoreDataClassesModule { abstract class CoreDataClassesModule {
@ContributesAndroidInjector abstract fun pumpEnactResultInjector(): PumpEnactResult @ContributesAndroidInjector abstract fun pumpEnactResultInjector(): PumpEnactResult
@ContributesAndroidInjector abstract fun apsResultInjector(): APSResultObject
@ContributesAndroidInjector abstract fun autosensDataInjector(): AutosensDataObject
@ContributesAndroidInjector abstract fun bolusWizardInjector(): BolusWizard @ContributesAndroidInjector abstract fun bolusWizardInjector(): BolusWizard
@ContributesAndroidInjector abstract fun quickWizardEntryInjector(): QuickWizardEntry @ContributesAndroidInjector abstract fun quickWizardEntryInjector(): QuickWizardEntry
} }

View file

@ -5,14 +5,11 @@ import android.os.Build
import android.telephony.SmsManager import android.telephony.SmsManager
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
import dagger.android.ContributesAndroidInjector
import info.nightscout.core.services.AlarmSoundService
@Module( @Module(
includes = [ includes = [
CoreDataClassesModule::class, CoreDataClassesModule::class,
PreferencesModule::class, PreferencesModule::class
ServicesModule::class
] ]
) )
open class CoreModule { open class CoreModule {

View file

@ -1,12 +0,0 @@
package info.nightscout.core.di
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.core.services.AlarmSoundService
@Module
@Suppress("unused")
abstract class ServicesModule {
@ContributesAndroidInjector abstract fun contributesAlarmSoundService(): AlarmSoundService
}

View file

@ -1,2 +0,0 @@
package info.nightscout.core.profile

View file

@ -1,9 +1,10 @@
package info.nightscout.core.aps package info.nightscout.plugins.aps
import android.text.Spanned import android.text.Spanned
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.extensions.convertedToAbsolute import info.nightscout.core.extensions.convertedToAbsolute
import info.nightscout.core.extensions.convertedToPercent import info.nightscout.core.extensions.convertedToPercent
import info.nightscout.core.ui.R
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.aps.APSResult import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
@ -14,7 +15,7 @@ import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.pump.defs.PumpDescription import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.DecimalFormatter
import info.nightscout.interfaces.utils.HtmlHelper.fromHtml import info.nightscout.interfaces.utils.HtmlHelper
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
@ -41,7 +42,7 @@ open class APSResultObject @Inject constructor(val injector: HasAndroidInjector)
@Inject lateinit var rh: ResourceHelper @Inject lateinit var rh: ResourceHelper
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
var date: Long = 0 override var date: Long = 0
override var reason: String = "" override var reason: String = ""
override var rate = 0.0 override var rate = 0.0
override var percent = 0 override var percent = 0
@ -116,11 +117,11 @@ open class APSResultObject @Inject constructor(val injector: HasAndroidInjector)
// reason // reason
ret += "<b>" + rh.gs(info.nightscout.core.ui.R.string.reason) + "</b>: " + reason.replace("<", "&lt;").replace(">", "&gt;") ret += "<b>" + rh.gs(info.nightscout.core.ui.R.string.reason) + "</b>: " + reason.replace("<", "&lt;").replace(">", "&gt;")
return fromHtml(ret) return HtmlHelper.fromHtml(ret)
} }
return if (isCarbsRequired) { return if (isCarbsRequired) {
fromHtml(carbsRequiredText) HtmlHelper.fromHtml(carbsRequiredText)
} else fromHtml(rh.gs(info.nightscout.core.ui.R.string.nochangerequested)) } else HtmlHelper.fromHtml(rh.gs(R.string.nochangerequested))
} }
override fun newAndClone(injector: HasAndroidInjector): APSResult { override fun newAndClone(injector: HasAndroidInjector): APSResult {

View file

@ -3,8 +3,10 @@ package info.nightscout.plugins.aps.di
import dagger.Binds import dagger.Binds
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.autotune.Autotune import info.nightscout.interfaces.autotune.Autotune
import info.nightscout.plugins.aps.APSResultObject
import info.nightscout.plugins.aps.OpenAPSFragment import info.nightscout.plugins.aps.OpenAPSFragment
import info.nightscout.plugins.aps.loop.LoopPlugin import info.nightscout.plugins.aps.loop.LoopPlugin
import info.nightscout.plugins.general.autotune.AutotunePlugin import info.nightscout.plugins.general.autotune.AutotunePlugin
@ -22,6 +24,7 @@ import info.nightscout.plugins.general.autotune.AutotunePlugin
abstract class ApsModule { abstract class ApsModule {
@ContributesAndroidInjector abstract fun contributesOpenAPSFragment(): OpenAPSFragment @ContributesAndroidInjector abstract fun contributesOpenAPSFragment(): OpenAPSFragment
@ContributesAndroidInjector abstract fun apsResultInjector(): APSResultObject
@Module @Module
interface Bindings { interface Bindings {

View file

@ -2,10 +2,12 @@ package info.nightscout.plugins.aps.di
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.plugins.aps.loop.CarbSuggestionReceiver
import info.nightscout.plugins.aps.loop.LoopFragment
@Module @Module
@Suppress("unused") @Suppress("unused")
abstract class LoopModule { abstract class LoopModule {
@ContributesAndroidInjector abstract fun contributesLoopFragment(): info.nightscout.plugins.aps.loop.LoopFragment @ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment
@ContributesAndroidInjector abstract fun contributesCarbSuggestionReceiver(): info.nightscout.plugins.aps.loop.CarbSuggestionReceiver @ContributesAndroidInjector abstract fun contributesCarbSuggestionReceiver(): CarbSuggestionReceiver
} }

View file

@ -57,6 +57,7 @@ import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.interfaces.utils.HardLimits import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.plugins.aps.APSResultObject
import info.nightscout.plugins.aps.R import info.nightscout.plugins.aps.R
import info.nightscout.plugins.aps.loop.events.EventLoopSetLastRunGui import info.nightscout.plugins.aps.loop.events.EventLoopSetLastRunGui
import info.nightscout.plugins.aps.loop.extensions.json import info.nightscout.plugins.aps.loop.extensions.json
@ -782,6 +783,9 @@ class LoopPlugin @Inject constructor(
configuration = runningConfiguration.configuration().toString() configuration = runningConfiguration.configuration().toString()
) )
} }
override fun provideEmptyAPSResultObject(): APSResult = APSResultObject(injector)
companion object { companion object {
private const val CHANNEL_ID = "AAPS-OpenLoop" private const val CHANNEL_ID = "AAPS-OpenLoop"

View file

@ -1,7 +1,7 @@
package info.nightscout.plugins.aps.openAPSAMA package info.nightscout.plugins.aps.openAPSAMA
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.aps.APSResultObject import info.nightscout.plugins.aps.APSResultObject
import info.nightscout.core.extensions.convertedToAbsolute import info.nightscout.core.extensions.convertedToAbsolute
import info.nightscout.core.extensions.getPassedDurationToTimeInMinutes import info.nightscout.core.extensions.getPassedDurationToTimeInMinutes
import info.nightscout.core.extensions.plannedRemainingMinutes import info.nightscout.core.extensions.plannedRemainingMinutes

View file

@ -1,7 +1,7 @@
package info.nightscout.plugins.aps.openAPSAMA package info.nightscout.plugins.aps.openAPSAMA
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.aps.APSResultObject import info.nightscout.plugins.aps.APSResultObject
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject

View file

@ -1,7 +1,7 @@
package info.nightscout.plugins.aps.openAPSSMB package info.nightscout.plugins.aps.openAPSSMB
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.aps.APSResultObject import info.nightscout.plugins.aps.APSResultObject
import info.nightscout.core.extensions.convertedToAbsolute import info.nightscout.core.extensions.convertedToAbsolute
import info.nightscout.core.extensions.getPassedDurationToTimeInMinutes import info.nightscout.core.extensions.getPassedDurationToTimeInMinutes
import info.nightscout.core.extensions.plannedRemainingMinutes import info.nightscout.core.extensions.plannedRemainingMinutes

View file

@ -1,7 +1,7 @@
package info.nightscout.plugins.aps.openAPSSMB package info.nightscout.plugins.aps.openAPSSMB
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.aps.APSResultObject import info.nightscout.plugins.aps.APSResultObject
import info.nightscout.interfaces.aps.VariableSensitivityResult import info.nightscout.interfaces.aps.VariableSensitivityResult
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import org.json.JSONException import org.json.JSONException

View file

@ -38,6 +38,7 @@ open class TestBaseWithProfile : TestBase() {
@Mock lateinit var context: Context @Mock lateinit var context: Context
lateinit var dateUtil: DateUtil lateinit var dateUtil: DateUtil
lateinit var testPumpPlugin: TestPumpPlugin
val rxBus = RxBus(aapsSchedulers, aapsLogger) val rxBus = RxBus(aapsSchedulers, aapsLogger)
val profileInjector = HasAndroidInjector { AndroidInjector { } } val profileInjector = HasAndroidInjector { AndroidInjector { } }
@ -56,6 +57,8 @@ open class TestBaseWithProfile : TestBase() {
dateUtil = Mockito.spy(DateUtil(context)) dateUtil = Mockito.spy(DateUtil(context))
`when`(dateUtil.now()).thenReturn(1656358822000) `when`(dateUtil.now()).thenReturn(1656358822000)
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!) validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
testPumpPlugin = TestPumpPlugin(profileInjector)
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
effectiveProfileSwitch = EffectiveProfileSwitch( effectiveProfileSwitch = EffectiveProfileSwitch(
timestamp = dateUtil.now(), timestamp = dateUtil.now(),
basalBlocks = validProfile.basalBlocks, basalBlocks = validProfile.basalBlocks,

View file

@ -1,17 +1,16 @@
package info.nightscout.androidaps.plugins.aps.loop package info.nightscout.plugins.aps.loop
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.core.aps.APSResultObject
import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.interfaces.aps.APSResult import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.utils.JsonHelper.safeGetDouble import info.nightscout.interfaces.utils.JsonHelper.safeGetDouble
import org.junit.Assert import info.nightscout.shared.sharedPreferences.SP
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
@ -21,7 +20,7 @@ import org.mockito.Mockito.`when`
class APSResultTest : TestBaseWithProfile() { class APSResultTest : TestBaseWithProfile() {
@Mock lateinit var constraints: Constraints @Mock lateinit var constraints: Constraints
@Mock lateinit var iobCobCalculator: IobCobCalculator @Mock lateinit var sp: SP
private val injector = HasAndroidInjector { AndroidInjector { } } private val injector = HasAndroidInjector { AndroidInjector { } }
@ -55,7 +54,7 @@ class APSResultTest : TestBaseWithProfile() {
@Test @Test
fun changeRequestedTest() { fun changeRequestedTest() {
val apsResult = APSResultObject { AndroidInjector { } } val apsResult = info.nightscout.plugins.aps.APSResultObject { AndroidInjector { } }
.also { .also {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
it.constraintChecker = constraints it.constraintChecker = constraints
@ -76,21 +75,21 @@ class APSResultTest : TestBaseWithProfile() {
closedLoopEnabled.set(aapsLogger, true) closedLoopEnabled.set(aapsLogger, true)
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null) `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(false) apsResult.tempBasalRequested(false)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
apsResult.tempBasalRequested(true).percent(200).duration(30) apsResult.tempBasalRequested(true).percent(200).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// open loop // open loop
closedLoopEnabled.set(aapsLogger, false) closedLoopEnabled.set(aapsLogger, false)
// no change requested // no change requested
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null) `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(false) apsResult.tempBasalRequested(false)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request 100% when no temp is running // request 100% when no temp is running
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null) `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(true).percent(100).duration(30) apsResult.tempBasalRequested(true).percent(100).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request equal temp // request equal temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -103,7 +102,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(70).duration(30) apsResult.tempBasalRequested(true).percent(70).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request zero temp // request zero temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -116,7 +115,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(0).duration(30) apsResult.tempBasalRequested(true).percent(0).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// request high temp // request high temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -129,7 +128,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(200).duration(30) apsResult.tempBasalRequested(true).percent(200).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// request slightly different temp // request slightly different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -142,7 +141,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(80).duration(30) apsResult.tempBasalRequested(true).percent(80).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request different temp // request different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -155,7 +154,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(120).duration(30) apsResult.tempBasalRequested(true).percent(120).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// it should work with absolute temps too // it should work with absolute temps too
// request different temp // request different temp
@ -169,7 +168,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(100).duration(30) apsResult.tempBasalRequested(true).percent(100).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal( TemporaryBasal(
timestamp = 0, timestamp = 0,
@ -180,7 +179,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).percent(50).duration(30) apsResult.tempBasalRequested(true).percent(50).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// **** ABSOLUTE pump **** // **** ABSOLUTE pump ****
testPumpPlugin.pumpDescription.fillFor(PumpType.MEDTRONIC_515_715) // U/h based testPumpPlugin.pumpDescription.fillFor(PumpType.MEDTRONIC_515_715) // U/h based
@ -191,7 +190,7 @@ class APSResultTest : TestBaseWithProfile() {
// request 100% when no temp is running // request 100% when no temp is running
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null) `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(true).rate(1.0).duration(30) apsResult.tempBasalRequested(true).rate(1.0).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request equal temp // request equal temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -204,7 +203,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(2.0).duration(30) apsResult.tempBasalRequested(true).rate(2.0).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal( TemporaryBasal(
timestamp = 0, timestamp = 0,
@ -215,7 +214,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(2.0).duration(30) apsResult.tempBasalRequested(true).rate(2.0).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request zero temp // request zero temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -228,7 +227,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(0.0).duration(30) apsResult.tempBasalRequested(true).rate(0.0).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// request high temp // request high temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -241,7 +240,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(35.0).duration(30) apsResult.tempBasalRequested(true).rate(35.0).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// request slightly different temp // request slightly different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -254,7 +253,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(1.2).duration(30) apsResult.tempBasalRequested(true).rate(1.2).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
// request different temp // request different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
@ -267,7 +266,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(1.5).duration(30) apsResult.tempBasalRequested(true).rate(1.5).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
// it should work with percent temps too // it should work with percent temps too
// request different temp // request different temp
@ -281,7 +280,7 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(1.1).duration(30) apsResult.tempBasalRequested(true).rate(1.1).duration(30)
Assert.assertEquals(false, apsResult.isChangeRequested) Assertions.assertEquals(false, apsResult.isChangeRequested)
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn( `when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal( TemporaryBasal(
timestamp = 0, timestamp = 0,
@ -292,11 +291,11 @@ class APSResultTest : TestBaseWithProfile() {
) )
) )
apsResult.tempBasalRequested(true).rate(0.5).duration(30) apsResult.tempBasalRequested(true).rate(0.5).duration(30)
Assert.assertEquals(true, apsResult.isChangeRequested) Assertions.assertEquals(true, apsResult.isChangeRequested)
} }
@Test fun cloneTest() { @Test fun cloneTest() {
val apsResult = APSResultObject { AndroidInjector { } } val apsResult = info.nightscout.plugins.aps.APSResultObject { AndroidInjector { } }
.also { .also {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
it.constraintChecker = constraints it.constraintChecker = constraints
@ -308,12 +307,12 @@ class APSResultTest : TestBaseWithProfile() {
} }
apsResult.rate(10.0) apsResult.rate(10.0)
val apsResult2 = apsResult.newAndClone(injector) val apsResult2 = apsResult.newAndClone(injector)
Assert.assertEquals(apsResult.rate, apsResult2.rate, 0.0) Assertions.assertEquals(apsResult.rate, apsResult2.rate, 0.0)
} }
@Test fun jsonTest() { @Test fun jsonTest() {
closedLoopEnabled.set(aapsLogger, true) closedLoopEnabled.set(aapsLogger, true)
val apsResult = APSResultObject { AndroidInjector { } } val apsResult = info.nightscout.plugins.aps.APSResultObject { AndroidInjector { } }
.also { .also {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
it.constraintChecker = constraints it.constraintChecker = constraints
@ -324,9 +323,9 @@ class APSResultTest : TestBaseWithProfile() {
it.rh = rh it.rh = rh
} }
apsResult.rate(20.0).tempBasalRequested(true) apsResult.rate(20.0).tempBasalRequested(true)
Assert.assertEquals(20.0, safeGetDouble(apsResult.json(), "rate"), 0.0) Assertions.assertEquals(20.0, safeGetDouble(apsResult.json(), "rate"), 0.0)
apsResult.rate(20.0).tempBasalRequested(false) apsResult.rate(20.0).tempBasalRequested(false)
Assert.assertEquals(false, apsResult.json()?.has("rate")) Assertions.assertEquals(false, apsResult.json()?.has("rate"))
} }
@BeforeEach @BeforeEach

View file

@ -28,6 +28,7 @@ dependencies {
implementation project(':core:interfaces') implementation project(':core:interfaces')
testImplementation project(':implementation') testImplementation project(':implementation')
testImplementation project(':plugins:main')
api "androidx.constraintlayout:constraintlayout:$constraintlayout_version" api "androidx.constraintlayout:constraintlayout:$constraintlayout_version"
api "com.google.android.gms:play-services-location:$play_services_location_version" api "com.google.android.gms:play-services-location:$play_services_location_version"

View file

@ -10,6 +10,7 @@ import info.nightscout.database.entities.DeviceStatus
import info.nightscout.database.entities.OfflineEvent import info.nightscout.database.entities.OfflineEvent
import info.nightscout.interfaces.ConfigBuilder import info.nightscout.interfaces.ConfigBuilder
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.configBuilder.RunningConfiguration import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
@ -42,7 +43,8 @@ ActionsTestBase : TestBaseWithProfile() {
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rh: ResourceHelper, rh: ResourceHelper,
injector: HasAndroidInjector, injector: HasAndroidInjector,
pluginDescription: PluginDescription pluginDescription: PluginDescription,
private val apsResult: APSResult
) : PluginBase( ) : PluginBase(
pluginDescription, aapsLogger, rh, injector pluginDescription, aapsLogger, rh, injector
), Loop { ), Loop {
@ -75,6 +77,9 @@ ActionsTestBase : TestBaseWithProfile() {
runningConfiguration: RunningConfiguration, runningConfiguration: RunningConfiguration,
version: String version: String
): DeviceStatus? = null ): DeviceStatus? = null
override fun provideEmptyAPSResultObject(): APSResult = apsResult
override fun setPluginEnabled(type: PluginType, newState: Boolean) {} override fun setPluginEnabled(type: PluginType, newState: Boolean) {}
} }
@ -87,6 +92,7 @@ ActionsTestBase : TestBaseWithProfile() {
@Mock lateinit var loopPlugin: TestLoopPlugin @Mock lateinit var loopPlugin: TestLoopPlugin
@Mock lateinit var uel: UserEntryLogger @Mock lateinit var uel: UserEntryLogger
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var apsResult: APSResult
private val pluginDescription = PluginDescription() private val pluginDescription = PluginDescription()
lateinit var testPumpPlugin: TestPumpPlugin lateinit var testPumpPlugin: TestPumpPlugin

View file

@ -3,9 +3,9 @@ package info.nightscout.automation.triggers
import com.google.common.base.Optional import com.google.common.base.Optional
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.automation.elements.Comparator import info.nightscout.automation.elements.Comparator
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataObject
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
@ -22,53 +22,53 @@ class TriggerAutosensValueTest : TriggerTestBase() {
var t = TriggerAutosensValue(injector) var t = TriggerAutosensValue(injector)
t.autosens.value = 110.0 t.autosens.value = 110.0
t.comparator.value = Comparator.Compare.IS_EQUAL t.comparator.value = Comparator.Compare.IS_EQUAL
Assert.assertEquals(110.0, t.autosens.value, 0.01) Assertions.assertEquals(110.0, t.autosens.value, 0.01)
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value) Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assert.assertFalse(t.shouldRun()) Assertions.assertFalse(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 100.0 t.autosens.value = 100.0
t.comparator.value = Comparator.Compare.IS_EQUAL t.comparator.value = Comparator.Compare.IS_EQUAL
Assert.assertEquals(100.0, t.autosens.value, 0.01) Assertions.assertEquals(100.0, t.autosens.value, 0.01)
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 50.0 t.autosens.value = 50.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 310.0 t.autosens.value = 310.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 420.0 t.autosens.value = 420.0
t.comparator.value = Comparator.Compare.IS_EQUAL t.comparator.value = Comparator.Compare.IS_EQUAL
Assert.assertFalse(t.shouldRun()) Assertions.assertFalse(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 390.0 t.autosens.value = 390.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 390.0 t.autosens.value = 390.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
Assert.assertFalse(t.shouldRun()) Assertions.assertFalse(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 20.0 t.autosens.value = 20.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 390.0 t.autosens.value = 390.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensDataObject(injector)) `when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensDataObject(injector))
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.autosens.value = 80.0 t.autosens.value = 80.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
Assert.assertFalse(t.shouldRun()) Assertions.assertFalse(t.shouldRun())
// Test autosensData == null and Comparator == IS_NOT_AVAILABLE // Test autosensData == null and Comparator == IS_NOT_AVAILABLE
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null) `when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
t = TriggerAutosensValue(injector) t = TriggerAutosensValue(injector)
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
Assert.assertTrue(t.shouldRun()) Assertions.assertTrue(t.shouldRun())
} }
@Test @Test
@ -77,8 +77,8 @@ class TriggerAutosensValueTest : TriggerTestBase() {
t.autosens.value = 213.0 t.autosens.value = 213.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
val t1 = t.duplicate() as TriggerAutosensValue val t1 = t.duplicate() as TriggerAutosensValue
Assert.assertEquals(213.0, t1.autosens.value, 0.01) Assertions.assertEquals(213.0, t1.autosens.value, 0.01)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value) Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
} }
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}" private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
@ -88,7 +88,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
val t = TriggerAutosensValue(injector) val t = TriggerAutosensValue(injector)
t.autosens.value = 410.0 t.autosens.value = 410.0
t.comparator.value = Comparator.Compare.IS_EQUAL t.comparator.value = Comparator.Compare.IS_EQUAL
Assert.assertEquals(asJson, t.toJSON()) Assertions.assertEquals(asJson, t.toJSON())
} }
@Test @Test
@ -97,12 +97,12 @@ class TriggerAutosensValueTest : TriggerTestBase() {
t.autosens.value = 410.0 t.autosens.value = 410.0
t.comparator.value = Comparator.Compare.IS_EQUAL t.comparator.value = Comparator.Compare.IS_EQUAL
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value) Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(410.0, t2.autosens.value, 0.01) Assertions.assertEquals(410.0, t2.autosens.value, 0.01)
} }
@Test fun iconTest() { @Test fun iconTest() {
Assert.assertEquals(Optional.of(R.drawable.ic_as), TriggerAutosensValue(injector).icon()) Assertions.assertEquals(Optional.of(R.drawable.ic_as), TriggerAutosensValue(injector).icon())
} }
@BeforeEach @BeforeEach

View file

@ -9,6 +9,7 @@ import info.nightscout.plugins.general.persistentNotification.DummyService
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin
import info.nightscout.plugins.general.wear.WearFragment import info.nightscout.plugins.general.wear.WearFragment
import info.nightscout.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataObject
@Module( @Module(
includes = [ includes = [
@ -32,6 +33,8 @@ abstract class PluginsModule {
@ContributesAndroidInjector abstract fun contributesWearFragment(): WearFragment @ContributesAndroidInjector abstract fun contributesWearFragment(): WearFragment
@ContributesAndroidInjector abstract fun contributesDummyService(): DummyService @ContributesAndroidInjector abstract fun contributesDummyService(): DummyService
@ContributesAndroidInjector abstract fun autosensDataObjectInjector(): AutosensDataObject
@Module @Module
interface Bindings { interface Bindings {

View file

@ -38,6 +38,7 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.DecimalFormatter
import info.nightscout.interfaces.utils.MidnightTime import info.nightscout.interfaces.utils.MidnightTime
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataObject
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataStoreObject import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataStoreObject
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
@ -599,6 +600,8 @@ class IobCobCalculatorPlugin @Inject constructor(
override fun calculateIobFromTempBasalsIncludingConvertedExtended(): IobTotal = override fun calculateIobFromTempBasalsIncludingConvertedExtended(): IobTotal =
calculateIobToTimeFromTempBasalsIncludingConvertedExtended(dateUtil.now()) calculateIobToTimeFromTempBasalsIncludingConvertedExtended(dateUtil.now())
override fun provideEmptyAutosensDataObject(): AutosensData = AutosensDataObject(injector)
override fun calculateIobToTimeFromTempBasalsIncludingConvertedExtended(toTime: Long): IobTotal { override fun calculateIobToTimeFromTempBasalsIncludingConvertedExtended(toTime: Long): IobTotal {
val total = IobTotal(toTime) val total = IobTotal(toTime)
val now = dateUtil.now() val now = dateUtil.now()

View file

@ -1,4 +1,4 @@
package info.nightscout.core.iob.iobCobCalculator.data package info.nightscout.plugins.iob.iobCobCalculator.data
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
@ -22,18 +22,22 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
init {
injector.androidInjector().inject(this)
}
override var time = 0L override var time = 0L
override var bg = 0.0 // mgdl override var bg = 0.0 // mgdl
override var pastSensitivity = "" override var pastSensitivity = ""
override var deviation = 0.0 override var deviation = 0.0
override var validDeviation = false override var validDeviation = false
var activeCarbsList: MutableList<AutosensData.CarbsInPast> = ArrayList() override var activeCarbsList: MutableList<AutosensData.CarbsInPast> = ArrayList()
var absorbed = 0.0 override var absorbed = 0.0
override var carbsFromBolus = 0.0 override var carbsFromBolus = 0.0
override var cob = 0.0 override var cob = 0.0
var bgi = 0.0 override var bgi = 0.0
var delta = 0.0 override var delta = 0.0
var avgDelta = 0.0 override var avgDelta = 0.0
override var avgDeviation = 0.0 override var avgDeviation = 0.0
override var autosensResult = AutosensResult() override var autosensResult = AutosensResult()
override var slopeFromMaxDeviation = 0.0 override var slopeFromMaxDeviation = 0.0
@ -86,7 +90,7 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
} }
// remove carbs older than timeframe // remove carbs older than timeframe
fun removeOldCarbs(toTime: Long, isAAPSOrWeighted: Boolean) { override fun removeOldCarbs(toTime: Long, isAAPSOrWeighted: Boolean) {
val maxAbsorptionHours: Double = val maxAbsorptionHours: Double =
if (isAAPSOrWeighted) sp.getDouble(info.nightscout.core.utils.R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME) if (isAAPSOrWeighted) sp.getDouble(info.nightscout.core.utils.R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME)
else sp.getDouble(info.nightscout.core.utils.R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME) else sp.getDouble(info.nightscout.core.utils.R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME)
@ -102,7 +106,7 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
} }
} }
fun deductAbsorbedCarbs() { override fun deductAbsorbedCarbs() {
var ac = absorbed var ac = absorbed
var i = 0 var i = 0
while (i < activeCarbsList.size && ac > 0) { while (i < activeCarbsList.size && ac > 0) {
@ -115,7 +119,4 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
i++ i++
} }
} }
init {
injector.androidInjector().inject(this)
}
} }

View file

@ -1,8 +1,10 @@
package info.nightscout.plugins.sync.nsclient.data package info.nightscout.plugins.sync.nsclient.data
import android.text.Spanned import android.text.Spanned
import dagger.Lazy
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.aps.APSResultObject import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.nsclient.NSSettingsStatus import info.nightscout.interfaces.nsclient.NSSettingsStatus
import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData
import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.interfaces.utils.HtmlHelper
@ -21,7 +23,8 @@ import javax.inject.Singleton
class ProcessedDeviceStatusDataImpl @Inject constructor( class ProcessedDeviceStatusDataImpl @Inject constructor(
private val rh: ResourceHelper, private val rh: ResourceHelper,
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val sp: SP private val sp: SP,
private val loop: Lazy<Loop>
) : ProcessedDeviceStatusData { ) : ProcessedDeviceStatusData {
override var pumpData: ProcessedDeviceStatusData.PumpData? = null override var pumpData: ProcessedDeviceStatusData.PumpData? = null
@ -112,11 +115,10 @@ class ProcessedDeviceStatusDataImpl @Inject constructor(
override val openApsTimestamp: Long override val openApsTimestamp: Long
get() = if (openAPSData.clockSuggested != 0L) openAPSData.clockSuggested else -1 get() = if (openAPSData.clockSuggested != 0L) openAPSData.clockSuggested else -1
override fun getAPSResult(injector: HasAndroidInjector): APSResultObject { override fun getAPSResult(injector: HasAndroidInjector): APSResult =
val result = APSResultObject(injector) loop.get().provideEmptyAPSResultObject().also {
result.json = openAPSData.suggested it.json = openAPSData.suggested
result.date = openAPSData.clockSuggested it.date = openAPSData.clockSuggested
return result
} }
override val uploaderStatus: String override val uploaderStatus: String
get() { get() {

View file

@ -1,7 +1,7 @@
package info.nightscout.ui.activities package info.nightscout.ui.activities
import android.os.Bundle import android.os.Bundle
import info.nightscout.core.services.AlarmSoundService import info.nightscout.ui.services.AlarmSoundService
import info.nightscout.core.ui.activities.DialogAppCompatActivity import info.nightscout.core.ui.activities.DialogAppCompatActivity
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction

View file

@ -32,6 +32,7 @@ import info.nightscout.ui.dialogs.TempTargetDialog
import info.nightscout.ui.dialogs.TreatmentDialog import info.nightscout.ui.dialogs.TreatmentDialog
import info.nightscout.ui.dialogs.WizardDialog import info.nightscout.ui.dialogs.WizardDialog
import info.nightscout.ui.dialogs.WizardInfoDialog import info.nightscout.ui.dialogs.WizardInfoDialog
import info.nightscout.ui.services.AlarmSoundService
import info.nightscout.ui.widget.Widget import info.nightscout.ui.widget.Widget
import info.nightscout.ui.widget.WidgetConfigureActivity import info.nightscout.ui.widget.WidgetConfigureActivity
@ -39,6 +40,8 @@ import info.nightscout.ui.widget.WidgetConfigureActivity
@Suppress("unused") @Suppress("unused")
abstract class UiModule { abstract class UiModule {
@ContributesAndroidInjector abstract fun contributesAlarmSoundService(): AlarmSoundService
@ContributesAndroidInjector abstract fun contributesWidget(): Widget @ContributesAndroidInjector abstract fun contributesWidget(): Widget
@ContributesAndroidInjector abstract fun contributesWidgetConfigureActivity(): WidgetConfigureActivity @ContributesAndroidInjector abstract fun contributesWidgetConfigureActivity(): WidgetConfigureActivity

View file

@ -1,4 +1,4 @@
package info.nightscout.core.services package info.nightscout.ui.services
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent

View file

@ -1,4 +1,4 @@
package info.nightscout.core.services package info.nightscout.ui.services
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context

View file

@ -28,7 +28,7 @@ import java.util.HashMap;
@SuppressWarnings({"unused", "rawtypes", "SuspiciousMethodCalls", "unchecked"}) @SuppressWarnings({"unused", "rawtypes", "SuspiciousMethodCalls", "unchecked"})
public final class BundleMock { public final class BundleMock {
/*
public static Bundle mock() { public static Bundle mock() {
return mock(new HashMap<>()); return mock(new HashMap<>());
} }
@ -180,4 +180,5 @@ public final class BundleMock {
return bundle; return bundle;
} }
*/
} }

View file

@ -17,12 +17,12 @@ import info.nightscout.core.graph.data.Scale
import info.nightscout.core.graph.data.ScaledDataPoint import info.nightscout.core.graph.data.ScaledDataPoint
import info.nightscout.core.iob.combine import info.nightscout.core.iob.combine
import info.nightscout.core.iob.copy import info.nightscout.core.iob.copy
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject
import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.utils.receivers.DataWorkerStorage
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.core.workflow.CalculationWorkflow
import info.nightscout.database.ValueWrapper import info.nightscout.database.ValueWrapper
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.aps.AutosensData
import info.nightscout.interfaces.aps.AutosensResult import info.nightscout.interfaces.aps.AutosensResult
import info.nightscout.interfaces.aps.SMBDefaults import info.nightscout.interfaces.aps.SMBDefaults
import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.iob.IobCobCalculator
@ -94,7 +94,7 @@ class PrepareIobAutosensGraphDataWorker(
} }
class AutosensDataPoint( class AutosensDataPoint(
private val ad: AutosensDataObject, private val ad: AutosensData,
private val scale: Scale, private val scale: Scale,
private val chartTime: Long, private val chartTime: Long,
private val rh: ResourceHelper private val rh: ResourceHelper
@ -163,7 +163,7 @@ class PrepareIobAutosensGraphDataWorker(
val iob = data.iobCobCalculator.calculateFromTreatmentsAndTemps(time, profile) val iob = data.iobCobCalculator.calculateFromTreatmentsAndTemps(time, profile)
val baseBasalIob = data.iobCobCalculator.calculateAbsoluteIobFromBaseBasals(time) val baseBasalIob = data.iobCobCalculator.calculateAbsoluteIobFromBaseBasals(time)
val absIob = IobTotal.combine(iob, baseBasalIob) val absIob = IobTotal.combine(iob, baseBasalIob)
val autosensData = adsData.getAutosensDataAtTime(time) as AutosensDataObject? val autosensData = adsData.getAutosensDataAtTime(time)
if (abs(lastIob - iob.iob) > 0.02) { if (abs(lastIob - iob.iob) > 0.02) {
if (abs(lastIob - iob.iob) > 0.2) iobArray.add(ScaledDataPoint(time, lastIob, data.overviewData.iobScale)) if (abs(lastIob - iob.iob) > 0.2) iobArray.add(ScaledDataPoint(time, lastIob, data.overviewData.iobScale))
iobArray.add(ScaledDataPoint(time, iob.iob, data.overviewData.iobScale)) iobArray.add(ScaledDataPoint(time, iob.iob, data.overviewData.iobScale))

View file

@ -7,7 +7,6 @@ import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.events.EventIobCalculationProgress
import info.nightscout.core.extensions.target import info.nightscout.core.extensions.target
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.utils.receivers.DataWorkerStorage
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
@ -115,7 +114,7 @@ class IobCobOref1Worker(
} }
aapsLogger.debug(LTag.AUTOSENS, "Processing calculation thread: ${data.reason} ($i/${bucketedData.size})") aapsLogger.debug(LTag.AUTOSENS, "Processing calculation thread: ${data.reason} ($i/${bucketedData.size})")
val sens = profile.getIsfMgdl(bgTime) val sens = profile.getIsfMgdl(bgTime)
val autosensData = AutosensDataObject(data.injector) val autosensData = data.iobCobCalculator.provideEmptyAutosensDataObject()
autosensData.time = bgTime autosensData.time = bgTime
if (previous != null) autosensData.activeCarbsList = previous.cloneCarbsList() else autosensData.activeCarbsList = ArrayList() if (previous != null) autosensData.activeCarbsList = previous.cloneCarbsList() else autosensData.activeCarbsList = ArrayList()

View file

@ -6,7 +6,6 @@ import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.events.EventIobCalculationProgress
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.utils.receivers.DataWorkerStorage
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
@ -56,7 +55,7 @@ class IobCobOrefWorker @Inject internal constructor(
class IobCobOrefWorkerData( class IobCobOrefWorkerData(
val injector: HasAndroidInjector, val injector: HasAndroidInjector,
val iobCobCalculatorPlugin: IobCobCalculator, // cannot be injected : HistoryBrowser uses different instance val iobCobCalculator: IobCobCalculator, // cannot be injected : HistoryBrowser uses different instance
val reason: String, val reason: String,
val end: Long, val end: Long,
val limitDataToOldestAvailable: Boolean, val limitDataToOldestAvailable: Boolean,
@ -75,9 +74,9 @@ class IobCobOrefWorker @Inject internal constructor(
return Result.success(workDataOf("Error" to "app still initializing")) return Result.success(workDataOf("Error" to "app still initializing"))
} }
//log.debug("Locking calculateSensitivityData"); //log.debug("Locking calculateSensitivityData");
val oldestTimeWithData = data.iobCobCalculatorPlugin.calculateDetectionStart(data.end, data.limitDataToOldestAvailable) val oldestTimeWithData = data.iobCobCalculator.calculateDetectionStart(data.end, data.limitDataToOldestAvailable)
// work on local copy and set back when finished // work on local copy and set back when finished
val ads = data.iobCobCalculatorPlugin.ads.clone() val ads = data.iobCobCalculator.ads.clone()
val bucketedData = ads.bucketedData val bucketedData = ads.bucketedData
val autosensDataTable = ads.autosensDataTable val autosensDataTable = ads.autosensDataTable
if (bucketedData == null || bucketedData.size < 3) { if (bucketedData == null || bucketedData.size < 3) {
@ -110,7 +109,7 @@ class IobCobOrefWorker @Inject internal constructor(
} }
aapsLogger.debug(LTag.AUTOSENS, "Processing calculation thread: ${data.reason} ($i/${bucketedData.size})") aapsLogger.debug(LTag.AUTOSENS, "Processing calculation thread: ${data.reason} ($i/${bucketedData.size})")
val sens = profile.getIsfMgdl(bgTime) val sens = profile.getIsfMgdl(bgTime)
val autosensData = AutosensDataObject(data.injector) val autosensData = data.iobCobCalculator.provideEmptyAutosensDataObject()
autosensData.time = bgTime autosensData.time = bgTime
if (previous != null) autosensData.activeCarbsList = previous.cloneCarbsList() else autosensData.activeCarbsList = ArrayList() if (previous != null) autosensData.activeCarbsList = previous.cloneCarbsList() else autosensData.activeCarbsList = ArrayList()
@ -125,7 +124,7 @@ class IobCobOrefWorker @Inject internal constructor(
autosensData.bg = bg autosensData.bg = bg
delta = bg - bucketedData[i + 1].value delta = bg - bucketedData[i + 1].value
avgDelta = (bg - bucketedData[i + 3].value) / 3 avgDelta = (bg - bucketedData[i + 3].value) / 3
val iob = data.iobCobCalculatorPlugin.calculateFromTreatmentsAndTemps(bgTime, profile) val iob = data.iobCobCalculator.calculateFromTreatmentsAndTemps(bgTime, profile)
val bgi = -iob.activity * sens * 5 val bgi = -iob.activity * sens * 5
val deviation = delta - bgi val deviation = delta - bgi
val avgDeviation = ((avgDelta - bgi) * 1000).roundToLong() / 1000.0 val avgDeviation = ((avgDelta - bgi) * 1000).roundToLong() / 1000.0
@ -260,7 +259,7 @@ class IobCobOrefWorker @Inject internal constructor(
autosensData.autosensResult = sensitivity autosensData.autosensResult = sensitivity
aapsLogger.debug(LTag.AUTOSENS, autosensData.toString()) aapsLogger.debug(LTag.AUTOSENS, autosensData.toString())
} }
data.iobCobCalculatorPlugin.ads = ads data.iobCobCalculator.ads = ads
Thread { Thread {
SystemClock.sleep(1000) SystemClock.sleep(1000)
rxBus.send(EventAutosensCalculationFinished(data.cause)) rxBus.send(EventAutosensCalculationFinished(data.cause))