Merge branch 'dev' of https://github.com/nightscout/AndroidAPS into avereha/warnings
This commit is contained in:
commit
b4cdd4e7b3
14 changed files with 213 additions and 14 deletions
|
@ -271,9 +271,12 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
private fun loadAll(from: String) {
|
||||
updateDate()
|
||||
Thread {
|
||||
overviewData.prepareBasalData(from)
|
||||
overviewData.prepareTemporaryTargetData(from)
|
||||
overviewData.prepareBgData("$from")
|
||||
overviewData.prepareTreatmentsData(from)
|
||||
rxBus.send(EventRefreshOverview("loadAll_$from"))
|
||||
overviewData.prepareTemporaryTargetData(from)
|
||||
rxBus.send(EventRefreshOverview("loadAll_$from"))
|
||||
overviewData.prepareBasalData(from)
|
||||
rxBus.send(EventRefreshOverview(from))
|
||||
aapsLogger.debug(LTag.UI, "loadAll $from finished")
|
||||
runCalculation(from)
|
||||
|
|
|
@ -187,7 +187,7 @@ class NSClientAddUpdateWorker(
|
|||
}
|
||||
eventType == TherapyEvent.Type.NOTE.text && json.isEffectiveProfileSwitch() -> // replace this by new Type when available in NS
|
||||
if (sp.getBoolean(R.string.key_ns_receive_profile_switch, false) && buildHelper.isEngineeringMode() || config.NSCLIENT) {
|
||||
effectiveProfileSwitchFromJson(json, dateUtil, activePlugin)?.let { effectiveProfileSwitch ->
|
||||
effectiveProfileSwitchFromJson(json, dateUtil)?.let { effectiveProfileSwitch ->
|
||||
repository.runTransactionForResult(SyncNsEffectiveProfileSwitchTransaction(effectiveProfileSwitch, invalidateByNsOnly = false))
|
||||
.doOnError {
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving EffectiveProfileSwitch", it)
|
||||
|
|
|
@ -90,7 +90,7 @@ class OverviewPlugin @Inject constructor(
|
|||
}, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventIobCalculationProgress::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ overviewData.calcProgress = it.progress; overviewBus.send(EventUpdateOverview("EventIobCalculationProgress", OverviewData.Property.CALC_PROGRESS)) }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventTempBasalChange::class.java)
|
||||
|
|
|
@ -510,10 +510,11 @@ class IobCobCalculatorPlugin @Inject constructor(
|
|||
|
||||
val tb = repository.getTemporaryBasalActiveAt(timestamp).blockingGet()
|
||||
if (tb is ValueWrapper.Existing) return tb.value
|
||||
val eb = repository.getExtendedBolusActiveAt(timestamp).blockingGet()
|
||||
val profile = profileFunction.getProfile(timestamp) ?: return null
|
||||
if (eb is ValueWrapper.Existing && activePlugin.activePump.isFakingTempsByExtendedBoluses)
|
||||
return eb.value.toTemporaryBasal(profile)
|
||||
if (activePlugin.activePump.isFakingTempsByExtendedBoluses) {
|
||||
val eb = repository.getExtendedBolusActiveAt(timestamp).blockingGet()
|
||||
val profile = profileFunction.getProfile(timestamp) ?: return null
|
||||
if (eb is ValueWrapper.Existing) return eb.value.toTemporaryBasal(profile)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ abstract class AutomationModule {
|
|||
@ContributesAndroidInjector abstract fun triggerBTDeviceInjector(): TriggerBTDevice
|
||||
@ContributesAndroidInjector abstract fun triggerRecurringTimeInjector(): TriggerRecurringTime
|
||||
@ContributesAndroidInjector abstract fun triggerTempTargetInjector(): TriggerTempTarget
|
||||
@ContributesAndroidInjector abstract fun triggerTempTargetValueInjector(): TriggerTempTargetValue
|
||||
@ContributesAndroidInjector abstract fun triggerTime(): TriggerTime
|
||||
@ContributesAndroidInjector abstract fun triggerTimeRangeInjector(): TriggerTimeRange
|
||||
@ContributesAndroidInjector abstract fun triggerWifiSsidInjector(): TriggerWifiSsid
|
||||
|
|
|
@ -311,6 +311,7 @@ class AutomationPlugin @Inject constructor(
|
|||
TriggerCOB(injector),
|
||||
TriggerProfilePercent(injector),
|
||||
TriggerTempTarget(injector),
|
||||
TriggerTempTargetValue(injector),
|
||||
TriggerWifiSsid(injector),
|
||||
TriggerLocation(injector),
|
||||
TriggerAutosensValue(injector),
|
||||
|
|
|
@ -131,6 +131,10 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
TriggerTempTarget::class.java.simpleName -> TriggerTempTarget(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerTempTargetValue::class.java.name,
|
||||
TriggerTempTargetValue::class.java.simpleName -> TriggerTempTargetValue(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerTime::class.java.name,
|
||||
TriggerTime::class.java.simpleName -> TriggerTime(injector).fromJSON(data.toString())
|
||||
TriggerTimeRange::class.java.name,
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.triggers
|
||||
|
||||
import android.widget.LinearLayout
|
||||
import com.google.common.base.Optional
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.automation.R
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputBg
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import org.json.JSONObject
|
||||
|
||||
class TriggerTempTargetValue(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
var ttValue = InputBg(profileFunction)
|
||||
var comparator = Comparator(resourceHelper)
|
||||
|
||||
constructor(injector: HasAndroidInjector, value: Double, units: GlucoseUnit, compare: Comparator.Compare) : this(injector) {
|
||||
ttValue = InputBg(profileFunction, value, units)
|
||||
comparator = Comparator(resourceHelper, compare)
|
||||
}
|
||||
|
||||
constructor(injector: HasAndroidInjector, triggerTempTarget: TriggerTempTargetValue) : this(injector) {
|
||||
ttValue = InputBg(profileFunction, triggerTempTarget.ttValue.value, triggerTempTarget.ttValue.units)
|
||||
comparator = Comparator(resourceHelper, triggerTempTarget.comparator.value)
|
||||
}
|
||||
|
||||
fun comparator(comparator: Comparator.Compare): TriggerTempTargetValue {
|
||||
this.comparator.value = comparator
|
||||
return this
|
||||
}
|
||||
|
||||
fun setUnits(units: GlucoseUnit): TriggerTempTargetValue {
|
||||
ttValue.units = units
|
||||
return this
|
||||
}
|
||||
|
||||
fun setValue(value: Double): TriggerTempTargetValue {
|
||||
ttValue.value = value
|
||||
return this
|
||||
}
|
||||
|
||||
override fun shouldRun(): Boolean {
|
||||
val tt = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()
|
||||
if (tt is ValueWrapper.Absent && comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||
return true
|
||||
}
|
||||
if (tt is ValueWrapper.Existing && comparator.value.check(tt.value.lowTarget, Profile.toMgdl(ttValue.value, ttValue.units))) {
|
||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||
return true
|
||||
}
|
||||
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription())
|
||||
return false
|
||||
}
|
||||
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("tt", ttValue.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
.put("units", ttValue.units.asText)
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
ttValue.setUnits(GlucoseUnit.fromText(JsonHelper.safeGetString(d, "units", Constants.MGDL)))
|
||||
ttValue.value = JsonHelper.safeGetDouble(d, "tt")
|
||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")!!))
|
||||
return this
|
||||
}
|
||||
|
||||
override fun friendlyName(): Int = R.string.careportal_temporarytargetvalue
|
||||
|
||||
override fun friendlyDescription(): String {
|
||||
return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE)
|
||||
resourceHelper.gs(R.string.notemptarget)
|
||||
else
|
||||
resourceHelper.gs(if (ttValue.units == GlucoseUnit.MGDL) R.string.temptargetcomparedmgdl else R.string.temptargetcomparedmmol, resourceHelper.gs(comparator.value.stringRes), ttValue.value, ttValue.units)
|
||||
}
|
||||
|
||||
override fun icon(): Optional<Int?> = Optional.of(R.drawable.ic_keyboard_tab)
|
||||
|
||||
override fun duplicate(): Trigger = TriggerTempTargetValue(injector, this)
|
||||
|
||||
override fun generateDialog(root: LinearLayout) {
|
||||
LayoutBuilder()
|
||||
.add(StaticLabel(resourceHelper, R.string.careportal_temporarytargetvalue, this))
|
||||
.add(comparator)
|
||||
.add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.target_u, ttValue.units), "", ttValue))
|
||||
.build(root)
|
||||
}
|
||||
}
|
|
@ -40,6 +40,9 @@
|
|||
<string name="glucoseisnotavailable">Glucose is not available</string>
|
||||
<string name="glucosecomparedmgdl">Glucose %1$s %2$.0f %3$s</string>
|
||||
<string name="glucosecomparedmmol">Glucose %1$s %2$.1f %3$s</string>
|
||||
<string name="notemptarget">Temp Target does not exist</string>
|
||||
<string name="temptargetcomparedmgdl">Temp Target %1$s %2$.0f %3$s</string>
|
||||
<string name="temptargetcomparedmmol">Temp Target %1$s %2$.1f %3$s</string>
|
||||
<string name="percentagecompared">Profile pct %1$s %2$d</string>
|
||||
<string name="iobcompared">IOB %1$s %2$.1f</string>
|
||||
<string name="and">And</string>
|
||||
|
@ -88,6 +91,7 @@
|
|||
<string name="latitude_short">Lat:</string>
|
||||
<string name="longitude_short">Lon:</string>
|
||||
<string name="glucose_u">Glucose [%1$s]:</string>
|
||||
<string name="target_u">Target [%1$s]:</string>
|
||||
<string name="lastboluslabel">Last bolus ago</string>
|
||||
<string name="lastboluscompared">Last bolus time %1$s %2$s min ago</string>
|
||||
<string name="triggercoblabel">COB</string>
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.triggers
|
||||
|
||||
import com.google.common.base.Optional
|
||||
import info.nightscout.androidaps.automation.R
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator
|
||||
import io.reactivex.Single
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||
|
||||
var now = 1514766900000L
|
||||
|
||||
@Before
|
||||
fun prepare() {
|
||||
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||
`when`(dateUtil.now()).thenReturn(now)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldRunTest() {
|
||||
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Existing(TemporaryTarget(duration = 60000, highTarget = 140.0, lowTarget = 140.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = now - 1))))
|
||||
var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent()))
|
||||
Assert.assertTrue(t.shouldRun())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun copyConstructorTest() {
|
||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
val t1 = t.duplicate() as TriggerTempTargetValue
|
||||
Assert.assertEquals(140.0, t1.ttValue.value, 0.01)
|
||||
Assert.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
|
||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}"
|
||||
|
||||
@Test
|
||||
fun toJSONTest() {
|
||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assert.assertEquals(ttJson, t.toJSON())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromJSONTest() {
|
||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue
|
||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
||||
Assert.assertEquals(7.7, t2.ttValue.value, 0.01)
|
||||
Assert.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun iconTest() {
|
||||
Assert.assertEquals(Optional.of(R.drawable.ic_keyboard_tab), TriggerTempTargetValue(injector).icon())
|
||||
}
|
||||
}
|
||||
|
|
@ -66,10 +66,13 @@ allprojects {
|
|||
maven { url "https://maven.google.com" }
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
//Support @JvmDefault
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = ['-Xjvm-default=all']
|
||||
freeCompilerArgs = [
|
||||
// Ignore warning for @ExperimentalCoroutinesApi
|
||||
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
'-Xjvm-default=all' //Support @JvmDefault
|
||||
]
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import info.nightscout.androidaps.data.ProfileSealed
|
|||
import info.nightscout.androidaps.database.embedments.InterfaceIDs
|
||||
import info.nightscout.androidaps.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
|
@ -43,7 +42,7 @@ fun EffectiveProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObjec
|
|||
if (isAdd && interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||
}
|
||||
|
||||
fun effectiveProfileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil, activePlugin: ActivePlugin): EffectiveProfileSwitch? {
|
||||
fun effectiveProfileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil): EffectiveProfileSwitch? {
|
||||
val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null
|
||||
val originalTimeshift = JsonHelper.safeGetLong(jsonObject, "originalTimeshift")
|
||||
val originalDuration = JsonHelper.safeGetLong(jsonObject, "originalDuration")
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.general.maintenance
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import info.nightscout.androidaps.annotations.OpenForTesting
|
||||
import info.nightscout.androidaps.core.R
|
||||
|
@ -30,7 +29,7 @@ class PrefFileListProvider @Inject constructor(
|
|||
private val storage: Storage,
|
||||
private val versionCheckerUtils: VersionCheckerUtils
|
||||
) {
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private val path = File(Environment.getExternalStorageDirectory().toString())
|
||||
private val aapsPath = File(path, "AAPS" + File.separator + "preferences")
|
||||
private val exportsPath = File(path, "AAPS" + File.separator + "exports")
|
||||
|
|
|
@ -272,6 +272,7 @@
|
|||
<string name="careportal_openapsoffline">OpenAPS Offline</string>
|
||||
<string name="careportal_pumpbatterychange">Pump Battery Change</string>
|
||||
<string name="careportal_temporarytarget">Temporary target</string>
|
||||
<string name="careportal_temporarytargetvalue">Temporary target value</string>
|
||||
<string name="careportal_temporarytargetcancel">Temporary target cancel</string>
|
||||
<string name="boluswizard">Bolus wizard</string>
|
||||
<string name="glucosetype_finger">Finger</string>
|
||||
|
|
Loading…
Reference in a new issue