move out of :core:main
This commit is contained in:
parent
d34bcbf74f
commit
8791e93cc9
35 changed files with 146 additions and 125 deletions
|
@ -132,7 +132,7 @@
|
|||
</provider>
|
||||
|
||||
<service
|
||||
android:name="info.nightscout.core.services.AlarmSoundService"
|
||||
android:name="info.nightscout.ui.services.AlarmSoundService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
<uses-library
|
||||
|
|
|
@ -14,8 +14,8 @@ import info.nightscout.androidaps.activities.MyPreferenceFragment
|
|||
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||
import info.nightscout.configuration.activities.SingleFragmentActivity
|
||||
import info.nightscout.core.events.EventNewNotification
|
||||
import info.nightscout.core.services.AlarmSoundService
|
||||
import info.nightscout.core.services.AlarmSoundServiceHelper
|
||||
import info.nightscout.ui.services.AlarmSoundService
|
||||
import info.nightscout.ui.services.AlarmSoundServiceHelper
|
||||
import info.nightscout.core.ui.toast.ToastUtils
|
||||
import info.nightscout.interfaces.notifications.Notification
|
||||
import info.nightscout.interfaces.nsclient.NSAlarm
|
||||
|
|
|
@ -8,6 +8,7 @@ import info.nightscout.interfaces.iob.IobTotal
|
|||
import org.json.JSONObject
|
||||
|
||||
interface APSResult {
|
||||
var date: Long
|
||||
var json: JSONObject?
|
||||
var reason: String
|
||||
var rate: Double
|
||||
|
|
|
@ -18,8 +18,13 @@ interface AutosensData {
|
|||
var pastSensitivity: String
|
||||
var deviation: Double
|
||||
var validDeviation: Boolean
|
||||
var activeCarbsList: MutableList<CarbsInPast>
|
||||
var absorbed: Double
|
||||
var carbsFromBolus: Double
|
||||
var cob: Double
|
||||
var bgi: Double
|
||||
var delta: Double
|
||||
var avgDelta: Double
|
||||
var slopeFromMaxDeviation: Double
|
||||
var slopeFromMinDeviation: Double
|
||||
var usedMinCarbsImpact: Double
|
||||
|
@ -37,4 +42,6 @@ interface AutosensData {
|
|||
var autosensResult: AutosensResult
|
||||
|
||||
fun cloneCarbsList(): MutableList<CarbsInPast>
|
||||
fun deductAbsorbedCarbs()
|
||||
fun removeOldCarbs(toTime: Long, isAAPSOrWeighted: Boolean)
|
||||
}
|
|
@ -57,4 +57,6 @@ interface Loop {
|
|||
runningConfiguration: RunningConfiguration,
|
||||
version: String
|
||||
): DeviceStatus?
|
||||
|
||||
fun provideEmptyAPSResultObject(): APSResult
|
||||
}
|
|
@ -104,4 +104,6 @@ interface IobCobCalculator {
|
|||
* @return IobTotal
|
||||
*/
|
||||
fun calculateIobFromTempBasalsIncludingConvertedExtended(): IobTotal
|
||||
|
||||
fun provideEmptyAutosensDataObject(): AutosensData
|
||||
}
|
|
@ -2,8 +2,6 @@ package info.nightscout.core.di
|
|||
|
||||
import dagger.Module
|
||||
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.QuickWizardEntry
|
||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||
|
@ -13,8 +11,6 @@ import info.nightscout.interfaces.pump.PumpEnactResult
|
|||
abstract class CoreDataClassesModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun pumpEnactResultInjector(): PumpEnactResult
|
||||
@ContributesAndroidInjector abstract fun apsResultInjector(): APSResultObject
|
||||
@ContributesAndroidInjector abstract fun autosensDataInjector(): AutosensDataObject
|
||||
@ContributesAndroidInjector abstract fun bolusWizardInjector(): BolusWizard
|
||||
@ContributesAndroidInjector abstract fun quickWizardEntryInjector(): QuickWizardEntry
|
||||
}
|
||||
|
|
|
@ -5,14 +5,11 @@ import android.os.Build
|
|||
import android.telephony.SmsManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.core.services.AlarmSoundService
|
||||
|
||||
@Module(
|
||||
includes = [
|
||||
CoreDataClassesModule::class,
|
||||
PreferencesModule::class,
|
||||
ServicesModule::class
|
||||
PreferencesModule::class
|
||||
]
|
||||
)
|
||||
open class CoreModule {
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
package info.nightscout.core.profile
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
package info.nightscout.core.aps
|
||||
package info.nightscout.plugins.aps
|
||||
|
||||
import android.text.Spanned
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.extensions.convertedToAbsolute
|
||||
import info.nightscout.core.extensions.convertedToPercent
|
||||
import info.nightscout.core.ui.R
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.interfaces.aps.APSResult
|
||||
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.pump.defs.PumpDescription
|
||||
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.LTag
|
||||
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 dateUtil: DateUtil
|
||||
|
||||
var date: Long = 0
|
||||
override var date: Long = 0
|
||||
override var reason: String = ""
|
||||
override var rate = 0.0
|
||||
override var percent = 0
|
||||
|
@ -116,11 +117,11 @@ open class APSResultObject @Inject constructor(val injector: HasAndroidInjector)
|
|||
|
||||
// reason
|
||||
ret += "<b>" + rh.gs(info.nightscout.core.ui.R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">")
|
||||
return fromHtml(ret)
|
||||
return HtmlHelper.fromHtml(ret)
|
||||
}
|
||||
return if (isCarbsRequired) {
|
||||
fromHtml(carbsRequiredText)
|
||||
} else fromHtml(rh.gs(info.nightscout.core.ui.R.string.nochangerequested))
|
||||
HtmlHelper.fromHtml(carbsRequiredText)
|
||||
} else HtmlHelper.fromHtml(rh.gs(R.string.nochangerequested))
|
||||
}
|
||||
|
||||
override fun newAndClone(injector: HasAndroidInjector): APSResult {
|
|
@ -3,8 +3,10 @@ package info.nightscout.plugins.aps.di
|
|||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.interfaces.aps.APSResult
|
||||
import info.nightscout.interfaces.aps.Loop
|
||||
import info.nightscout.interfaces.autotune.Autotune
|
||||
import info.nightscout.plugins.aps.APSResultObject
|
||||
import info.nightscout.plugins.aps.OpenAPSFragment
|
||||
import info.nightscout.plugins.aps.loop.LoopPlugin
|
||||
import info.nightscout.plugins.general.autotune.AutotunePlugin
|
||||
|
@ -22,6 +24,7 @@ import info.nightscout.plugins.general.autotune.AutotunePlugin
|
|||
abstract class ApsModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSFragment(): OpenAPSFragment
|
||||
@ContributesAndroidInjector abstract fun apsResultInjector(): APSResultObject
|
||||
|
||||
@Module
|
||||
interface Bindings {
|
||||
|
|
|
@ -2,10 +2,12 @@ package info.nightscout.plugins.aps.di
|
|||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.plugins.aps.loop.CarbSuggestionReceiver
|
||||
import info.nightscout.plugins.aps.loop.LoopFragment
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
abstract class LoopModule {
|
||||
@ContributesAndroidInjector abstract fun contributesLoopFragment(): info.nightscout.plugins.aps.loop.LoopFragment
|
||||
@ContributesAndroidInjector abstract fun contributesCarbSuggestionReceiver(): info.nightscout.plugins.aps.loop.CarbSuggestionReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment
|
||||
@ContributesAndroidInjector abstract fun contributesCarbSuggestionReceiver(): CarbSuggestionReceiver
|
||||
}
|
|
@ -57,6 +57,7 @@ import info.nightscout.interfaces.queue.CommandQueue
|
|||
import info.nightscout.interfaces.receivers.ReceiverStatusStore
|
||||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
import info.nightscout.interfaces.utils.HardLimits
|
||||
import info.nightscout.plugins.aps.APSResultObject
|
||||
import info.nightscout.plugins.aps.R
|
||||
import info.nightscout.plugins.aps.loop.events.EventLoopSetLastRunGui
|
||||
import info.nightscout.plugins.aps.loop.extensions.json
|
||||
|
@ -782,6 +783,9 @@ class LoopPlugin @Inject constructor(
|
|||
configuration = runningConfiguration.configuration().toString()
|
||||
)
|
||||
}
|
||||
|
||||
override fun provideEmptyAPSResultObject(): APSResult = APSResultObject(injector)
|
||||
|
||||
companion object {
|
||||
|
||||
private const val CHANNEL_ID = "AAPS-OpenLoop"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.plugins.aps.openAPSAMA
|
||||
|
||||
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.getPassedDurationToTimeInMinutes
|
||||
import info.nightscout.core.extensions.plannedRemainingMinutes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.plugins.aps.openAPSAMA
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.aps.APSResultObject
|
||||
import info.nightscout.plugins.aps.APSResultObject
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.plugins.aps.openAPSSMB
|
||||
|
||||
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.getPassedDurationToTimeInMinutes
|
||||
import info.nightscout.core.extensions.plannedRemainingMinutes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.plugins.aps.openAPSSMB
|
||||
|
||||
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.rx.logging.LTag
|
||||
import org.json.JSONException
|
||||
|
|
|
@ -38,6 +38,7 @@ open class TestBaseWithProfile : TestBase() {
|
|||
@Mock lateinit var context: Context
|
||||
|
||||
lateinit var dateUtil: DateUtil
|
||||
lateinit var testPumpPlugin: TestPumpPlugin
|
||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||
|
||||
val profileInjector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
@ -56,6 +57,8 @@ open class TestBaseWithProfile : TestBase() {
|
|||
dateUtil = Mockito.spy(DateUtil(context))
|
||||
`when`(dateUtil.now()).thenReturn(1656358822000)
|
||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
||||
testPumpPlugin = TestPumpPlugin(profileInjector)
|
||||
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
|
||||
effectiveProfileSwitch = EffectiveProfileSwitch(
|
||||
timestamp = dateUtil.now(),
|
||||
basalBlocks = validProfile.basalBlocks,
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package info.nightscout.androidaps.plugins.aps.loop
|
||||
package info.nightscout.plugins.aps.loop
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.core.aps.APSResultObject
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.interfaces.aps.APSResult
|
||||
import info.nightscout.interfaces.constraints.Constraint
|
||||
import info.nightscout.interfaces.constraints.Constraints
|
||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||
import info.nightscout.interfaces.pump.defs.PumpType
|
||||
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.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
|
@ -21,7 +20,7 @@ import org.mockito.Mockito.`when`
|
|||
class APSResultTest : TestBaseWithProfile() {
|
||||
|
||||
@Mock lateinit var constraints: Constraints
|
||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||
@Mock lateinit var sp: SP
|
||||
|
||||
private val injector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
||||
|
@ -55,7 +54,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
@Test
|
||||
fun changeRequestedTest() {
|
||||
|
||||
val apsResult = APSResultObject { AndroidInjector { } }
|
||||
val apsResult = info.nightscout.plugins.aps.APSResultObject { AndroidInjector { } }
|
||||
.also {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.constraintChecker = constraints
|
||||
|
@ -76,21 +75,21 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
closedLoopEnabled.set(aapsLogger, true)
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||
apsResult.tempBasalRequested(false)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// open loop
|
||||
closedLoopEnabled.set(aapsLogger, false)
|
||||
// no change requested
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||
apsResult.tempBasalRequested(false)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request 100% when no temp is running
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request equal temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -103,7 +102,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(70).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request zero temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -116,7 +115,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(0).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// request high temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -129,7 +128,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// request slightly different temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -142,7 +141,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(80).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request different temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -155,7 +154,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(120).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// it should work with absolute temps too
|
||||
// request different temp
|
||||
|
@ -169,7 +168,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
TemporaryBasal(
|
||||
timestamp = 0,
|
||||
|
@ -180,7 +179,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).percent(50).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// **** ABSOLUTE pump ****
|
||||
testPumpPlugin.pumpDescription.fillFor(PumpType.MEDTRONIC_515_715) // U/h based
|
||||
|
@ -191,7 +190,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
// request 100% when no temp is running
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||
apsResult.tempBasalRequested(true).rate(1.0).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request equal temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -204,7 +203,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
TemporaryBasal(
|
||||
timestamp = 0,
|
||||
|
@ -215,7 +214,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request zero temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -228,7 +227,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(0.0).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// request high temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -241,7 +240,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(35.0).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
|
||||
// request slightly different temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -254,7 +253,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(1.2).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
|
||||
// request different temp
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
|
@ -267,7 +266,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
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
|
||||
// request different temp
|
||||
|
@ -281,7 +280,7 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(1.1).duration(30)
|
||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||
TemporaryBasal(
|
||||
timestamp = 0,
|
||||
|
@ -292,11 +291,11 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
apsResult.tempBasalRequested(true).rate(0.5).duration(30)
|
||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
||||
}
|
||||
|
||||
@Test fun cloneTest() {
|
||||
val apsResult = APSResultObject { AndroidInjector { } }
|
||||
val apsResult = info.nightscout.plugins.aps.APSResultObject { AndroidInjector { } }
|
||||
.also {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.constraintChecker = constraints
|
||||
|
@ -308,12 +307,12 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
}
|
||||
apsResult.rate(10.0)
|
||||
val apsResult2 = apsResult.newAndClone(injector)
|
||||
Assert.assertEquals(apsResult.rate, apsResult2.rate, 0.0)
|
||||
Assertions.assertEquals(apsResult.rate, apsResult2.rate, 0.0)
|
||||
}
|
||||
|
||||
@Test fun jsonTest() {
|
||||
closedLoopEnabled.set(aapsLogger, true)
|
||||
val apsResult = APSResultObject { AndroidInjector { } }
|
||||
val apsResult = info.nightscout.plugins.aps.APSResultObject { AndroidInjector { } }
|
||||
.also {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.constraintChecker = constraints
|
||||
|
@ -324,9 +323,9 @@ class APSResultTest : TestBaseWithProfile() {
|
|||
it.rh = rh
|
||||
}
|
||||
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)
|
||||
Assert.assertEquals(false, apsResult.json()?.has("rate"))
|
||||
Assertions.assertEquals(false, apsResult.json()?.has("rate"))
|
||||
}
|
||||
|
||||
@BeforeEach
|
|
@ -28,6 +28,7 @@ dependencies {
|
|||
implementation project(':core:interfaces')
|
||||
|
||||
testImplementation project(':implementation')
|
||||
testImplementation project(':plugins:main')
|
||||
|
||||
api "androidx.constraintlayout:constraintlayout:$constraintlayout_version"
|
||||
api "com.google.android.gms:play-services-location:$play_services_location_version"
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.database.entities.DeviceStatus
|
|||
import info.nightscout.database.entities.OfflineEvent
|
||||
import info.nightscout.interfaces.ConfigBuilder
|
||||
import info.nightscout.interfaces.GlucoseUnit
|
||||
import info.nightscout.interfaces.aps.APSResult
|
||||
import info.nightscout.interfaces.aps.Loop
|
||||
import info.nightscout.interfaces.configBuilder.RunningConfiguration
|
||||
import info.nightscout.interfaces.constraints.Constraint
|
||||
|
@ -42,7 +43,8 @@ ActionsTestBase : TestBaseWithProfile() {
|
|||
aapsLogger: AAPSLogger,
|
||||
rh: ResourceHelper,
|
||||
injector: HasAndroidInjector,
|
||||
pluginDescription: PluginDescription
|
||||
pluginDescription: PluginDescription,
|
||||
private val apsResult: APSResult
|
||||
) : PluginBase(
|
||||
pluginDescription, aapsLogger, rh, injector
|
||||
), Loop {
|
||||
|
@ -75,6 +77,9 @@ ActionsTestBase : TestBaseWithProfile() {
|
|||
runningConfiguration: RunningConfiguration,
|
||||
version: String
|
||||
): DeviceStatus? = null
|
||||
|
||||
override fun provideEmptyAPSResultObject(): APSResult = apsResult
|
||||
|
||||
override fun setPluginEnabled(type: PluginType, newState: Boolean) {}
|
||||
}
|
||||
|
||||
|
@ -87,6 +92,7 @@ ActionsTestBase : TestBaseWithProfile() {
|
|||
@Mock lateinit var loopPlugin: TestLoopPlugin
|
||||
@Mock lateinit var uel: UserEntryLogger
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var apsResult: APSResult
|
||||
|
||||
private val pluginDescription = PluginDescription()
|
||||
lateinit var testPumpPlugin: TestPumpPlugin
|
||||
|
|
|
@ -3,9 +3,9 @@ package info.nightscout.automation.triggers
|
|||
import com.google.common.base.Optional
|
||||
import info.nightscout.automation.R
|
||||
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.junit.Assert
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
|
@ -22,53 +22,53 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
|||
var t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 110.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||
Assert.assertEquals(110.0, t.autosens.value, 0.01)
|
||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
Assertions.assertEquals(110.0, t.autosens.value, 0.01)
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 100.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||
Assert.assertEquals(100.0, t.autosens.value, 0.01)
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
Assertions.assertEquals(100.0, t.autosens.value, 0.01)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 50.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 310.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 420.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 390.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 390.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 20.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 390.0
|
||||
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))
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 80.0
|
||||
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
|
||||
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
|
||||
t = TriggerAutosensValue(injector)
|
||||
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,8 +77,8 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
|||
t.autosens.value = 213.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||
val t1 = t.duplicate() as TriggerAutosensValue
|
||||
Assert.assertEquals(213.0, t1.autosens.value, 0.01)
|
||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
Assertions.assertEquals(213.0, t1.autosens.value, 0.01)
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
|
||||
|
@ -88,7 +88,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
|||
val t = TriggerAutosensValue(injector)
|
||||
t.autosens.value = 410.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||
Assert.assertEquals(asJson, t.toJSON())
|
||||
Assertions.assertEquals(asJson, t.toJSON())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -97,12 +97,12 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
|||
t.autosens.value = 410.0
|
||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
|
||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
||||
Assert.assertEquals(410.0, t2.autosens.value, 0.01)
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
||||
Assertions.assertEquals(410.0, t2.autosens.value, 0.01)
|
||||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.plugins.general.persistentNotification.DummyService
|
|||
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||
import info.nightscout.plugins.general.wear.WearFragment
|
||||
import info.nightscout.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataObject
|
||||
|
||||
@Module(
|
||||
includes = [
|
||||
|
@ -32,6 +33,8 @@ abstract class PluginsModule {
|
|||
|
||||
@ContributesAndroidInjector abstract fun contributesWearFragment(): WearFragment
|
||||
@ContributesAndroidInjector abstract fun contributesDummyService(): DummyService
|
||||
@ContributesAndroidInjector abstract fun autosensDataObjectInjector(): AutosensDataObject
|
||||
|
||||
|
||||
@Module
|
||||
interface Bindings {
|
||||
|
|
|
@ -38,6 +38,7 @@ import info.nightscout.interfaces.profile.ProfileFunction
|
|||
import info.nightscout.interfaces.utils.DecimalFormatter
|
||||
import info.nightscout.interfaces.utils.MidnightTime
|
||||
import info.nightscout.plugins.R
|
||||
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataObject
|
||||
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataStoreObject
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
|
@ -599,6 +600,8 @@ class IobCobCalculatorPlugin @Inject constructor(
|
|||
override fun calculateIobFromTempBasalsIncludingConvertedExtended(): IobTotal =
|
||||
calculateIobToTimeFromTempBasalsIncludingConvertedExtended(dateUtil.now())
|
||||
|
||||
override fun provideEmptyAutosensDataObject(): AutosensData = AutosensDataObject(injector)
|
||||
|
||||
override fun calculateIobToTimeFromTempBasalsIncludingConvertedExtended(toTime: Long): IobTotal {
|
||||
val total = IobTotal(toTime)
|
||||
val now = dateUtil.now()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.core.iob.iobCobCalculator.data
|
||||
package info.nightscout.plugins.iob.iobCobCalculator.data
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.interfaces.Constants
|
||||
|
@ -22,18 +22,22 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
|
|||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
init {
|
||||
injector.androidInjector().inject(this)
|
||||
}
|
||||
|
||||
override var time = 0L
|
||||
override var bg = 0.0 // mgdl
|
||||
override var pastSensitivity = ""
|
||||
override var deviation = 0.0
|
||||
override var validDeviation = false
|
||||
var activeCarbsList: MutableList<AutosensData.CarbsInPast> = ArrayList()
|
||||
var absorbed = 0.0
|
||||
override var activeCarbsList: MutableList<AutosensData.CarbsInPast> = ArrayList()
|
||||
override var absorbed = 0.0
|
||||
override var carbsFromBolus = 0.0
|
||||
override var cob = 0.0
|
||||
var bgi = 0.0
|
||||
var delta = 0.0
|
||||
var avgDelta = 0.0
|
||||
override var bgi = 0.0
|
||||
override var delta = 0.0
|
||||
override var avgDelta = 0.0
|
||||
override var avgDeviation = 0.0
|
||||
override var autosensResult = AutosensResult()
|
||||
override var slopeFromMaxDeviation = 0.0
|
||||
|
@ -86,7 +90,7 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
|
|||
}
|
||||
|
||||
// remove carbs older than timeframe
|
||||
fun removeOldCarbs(toTime: Long, isAAPSOrWeighted: Boolean) {
|
||||
override fun removeOldCarbs(toTime: Long, isAAPSOrWeighted: Boolean) {
|
||||
val maxAbsorptionHours: Double =
|
||||
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)
|
||||
|
@ -102,7 +106,7 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
|
|||
}
|
||||
}
|
||||
|
||||
fun deductAbsorbedCarbs() {
|
||||
override fun deductAbsorbedCarbs() {
|
||||
var ac = absorbed
|
||||
var i = 0
|
||||
while (i < activeCarbsList.size && ac > 0) {
|
||||
|
@ -115,7 +119,4 @@ class AutosensDataObject(injector: HasAndroidInjector) : AutosensData {
|
|||
i++
|
||||
}
|
||||
}
|
||||
init {
|
||||
injector.androidInjector().inject(this)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package info.nightscout.plugins.sync.nsclient.data
|
||||
|
||||
import android.text.Spanned
|
||||
import dagger.Lazy
|
||||
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.ProcessedDeviceStatusData
|
||||
import info.nightscout.interfaces.utils.HtmlHelper
|
||||
|
@ -21,7 +23,8 @@ import javax.inject.Singleton
|
|||
class ProcessedDeviceStatusDataImpl @Inject constructor(
|
||||
private val rh: ResourceHelper,
|
||||
private val dateUtil: DateUtil,
|
||||
private val sp: SP
|
||||
private val sp: SP,
|
||||
private val loop: Lazy<Loop>
|
||||
) : ProcessedDeviceStatusData {
|
||||
|
||||
override var pumpData: ProcessedDeviceStatusData.PumpData? = null
|
||||
|
@ -112,11 +115,10 @@ class ProcessedDeviceStatusDataImpl @Inject constructor(
|
|||
override val openApsTimestamp: Long
|
||||
get() = if (openAPSData.clockSuggested != 0L) openAPSData.clockSuggested else -1
|
||||
|
||||
override fun getAPSResult(injector: HasAndroidInjector): APSResultObject {
|
||||
val result = APSResultObject(injector)
|
||||
result.json = openAPSData.suggested
|
||||
result.date = openAPSData.clockSuggested
|
||||
return result
|
||||
override fun getAPSResult(injector: HasAndroidInjector): APSResult =
|
||||
loop.get().provideEmptyAPSResultObject().also {
|
||||
it.json = openAPSData.suggested
|
||||
it.date = openAPSData.clockSuggested
|
||||
}
|
||||
override val uploaderStatus: String
|
||||
get() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.ui.activities
|
||||
|
||||
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.database.impl.AppRepository
|
||||
import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction
|
||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.ui.dialogs.TempTargetDialog
|
|||
import info.nightscout.ui.dialogs.TreatmentDialog
|
||||
import info.nightscout.ui.dialogs.WizardDialog
|
||||
import info.nightscout.ui.dialogs.WizardInfoDialog
|
||||
import info.nightscout.ui.services.AlarmSoundService
|
||||
import info.nightscout.ui.widget.Widget
|
||||
import info.nightscout.ui.widget.WidgetConfigureActivity
|
||||
|
||||
|
@ -39,6 +40,8 @@ import info.nightscout.ui.widget.WidgetConfigureActivity
|
|||
@Suppress("unused")
|
||||
abstract class UiModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesAlarmSoundService(): AlarmSoundService
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesWidget(): Widget
|
||||
@ContributesAndroidInjector abstract fun contributesWidgetConfigureActivity(): WidgetConfigureActivity
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.core.services
|
||||
package info.nightscout.ui.services
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.core.services
|
||||
package info.nightscout.ui.services
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
|
@ -28,7 +28,7 @@ import java.util.HashMap;
|
|||
|
||||
@SuppressWarnings({"unused", "rawtypes", "SuspiciousMethodCalls", "unchecked"})
|
||||
public final class BundleMock {
|
||||
|
||||
/*
|
||||
public static Bundle mock() {
|
||||
return mock(new HashMap<>());
|
||||
}
|
||||
|
@ -180,4 +180,5 @@ public final class BundleMock {
|
|||
|
||||
return bundle;
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -17,12 +17,12 @@ import info.nightscout.core.graph.data.Scale
|
|||
import info.nightscout.core.graph.data.ScaledDataPoint
|
||||
import info.nightscout.core.iob.combine
|
||||
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.worker.LoggingWorker
|
||||
import info.nightscout.core.workflow.CalculationWorkflow
|
||||
import info.nightscout.database.ValueWrapper
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.interfaces.aps.AutosensData
|
||||
import info.nightscout.interfaces.aps.AutosensResult
|
||||
import info.nightscout.interfaces.aps.SMBDefaults
|
||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||
|
@ -94,7 +94,7 @@ class PrepareIobAutosensGraphDataWorker(
|
|||
}
|
||||
|
||||
class AutosensDataPoint(
|
||||
private val ad: AutosensDataObject,
|
||||
private val ad: AutosensData,
|
||||
private val scale: Scale,
|
||||
private val chartTime: Long,
|
||||
private val rh: ResourceHelper
|
||||
|
@ -163,7 +163,7 @@ class PrepareIobAutosensGraphDataWorker(
|
|||
val iob = data.iobCobCalculator.calculateFromTreatmentsAndTemps(time, profile)
|
||||
val baseBasalIob = data.iobCobCalculator.calculateAbsoluteIobFromBaseBasals(time)
|
||||
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.2) iobArray.add(ScaledDataPoint(time, lastIob, data.overviewData.iobScale))
|
||||
iobArray.add(ScaledDataPoint(time, iob.iob, data.overviewData.iobScale))
|
||||
|
|
|
@ -7,7 +7,6 @@ import androidx.work.workDataOf
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.events.EventIobCalculationProgress
|
||||
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.receivers.DataWorkerStorage
|
||||
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})")
|
||||
val sens = profile.getIsfMgdl(bgTime)
|
||||
val autosensData = AutosensDataObject(data.injector)
|
||||
val autosensData = data.iobCobCalculator.provideEmptyAutosensDataObject()
|
||||
autosensData.time = bgTime
|
||||
if (previous != null) autosensData.activeCarbsList = previous.cloneCarbsList() else autosensData.activeCarbsList = ArrayList()
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import androidx.work.WorkerParameters
|
|||
import androidx.work.workDataOf
|
||||
import dagger.android.HasAndroidInjector
|
||||
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.receivers.DataWorkerStorage
|
||||
import info.nightscout.core.utils.worker.LoggingWorker
|
||||
|
@ -56,7 +55,7 @@ class IobCobOrefWorker @Inject internal constructor(
|
|||
|
||||
class IobCobOrefWorkerData(
|
||||
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 end: Long,
|
||||
val limitDataToOldestAvailable: Boolean,
|
||||
|
@ -75,9 +74,9 @@ class IobCobOrefWorker @Inject internal constructor(
|
|||
return Result.success(workDataOf("Error" to "app still initializing"))
|
||||
}
|
||||
//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
|
||||
val ads = data.iobCobCalculatorPlugin.ads.clone()
|
||||
val ads = data.iobCobCalculator.ads.clone()
|
||||
val bucketedData = ads.bucketedData
|
||||
val autosensDataTable = ads.autosensDataTable
|
||||
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})")
|
||||
val sens = profile.getIsfMgdl(bgTime)
|
||||
val autosensData = AutosensDataObject(data.injector)
|
||||
val autosensData = data.iobCobCalculator.provideEmptyAutosensDataObject()
|
||||
autosensData.time = bgTime
|
||||
if (previous != null) autosensData.activeCarbsList = previous.cloneCarbsList() else autosensData.activeCarbsList = ArrayList()
|
||||
|
||||
|
@ -125,7 +124,7 @@ class IobCobOrefWorker @Inject internal constructor(
|
|||
autosensData.bg = bg
|
||||
delta = bg - bucketedData[i + 1].value
|
||||
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 deviation = delta - bgi
|
||||
val avgDeviation = ((avgDelta - bgi) * 1000).roundToLong() / 1000.0
|
||||
|
@ -260,7 +259,7 @@ class IobCobOrefWorker @Inject internal constructor(
|
|||
autosensData.autosensResult = sensitivity
|
||||
aapsLogger.debug(LTag.AUTOSENS, autosensData.toString())
|
||||
}
|
||||
data.iobCobCalculatorPlugin.ads = ads
|
||||
data.iobCobCalculator.ads = ads
|
||||
Thread {
|
||||
SystemClock.sleep(1000)
|
||||
rxBus.send(EventAutosensCalculationFinished(data.cause))
|
||||
|
|
Loading…
Reference in a new issue