From 379df79bf8dacad5593873fce873271ea39b7cd6 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 18 Mar 2018 23:44:33 +0100 Subject: [PATCH 01/10] CB.applySMBRequest: return reason when skipping due to frequency. --- .../ConfigBuilder/ConfigBuilderPlugin.java | 89 +++++++++++-------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index e0a8155ffa..783aee258a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -355,11 +355,13 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr * expect absolute request and allow both absolute and percent response based on pump capabilities */ public void applyTBRRequest(APSResult request, Profile profile, Callback callback) { + if (!request.tempBasalReqested) { + return; + } + PumpInterface pump = getActivePump(); request.rate = applyBasalConstraints(request.rate); - long now = System.currentTimeMillis(); - if (!pump.isInitialized()) { log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized)); if (callback != null) { @@ -379,37 +381,50 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: " + request.toString()); - if (request.tempBasalReqested) { - TemporaryBasal activeTemp = getTempBasalFromHistory(now); - if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) { - if (activeTemp != null) { - if (Config.logCongigBuilderActions) - log.debug("applyAPSRequest: cancelTempBasal()"); - getCommandQueue().cancelTempBasal(false, callback); - } else { - if (Config.logCongigBuilderActions) - log.debug("applyAPSRequest: Basal set correctly"); - if (callback != null) { - callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run(); - } - } - } else if (activeTemp != null - && activeTemp.getPlannedRemainingMinutes() > 5 - && Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) { + long now = System.currentTimeMillis(); + TemporaryBasal activeTemp = getTempBasalFromHistory(now); + if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) { + if (activeTemp != null) { if (Config.logCongigBuilderActions) - log.debug("applyAPSRequest: Temp basal set correctly"); - if (callback != null) { - callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)).duration(activeTemp.getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run(); - } + log.debug("applyAPSRequest: cancelTempBasal()"); + getCommandQueue().cancelTempBasal(false, callback); } else { if (Config.logCongigBuilderActions) - log.debug("applyAPSRequest: setTempBasalAbsolute()"); - getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback); + log.debug("applyAPSRequest: Basal set correctly"); + if (callback != null) { + callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run(); + } } + } else if (activeTemp != null + && activeTemp.getPlannedRemainingMinutes() > 5 + && Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) { + if (Config.logCongigBuilderActions) + log.debug("applyAPSRequest: Temp basal set correctly"); + if (callback != null) { + callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)).duration(activeTemp.getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run(); + } + } else { + if (Config.logCongigBuilderActions) + log.debug("applyAPSRequest: setTempBasalAbsolute()"); + getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback); } } public void applySMBRequest(APSResult request, Callback callback) { + if (!request.bolusRequested) { + return; + } + + long lastBolusTime = getLastBolusTime(); + if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) { + log.debug("SMB requested but still in 3 min interval"); + if (callback != null) { + callback.result(new PumpEnactResult() + .comment(MainApp.gs(R.string.smb_frequency_exceeded)) + .enacted(false).success(false)).run(); + } + } + PumpInterface pump = getActivePump(); if (!pump.isInitialized()) { @@ -431,20 +446,16 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr if (Config.logCongigBuilderActions) log.debug("applySMBRequest: " + request.toString()); - if (request.bolusRequested) { - long lastBolusTime = getLastBolusTime(); - if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) { - log.debug("SMB requsted but still in 3 min interval"); - } else { - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; - detailedBolusInfo.insulin = request.smb; - detailedBolusInfo.isSMB = true; - detailedBolusInfo.source = Source.USER; - detailedBolusInfo.deliverAt = request.deliverAt; - getCommandQueue().bolus(detailedBolusInfo, callback); - } - } + // deliver SMB + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; + detailedBolusInfo.insulin = request.smb; + detailedBolusInfo.isSMB = true; + detailedBolusInfo.source = Source.USER; + detailedBolusInfo.deliverAt = request.deliverAt; + if (Config.logCongigBuilderActions) + log.debug("applyAPSRequest: bolus()"); + getCommandQueue().bolus(detailedBolusInfo, callback); } /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6aace520ea..8f30bada44 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -962,5 +962,6 @@ ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile. Bolus count TBR count + A bolus was delivered within the last 3 minutes, skipping SMB From fad10af11b5bad4cd8c3b50f4545a4f1bb349071 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 11:08:58 +0100 Subject: [PATCH 02/10] Clean ups around PumpEnactResult, APSResult. --- .../androidaps/data/PumpEnactResult.java | 23 +++++++++++-------- .../ConfigBuilder/ConfigBuilderPlugin.java | 5 +--- .../androidaps/plugins/Loop/APSResult.java | 6 ++--- .../OpenAPSAMA/DetermineBasalResultAMA.java | 10 ++++---- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 6 ++--- .../OpenAPSMA/DetermineBasalResultMA.java | 12 +++++----- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 6 ++--- .../OpenAPSSMB/DetermineBasalResultSMB.java | 4 ++-- .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 6 ++--- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java index 9aa09244aa..a9467caafd 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java +++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java @@ -100,16 +100,19 @@ public class PumpEnactResult { ret += "\n" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + "U"; } else if (isTempCancel) { ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; - ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment + "\n" + - MainApp.sResources.getString(R.string.canceltemp); + if (!comment.isEmpty()) + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + ret += MainApp.sResources.getString(R.string.canceltemp); } else if (isPercent) { ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; - ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + if (!comment.isEmpty()) + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; ret += "\n" + MainApp.sResources.getString(R.string.percent) + ": " + percent + "%"; } else { ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; - ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + if (!comment.isEmpty()) + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; ret += "\n" + MainApp.sResources.getString(R.string.absolute) + ": " + absolute + " U/h"; } @@ -126,7 +129,8 @@ public class PumpEnactResult { } else if (enacted) { if (bolusDelivered > 0) { ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; - ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + if (!comment.isEmpty()) + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; ret += "
" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + "U"; } else if (isTempCancel) { ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; @@ -134,18 +138,17 @@ public class PumpEnactResult { "
" + MainApp.sResources.getString(R.string.canceltemp); } else if (isPercent && percent != -1) { ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; - ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + if (!comment.isEmpty()) + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; ret += "
" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; ret += "
" + MainApp.sResources.getString(R.string.percent) + ": " + percent + "%"; } else if (absolute != -1) { ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; - ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + if (!comment.isEmpty()) + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; ret += "
" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; ret += "
" + MainApp.sResources.getString(R.string.absolute) + ": " + DecimalFormatter.to2Decimal(absolute) + " U/h"; } - if (bolusDelivered > 0) { - ret += "
" + MainApp.sResources.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusDelivered) + " U"; - } } else { ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 783aee258a..2fb7e6efa0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -4,8 +4,6 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.annotation.Nullable; -import org.json.JSONException; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +41,6 @@ import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.queue.Callback; @@ -355,7 +352,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr * expect absolute request and allow both absolute and percent response based on pump capabilities */ public void applyTBRRequest(APSResult request, Profile profile, Callback callback) { - if (!request.tempBasalReqested) { + if (!request.tempBasalRequested) { return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index 8050aa7769..7eab0e7722 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -31,7 +31,7 @@ public class APSResult { public String reason; public double rate; public int duration; - public boolean tempBasalReqested = false; + public boolean tempBasalRequested = false; public boolean bolusRequested = false; public IobTotal iob; public JSONObject json = new JSONObject(); @@ -98,7 +98,7 @@ public class APSResult { newResult.reason = reason; newResult.rate = rate; newResult.duration = duration; - newResult.tempBasalReqested = tempBasalReqested; + newResult.tempBasalRequested = tempBasalRequested; newResult.bolusRequested = bolusRequested; newResult.iob = iob; return newResult; @@ -216,6 +216,6 @@ public class APSResult { } public boolean isChangeRequested() { - return tempBasalReqested || bolusRequested; + return tempBasalRequested || bolusRequested; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java index 50dde42674..cb2b4a0091 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java @@ -22,7 +22,7 @@ public class DetermineBasalResultAMA extends APSResult { json = j; if (result.containsKey("error")) { reason = result.get("error").toString(); - tempBasalReqested = false; + tempBasalRequested = false; rate = -1; duration = -1; } else { @@ -32,17 +32,17 @@ public class DetermineBasalResultAMA extends APSResult { if (result.containsKey("rate")) { rate = (Double) result.get("rate"); if (rate < 0d) rate = 0d; - tempBasalReqested = true; + tempBasalRequested = true; } else { rate = -1; - tempBasalReqested = false; + tempBasalRequested = false; } if (result.containsKey("duration")) { duration = ((Double) result.get("duration")).intValue(); //changeRequested as above } else { duration = -1; - tempBasalReqested = false; + tempBasalRequested = false; } } bolusRequested = false; @@ -58,7 +58,7 @@ public class DetermineBasalResultAMA extends APSResult { newResult.reason = reason; newResult.rate = rate; newResult.duration = duration; - newResult.tempBasalReqested = tempBasalReqested; + newResult.tempBasalRequested = tempBasalRequested; newResult.rate = rate; newResult.duration = duration; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index dfab195125..f2d792d9e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -246,7 +246,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { Profiler.log(log, "AMA calculation", start); // Fix bug determine basal if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) - determineBasalResultAMA.tempBasalReqested = false; + determineBasalResultAMA.tempBasalRequested = false; // limit requests on openloop mode if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { long now = System.currentTimeMillis(); @@ -254,9 +254,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultAMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { - determineBasalResultAMA.tempBasalReqested = false; + determineBasalResultAMA.tempBasalRequested = false; } else if (activeTemp == null && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) - determineBasalResultAMA.tempBasalReqested = false; + determineBasalResultAMA.tempBasalRequested = false; } determineBasalResultAMA.iob = iobArray[0]; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java index 3f40c02980..75928f09d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java @@ -20,7 +20,7 @@ public class DetermineBasalResultMA extends APSResult { json = j; if (result.containsKey("error")) { reason = (String) result.get("error"); - tempBasalReqested = false; + tempBasalRequested = false; rate = -1; duration = -1; mealAssist = ""; @@ -31,17 +31,17 @@ public class DetermineBasalResultMA extends APSResult { if (result.containsKey("rate")) { rate = (Double) result.get("rate"); if (rate < 0d) rate = 0d; - tempBasalReqested = true; + tempBasalRequested = true; } else { rate = -1; - tempBasalReqested = false; + tempBasalRequested = false; } if (result.containsKey("duration")) { duration = ((Double) result.get("duration")).intValue(); //changeRequested as above } else { duration = -1; - tempBasalReqested = false; + tempBasalRequested = false; } if (result.containsKey("mealAssist")) { mealAssist = result.get("mealAssist").toString(); @@ -58,10 +58,10 @@ public class DetermineBasalResultMA extends APSResult { newResult.reason = new String(reason); newResult.rate = rate; newResult.duration = duration; - newResult.tempBasalReqested = isChangeRequested(); + newResult.tempBasalRequested = isChangeRequested(); newResult.rate = rate; newResult.duration = duration; - newResult.tempBasalReqested = isChangeRequested(); + newResult.tempBasalRequested = isChangeRequested(); try { newResult.json = new JSONObject(json.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 76df63e752..a8a6628743 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -235,16 +235,16 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke(); // Fix bug determinef basal if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) - determineBasalResultMA.tempBasalReqested = false; + determineBasalResultMA.tempBasalRequested = false; // limit requests on openloop mode if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { - determineBasalResultMA.tempBasalReqested = false; + determineBasalResultMA.tempBasalRequested = false; } else if (activeTemp == null && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) - determineBasalResultMA.tempBasalReqested = false; + determineBasalResultMA.tempBasalRequested = false; } determineBasalResultMA.iob = iobTotal; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java index 0320b3633d..59c1dd95e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java @@ -35,7 +35,7 @@ public class DetermineBasalResultSMB extends APSResult { if (result.has("carbsReq")) carbsReq = result.getDouble("carbsReq"); if (result.has("rate") && result.has("duration")) { - tempBasalReqested = true; + tempBasalRequested = true; rate = result.getDouble("rate"); if (rate < 0d) rate = 0d; duration = result.getInt("duration"); @@ -74,7 +74,7 @@ public class DetermineBasalResultSMB extends APSResult { newResult.reason = reason; newResult.rate = rate; newResult.duration = duration; - newResult.tempBasalReqested = tempBasalReqested; + newResult.tempBasalRequested = tempBasalRequested; newResult.bolusRequested = bolusRequested; newResult.rate = rate; newResult.duration = duration; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index f10e6cb0be..778b9d5849 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -251,16 +251,16 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { // TODO still needed with oref1? // Fix bug determine basal if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) - determineBasalResultSMB.tempBasalReqested = false; + determineBasalResultSMB.tempBasalRequested = false; // limit requests on openloop mode if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultSMB.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { - determineBasalResultSMB.tempBasalReqested = false; + determineBasalResultSMB.tempBasalRequested = false; } else if (activeTemp == null && Math.abs(determineBasalResultSMB.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) - determineBasalResultSMB.tempBasalReqested = false; + determineBasalResultSMB.tempBasalRequested = false; } determineBasalResultSMB.iob = iobArray[0]; From d1f1db859b0b4f20b689f92a95899a34a2a6cf64 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 11:33:52 +0100 Subject: [PATCH 03/10] Translations cleanup. --- app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 10a2d32c6f..1d99f86773 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -742,4 +742,6 @@ Es wurde keine hohe TBR gesetzt, da nach der Berechnung Boluseinträge in der Pumpenhistorik gefunden wurden. Der letzte Bolus liegt mehr als 24 Stunden zurück oder liegt in der Zukunft. Prüfe bitte das Datum auf der Pumpe. Zeit/Datum des abgegebenen Boluses auf der Pumpe erscheint falsch, IOB ist wahrscheinlich nicht korrekt. Bitte prüfe Zeit/Datum der Pumpe. + Anzahl TBRs + Anzahl Boluse diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f30bada44..2f0cf26d7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -641,8 +641,8 @@ Cancel Not all profiles loaded! Values not stored! - Accu-Chek Combo - COMBO + Accu-Chek Combo + COMBO Enable broadcasts to other apps (like xDrip). Enable local Broadcasts. ACTIVITY & FEEDBACK From 706bb913e921677f00634015c7591825a60970c9 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 12:07:28 +0100 Subject: [PATCH 04/10] LoopPlugin: fix 'waiting for pump' display for SMB. --- .../info/nightscout/androidaps/plugins/Loop/LoopPlugin.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 5846140b1e..a278e5742b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -333,7 +333,10 @@ public class LoopPlugin implements PluginBase { if (result.isChangeRequested()) { final PumpEnactResult waiting = new PumpEnactResult(); waiting.queued = true; - lastRun.tbrSetByPump = waiting; + if (resultAfterConstraints.tempBasalRequested) + lastRun.tbrSetByPump = waiting; + if (resultAfterConstraints.bolusRequested) + lastRun.smbSetByPump = waiting; MainApp.bus().post(new EventLoopUpdateGui()); FabricPrivacy.getInstance().logCustom(new CustomEvent("APSRequest")); MainApp.getConfigBuilder().applyTBRRequest(resultAfterConstraints, profile, new Callback() { From f918a5f30395993decc3cd487bbac02a06cb9c6e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 13:10:09 +0100 Subject: [PATCH 05/10] More loop results cleanup and i18n. --- .../info/nightscout/androidaps/data/PumpEnactResult.java | 5 +++-- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 7 +++++-- .../androidaps/plugins/PumpCombo/ComboFragment.java | 4 ++-- app/src/main/res/layout/overview_wizard_dialog.xml | 2 +- app/src/main/res/values-bg/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-el/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values-ro/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-sv/strings.xml | 2 +- app/src/main/res/values/strings.xml | 5 +++-- 17 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java index a9467caafd..264a153c5e 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java +++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java @@ -97,7 +97,8 @@ public class PumpEnactResult { if (bolusDelivered > 0) { ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; - ret += "\n" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + "U"; + ret += "\n" + MainApp.sResources.getString(R.string.smb_shortname) + + ": " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname); } else if (isTempCancel) { ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; if (!comment.isEmpty()) @@ -131,7 +132,7 @@ public class PumpEnactResult { ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; if (!comment.isEmpty()) ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; - ret += "
" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + "U"; + ret += "
" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname); } else if (isTempCancel) { ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 2fb7e6efa0..24da254cee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -389,7 +389,8 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: Basal set correctly"); if (callback != null) { - callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run(); + callback.result(new PumpEnactResult().absolute(request.rate).duration(0) + .enacted(false).success(true).comment(MainApp.gs(R.string.basal_set_correctly))).run(); } } } else if (activeTemp != null @@ -398,7 +399,9 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: Temp basal set correctly"); if (callback != null) { - callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)).duration(activeTemp.getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run(); + callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)) + .enacted(false).success(true).duration(activeTemp.getPlannedRemainingMinutes()) + .comment(MainApp.gs(R.string.let_temp_basal_run))).run(); } } else { if (Config.logCongigBuilderActions) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index d7c0a4b7c6..9753f35ea4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -233,7 +233,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis // reservoir int reservoirLevel = plugin.getPump().reservoirLevel; if (reservoirLevel != -1) { - reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); + reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.insulin_unit_shortname)); } else if (ps.insulinState == PumpState.LOW) { reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low)); } else if (ps.insulinState == PumpState.EMPTY) { @@ -275,7 +275,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis if (bolus != null) { long agoMsc = System.currentTimeMillis() - bolus.timestamp; double bolusMinAgo = agoMsc / 60d / 1000d; - String unit = MainApp.gs(R.string.treatments_wizard_unit_label); + String unit = MainApp.gs(R.string.insulin_unit_shortname); String ago; if ((agoMsc < 60 * 1000)) { ago = MainApp.gs(R.string.combo_pump_connected_now); diff --git a/app/src/main/res/layout/overview_wizard_dialog.xml b/app/src/main/res/layout/overview_wizard_dialog.xml index faaae6967d..4fbdfd3614 100644 --- a/app/src/main/res/layout/overview_wizard_dialog.xml +++ b/app/src/main/res/layout/overview_wizard_dialog.xml @@ -108,7 +108,7 @@ android:gravity="left" android:minWidth="45dp" android:paddingLeft="5dp" - android:text="@string/treatments_wizard_unit_label" + android:text="@string/insulin_unit_shortname" android:textAppearance="?android:attr/textAppearanceSmall" /> diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index a8ce006ae4..1c50162d75 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -40,7 +40,7 @@ КЗ ВХ Корекция - Ед + Ед IOB от болуси Старт сега Базова базална стойност diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 9b41207756..a62329ae4b 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -139,7 +139,7 @@ Bolusové IOB Sacharidy Korekce - U + U Maximální povolený bolus [U] Maximální povolené sacharidy [g] Bezpečnost zadání ošetřeni diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1d99f86773..bbe2ed5497 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -84,7 +84,7 @@ Aktives Gesamt-IOB: Gesamt-IOB: Basal-IOB - IE + IE Virtuelle Pumpe Reservoir xDrip diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 2dbac99d72..1b7fdf8022 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -42,7 +42,7 @@ TT Υδατάνθρακες Διόρθωση - U + U Bolus IOB Έναρξη τώρα ΕΙΚΟΝΙΚΗ ΑΝΤΛΙΑ diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3a3c46cf13..af936ed618 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -36,7 +36,7 @@ Glucosa Hidratos Carbono Corrección - U + U Bolo IOB Ejecutar ahora BOMBA VIRTUAL diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 44550e54dc..67ecda2b0f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -42,7 +42,7 @@ CT Glucides Corr - U + U Bolus IR "Exécuter maintenant " POMPE VIRTUELLE diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9877ee2535..352f802ee6 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -425,7 +425,7 @@ Sicurezza delle prestazioni Valore massimo carbo (g) Bolo massimo (U) - U + U Correzione COB Carboidrati diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index a0994b4e9f..46f1cb3525 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -40,7 +40,7 @@ 혈당 탄수화물 교정 - U + U 식사주입 IOB 지금 실행 가상 펌프 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index a6bb2f2d34..ca73dcbffa 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -347,7 +347,7 @@ Autoscroll Geen NS API geheim op (min 12 kar.) Max toegestane bolus [E] - E + E Correctie COB Koolhydraten diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index caa88fbe76..aca835b34d 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -42,7 +42,7 @@ BG Carbohidrați Corecție - U + U Bolus IOB Fă acum POMPĂ VIRTUALĂ diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 2ebcf74b46..ddc446b62c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -482,7 +482,7 @@ углеводы активн углеводы коррекция - ед + ед макс разрешенный болюс макс разрешенные углеводы (г) безопасность назначений diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index d4923abfbb..669f96e4e9 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -303,7 +303,7 @@ Säkerhet vid behandling Max tillåtna KH (g) Max tillåten bolus [E] - E + E Korr COB KH diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f0cf26d7e..ffe1df0bc9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,7 +42,7 @@ TT Carbs Corr - U + U Bolus IOB Run now VIRTUAL PUMP @@ -889,7 +889,7 @@ Enable SMB when there is temp target active (eating soon, exercise) Enable SMB with high temp targets Enable SMB when there is high temp target active (exercise) - Let current temp basal run + Let temp basal run Mute Insulin Carbs @@ -963,5 +963,6 @@ Bolus count TBR count A bolus was delivered within the last 3 minutes, skipping SMB + Basal set correctly From ede1e719d2881394a95f0a8d58edb02388e6a894 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 13:33:40 +0100 Subject: [PATCH 06/10] CB.applyTBRRequest: enact same-rate TBR ... if requested duration is at least 30m longer than the currently running TBR. --- .../androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 24da254cee..40b7dec74c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -395,6 +395,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr } } else if (activeTemp != null && activeTemp.getPlannedRemainingMinutes() > 5 + && request.duration - activeTemp.getPlannedRemainingMinutes() < 30 && Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) { if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: Temp basal set correctly"); From 85d8730eae1c1d7c458f64b8d844742765bafdc7 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 14:33:57 +0100 Subject: [PATCH 07/10] Add missing return. --- .../androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 40b7dec74c..7f24aac23f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -424,6 +424,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr .comment(MainApp.gs(R.string.smb_frequency_exceeded)) .enacted(false).success(false)).run(); } + return; } PumpInterface pump = getActivePump(); From 86b25174e2a4b0b43431e575669e1e3adecda2b4 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 19 Mar 2018 15:59:23 +0100 Subject: [PATCH 08/10] Combo: unbreak basal rate conversion. This aligns the combo with the changes from the nodefaultprofile merge. --- .../nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index bf7b48dc41..afefbe80da 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -347,7 +347,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private BasalProfile convertProfileToComboProfile(Profile profile) { BasalProfile basalProfile = new BasalProfile(); for (int i = 0; i < 24; i++) { - double rate = profile.getBasal(Integer.valueOf(i * 60 * 60)); + double rate = profile.getBasalTimeFromMidnight(i * 60 * 60); /*The Combo pump does hava a different granularity for basal rate: * 0.01 - if below 1U/h From d62a836f6ca770241de0657dc3dabe96d4abead0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 20 Mar 2018 10:07:52 +0100 Subject: [PATCH 09/10] resistant adult max bolus 25U --- app/src/main/java/info/nightscout/utils/HardLimits.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/HardLimits.java b/app/src/main/java/info/nightscout/utils/HardLimits.java index 00e42ce535..a277148d11 100644 --- a/app/src/main/java/info/nightscout/utils/HardLimits.java +++ b/app/src/main/java/info/nightscout/utils/HardLimits.java @@ -18,7 +18,7 @@ public class HardLimits { final static int ADULT = 2; final static int RESISTANTADULT = 3; - final static double[] MAXBOLUS = {5d, 10d, 17d, 21d}; + final static double[] MAXBOLUS = {5d, 10d, 17d, 25d}; // Very Hard Limits Ranges // First value is the Lowest and second value is the Highest a Limit can define @@ -40,7 +40,7 @@ public class HardLimits { public static final double MAXISF = 720; // mgdl public static final double[] MAXIOB_AMA = {3, 5, 7, 12}; - public static final double[] MAXIOB_SMB = {3, 7, 12, 22}; + public static final double[] MAXIOB_SMB = {3, 7, 12, 25}; public static final double[] MAXBASAL = {2, 5, 10, 12}; From e117527257adf510cf9c4a9ff0e5cece39a64e00 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 20 Mar 2018 19:05:12 +0100 Subject: [PATCH 10/10] Revert "Merge pull request #770 from jotomo/new-bg-processing" This reverts commit 7f0918d1472cfab2237ff5ecb2bd9563d9b2d745, reversing changes made to 3f04d10f79638d7b47a7d8d817e6685996c2b36c. --- .../androidaps/Services/DataService.java | 12 ++++++------ .../androidaps/db/DatabaseHelper.java | 13 +++++++------ .../androidaps/events/EventNewBG.java | 11 +---------- .../IobCobCalculatorPlugin.java | 2 -- .../androidaps/plugins/Loop/LoopPlugin.java | 9 ++------- .../plugins/Overview/Dialogs/WizardDialog.java | 18 ++++++++---------- .../PersistentNotificationPlugin.java | 3 +-- .../androidaps/plugins/Wear/WearPlugin.java | 3 +-- .../XDripStatusline/StatuslinePlugin.java | 3 +-- 9 files changed, 27 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 07ca0fc049..5faa288d77 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -192,7 +192,7 @@ public class DataService extends IntentService { bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP); bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW); - MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP", xDripEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP"); } private void handleNewDataFromGlimp(Intent intent) { @@ -206,7 +206,7 @@ public class DataService extends IntentService { bgReading.date = bundle.getLong("myTimestamp"); bgReading.raw = 0; - MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP", glimpEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP"); } private void handleNewDataFromDexcomG5(Intent intent) { @@ -229,7 +229,7 @@ public class DataService extends IntentService { bgReading.direction = json.getString("m_trend"); bgReading.date = json.getLong("m_time") * 1000L; bgReading.raw = 0; - boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5", dexcomG5Enabled); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { NSUpload.uploadBg(bgReading); } @@ -268,7 +268,7 @@ public class DataService extends IntentService { bgReading.date = json_object.getLong("date"); bgReading.raw = json_object.getDouble("sgv"); - MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g", mm640gEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g"); break; default: log.debug("Unknown entries type: " + type); @@ -425,7 +425,7 @@ public class DataService extends IntentService { JSONObject sgvJson = new JSONObject(sgvstring); NSSgv nsSgv = new NSSgv(sgvJson); BgReading bgReading = new BgReading(nsSgv); - MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); } if (bundles.containsKey("sgvs")) { @@ -435,7 +435,7 @@ public class DataService extends IntentService { JSONObject sgvJson = jsonArray.getJSONObject(i); NSSgv nsSgv = new NSSgv(sgvJson); BgReading bgReading = new BgReading(nsSgv); - MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); } } } catch (Exception e) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 041f92ab84..68b506b37a 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -8,6 +8,7 @@ import android.support.annotation.Nullable; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.dao.CloseableIterator; import com.j256.ormlite.dao.Dao; +import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.Where; @@ -240,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(true); - scheduleBgChange(null, false, false); // trigger refresh + scheduleBgChange(null); // trigger refresh scheduleTemporaryBasalChange(); scheduleTreatmentChange(null); scheduleExtendedBolusChange(); @@ -366,14 +367,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } // ------------------- BgReading handling ----------------------- - public boolean createIfNotExists(BgReading bgReading, String from, boolean isFromActiveBgSource) { + public boolean createIfNotExists(BgReading bgReading, String from) { try { bgReading.date = roundDateToSec(bgReading.date); BgReading old = getDaoBgReadings().queryForId(bgReading.date); if (old == null) { getDaoBgReadings().create(bgReading); log.debug("BG: New record from: " + from + " " + bgReading.toString()); - scheduleBgChange(bgReading, true, isFromActiveBgSource); + scheduleBgChange(bgReading); return true; } if (!old.isEqual(bgReading)) { @@ -381,7 +382,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(bgReading); getDaoBgReadings().update(old); log.debug("BG: Updating record from: " + from + " New data: " + old.toString()); - scheduleBgChange(bgReading, false, isFromActiveBgSource); + scheduleBgChange(bgReading); return false; } } catch (SQLException e) { @@ -399,11 +400,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleBgChange(@Nullable final BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) { + private static void scheduleBgChange(@Nullable final BgReading bgReading) { class PostRunnable implements Runnable { public void run() { log.debug("Firing EventNewBg"); - MainApp.bus().post(new EventNewBG(bgReading, isNew, isFromActiveBgSource)); + MainApp.bus().post(new EventNewBG(bgReading)); scheduledBgPost = null; } } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java index e65c02a58c..dc4d434e0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java @@ -10,17 +10,8 @@ import info.nightscout.androidaps.db.BgReading; public class EventNewBG extends EventLoop { @Nullable public final BgReading bgReading; - public final boolean isNew; - public final boolean isFromActiveBgSource; - /** Whether the BgReading is current (enough to use for treatment decisions). */ - public boolean isCurrent() { - return bgReading != null && bgReading.date + 9 * 60 * 1000 > System.currentTimeMillis(); - } - - public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) { + public EventNewBG(BgReading bgReading) { this.bgReading = bgReading; - this.isNew = isNew; - this.isFromActiveBgSource = isFromActiveBgSource; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 19b8e492d6..c60991253c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -531,8 +531,6 @@ public class IobCobCalculatorPlugin implements PluginBase { @Subscribe public void onEventNewBG(EventNewBG ev) { - if (!ev.isFromActiveBgSource) - return; if (this != getPlugin()) { log.debug("Ignoring event for non default instance"); return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 5846140b1e..12db67534b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -23,7 +23,6 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.APSInterface; @@ -160,12 +159,8 @@ public class LoopPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventAutosensCalculationFinished ev) { - if (!(ev.cause instanceof EventNewBG)) - return; - - EventNewBG bgEv = (EventNewBG) ev.cause; - if (bgEv.isNew && bgEv.isFromActiveBgSource && bgEv.isCurrent()) { - invoke("New BG", true); + if (ev.cause instanceof EventNewBG) { + invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 0d59983796..56f2276327 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -142,16 +142,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com @Subscribe public void onStatusEvent(final EventNewBG e) { - if (e.isFromActiveBgSource && e.isNew && e.isCurrent()) { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - calculateInsulin(); - } - }); - } + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + calculateInsulin(); + } + }); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index a68864b9c8..26d5851865 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -255,8 +255,7 @@ public class PersistentNotificationPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent()) - updateNotification(); + updateNotification(); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index bc44c75911..5f11fc5fda 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -182,8 +182,7 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - if (ev.isFromActiveBgSource) - sendDataToWatch(true, true, true); + sendDataToWatch(true, true, true); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index f1fd58c3f9..76e8ac9e4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -235,8 +235,7 @@ public class StatuslinePlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent()) - sendStatus(); + sendStatus(); } @Subscribe