double SMB fix
This commit is contained in:
parent
b9806d0ea9
commit
c5aa12c5ba
6 changed files with 52 additions and 29 deletions
|
@ -35,7 +35,7 @@ class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldRun(): Boolean {
|
override fun shouldRun(): Boolean {
|
||||||
val lastBolusTime = treatmentsPlugin.getLastBolusTime(false)
|
val lastBolusTime = treatmentsPlugin.getLastBolusTime(true)
|
||||||
if (lastBolusTime == 0L)
|
if (lastBolusTime == 0L)
|
||||||
return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||||
|
|
|
@ -45,6 +45,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
@ -588,6 +589,30 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the newest record with insulin > 0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Treatment getLastBolus(boolean excludeSMB) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<Treatment, Long> queryBuilder = getDao().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.gt("insulin", 0);
|
||||||
|
where.and().le("date", DateUtil.now());
|
||||||
|
where.and().eq("isValid", true);
|
||||||
|
if (excludeSMB) where.and().eq("isSMB", false);
|
||||||
|
queryBuilder.orderBy("date", false);
|
||||||
|
queryBuilder.limit(1L);
|
||||||
|
|
||||||
|
List<Treatment> result = getDao().query(queryBuilder.prepare());
|
||||||
|
if (result.isEmpty())
|
||||||
|
return null;
|
||||||
|
return result.get(0);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteNS(JSONObject json) {
|
public void deleteNS(JSONObject json) {
|
||||||
String _id = JsonHelper.safeGetString(json, "_id");
|
String _id = JsonHelper.safeGetString(json, "_id");
|
||||||
if (_id != null && !_id.isEmpty())
|
if (_id != null && !_id.isEmpty())
|
||||||
|
|
|
@ -335,33 +335,27 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLastBolusTime() {
|
public long getLastBolusTime() {
|
||||||
long now = System.currentTimeMillis();
|
Treatment last = getService().getLastBolus(false);
|
||||||
long last = 0;
|
if (last == null) {
|
||||||
synchronized (treatments) {
|
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: NOTHING FOUND");
|
||||||
for (Treatment t : treatments) {
|
return 0;
|
||||||
if (!t.isValid)
|
}
|
||||||
continue;
|
else {
|
||||||
if (t.date > last && t.insulin > 0 && t.date <= now)
|
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: " + dateUtil.dateAndTimeString(last.date));
|
||||||
last = t.date;
|
return last.date;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: " + dateUtil.dateAndTimeString(last));
|
|
||||||
return last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastBolusTime(boolean isSMB) {
|
public long getLastBolusTime(boolean excludeSMB) {
|
||||||
long now = System.currentTimeMillis();
|
Treatment last = getService().getLastBolus(excludeSMB);
|
||||||
long last = 0;
|
if (last == null) {
|
||||||
synchronized (treatments) {
|
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: NOTHING FOUND");
|
||||||
for (Treatment t : treatments) {
|
return 0;
|
||||||
if (!t.isValid)
|
}
|
||||||
continue;
|
else {
|
||||||
if (t.date > last && t.insulin > 0 && t.date <= now && isSMB == t.isSMB)
|
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: " + dateUtil.dateAndTimeString(last.date));
|
||||||
last = t.date;
|
return last.date;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: " + dateUtil.dateAndTimeString(last));
|
|
||||||
return last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldRunTest() {
|
fun shouldRunTest() {
|
||||||
`when`(treatmentsPlugin.getLastBolusTime(false)).thenReturn(now) // Set last bolus time to now
|
`when`(treatmentsPlugin.getLastBolusTime(true)).thenReturn(now) // Set last bolus time to now
|
||||||
`when`(DateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min
|
`when`(DateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min
|
||||||
var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
|
var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assert.assertEquals(110, t.minutesAgo.value)
|
Assert.assertEquals(110, t.minutesAgo.value)
|
||||||
|
@ -53,7 +53,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
PowerMockito.`when`(treatmentsPlugin.getLastBolusTime(false)).thenReturn(0L) // Set last bolus time to 0
|
PowerMockito.`when`(treatmentsPlugin.getLastBolusTime(true)).thenReturn(0L) // Set last bolus time to 0
|
||||||
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package info.nightscout.androidaps.danars.comm
|
package info.nightscout.androidaps.danars.comm
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.logging.LTag
|
|
||||||
import info.nightscout.androidaps.dana.DanaPump
|
import info.nightscout.androidaps.dana.DanaPump
|
||||||
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
||||||
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DanaRS_Packet_Bolus_Get_Step_Bolus_Information(
|
class DanaRS_Packet_Bolus_Get_Step_Bolus_Information(
|
||||||
|
@ -24,7 +25,8 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_Information(
|
||||||
danaPump.initialBolusAmount = intFromBuff(data, 2, 2) / 100.0
|
danaPump.initialBolusAmount = intFromBuff(data, 2, 2) / 100.0
|
||||||
val hours = intFromBuff(data, 4, 1)
|
val hours = intFromBuff(data, 4, 1)
|
||||||
val minutes = intFromBuff(data, 5, 1)
|
val minutes = intFromBuff(data, 5, 1)
|
||||||
danaPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis
|
if (danaPump.usingUTC) danaPump.lastBolusTime = DateTime.now().withZone(DateTimeZone.UTC).withHourOfDay(hours).withMinuteOfHour(minutes).millis
|
||||||
|
else danaPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis
|
||||||
danaPump.lastBolusAmount = intFromBuff(data, 6, 2) / 100.0
|
danaPump.lastBolusAmount = intFromBuff(data, 6, 2) / 100.0
|
||||||
danaPump.maxBolus = intFromBuff(data, 8, 2) / 100.0
|
danaPump.maxBolus = intFromBuff(data, 8, 2) / 100.0
|
||||||
danaPump.bolusStep = intFromBuff(data, 10, 1) / 100.0
|
danaPump.bolusStep = intFromBuff(data, 10, 1) / 100.0
|
||||||
|
|
|
@ -5,6 +5,7 @@ import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.dana.DanaPump
|
import info.nightscout.androidaps.dana.DanaPump
|
||||||
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DanaRS_Packet_General_Get_More_Information(
|
class DanaRS_Packet_General_Get_More_Information(
|
||||||
|
@ -30,7 +31,8 @@ class DanaRS_Packet_General_Get_More_Information(
|
||||||
// val remainRate = intFromBuff(data, 7, 2) / 100.0
|
// val remainRate = intFromBuff(data, 7, 2) / 100.0
|
||||||
val hours = intFromBuff(data, 9, 1)
|
val hours = intFromBuff(data, 9, 1)
|
||||||
val minutes = intFromBuff(data, 10, 1)
|
val minutes = intFromBuff(data, 10, 1)
|
||||||
danaPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis
|
if (danaPump.usingUTC) danaPump.lastBolusTime = DateTime.now().withZone(DateTimeZone.UTC).withHourOfDay(hours).withMinuteOfHour(minutes).millis
|
||||||
|
else danaPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis
|
||||||
danaPump.lastBolusAmount = intFromBuff(data, 11, 2) / 100.0
|
danaPump.lastBolusAmount = intFromBuff(data, 11, 2) / 100.0
|
||||||
// On DanaRS DailyUnits can't be more than 160
|
// On DanaRS DailyUnits can't be more than 160
|
||||||
if (danaPump.dailyTotalUnits > 160) failed = true
|
if (danaPump.dailyTotalUnits > 160) failed = true
|
||||||
|
|
Loading…
Reference in a new issue