execute SMB
This commit is contained in:
parent
466ba2907b
commit
ec114c3b38
|
@ -30,6 +30,7 @@ public interface TreatmentsInterface {
|
||||||
|
|
||||||
List<Treatment> getTreatmentsFromHistory();
|
List<Treatment> getTreatmentsFromHistory();
|
||||||
List<Treatment> getTreatments5MinBackFromHistory(long time);
|
List<Treatment> getTreatments5MinBackFromHistory(long time);
|
||||||
|
long getLastSMBTime();
|
||||||
|
|
||||||
// real basals (not faked by extended bolus)
|
// real basals (not faked by extended bolus)
|
||||||
boolean isInHistoryRealTempBasalInProgress();
|
boolean isInHistoryRealTempBasalInProgress();
|
||||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.Intervals;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileIntervals;
|
import info.nightscout.androidaps.data.ProfileIntervals;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
|
@ -442,6 +443,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
bolusProgressDialog = new BolusProgressDialog();
|
bolusProgressDialog = new BolusProgressDialog();
|
||||||
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
||||||
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
||||||
|
} else if (detailedBolusInfo.isSMB) {
|
||||||
|
// do not show bolus progress dialog
|
||||||
} else {
|
} else {
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
i.putExtra("insulin", detailedBolusInfo.insulin);
|
i.putExtra("insulin", detailedBolusInfo.insulin);
|
||||||
|
@ -588,6 +591,23 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
log.debug("applyAPSRequest: setTempBasalAbsolute()");
|
log.debug("applyAPSRequest: setTempBasalAbsolute()");
|
||||||
result = setTempBasalAbsolute(request.rate, request.duration);
|
result = setTempBasalAbsolute(request.rate, request.duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.smb != 0) {
|
||||||
|
long lastSMBTime = getLastSMBTime();
|
||||||
|
if (lastSMBTime != 0 && lastSMBTime + 4.5 * 60 * 1000 > System.currentTimeMillis()) {
|
||||||
|
log.debug("SMS requsted but still in 5 min interval");
|
||||||
|
} else {
|
||||||
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
|
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||||
|
detailedBolusInfo.insulin = request.smb;
|
||||||
|
detailedBolusInfo.isSMB = true;
|
||||||
|
PumpEnactResult smbResult = deliverTreatment(detailedBolusInfo);
|
||||||
|
if (smbResult.success)
|
||||||
|
return result;
|
||||||
|
else
|
||||||
|
return smbResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,6 +817,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return activeTreatments.getTreatments5MinBackFromHistory(time);
|
return activeTreatments.getTreatments5MinBackFromHistory(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLastSMBTime() {
|
||||||
|
return activeTreatments.getLastSMBTime();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInHistoryRealTempBasalInProgress() {
|
public boolean isInHistoryRealTempBasalInProgress() {
|
||||||
return activeTreatments.isInHistoryRealTempBasalInProgress();
|
return activeTreatments.isInHistoryRealTempBasalInProgress();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.json.JSONObject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
|
@ -21,6 +22,10 @@ public class APSResult {
|
||||||
public double rate;
|
public double rate;
|
||||||
public int duration;
|
public int duration;
|
||||||
public boolean changeRequested = false;
|
public boolean changeRequested = false;
|
||||||
|
public IobTotal iob;
|
||||||
|
public double smb = 0d; // super micro bolus in units
|
||||||
|
public long deliverAt = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
||||||
|
@ -31,6 +36,7 @@ public class APSResult {
|
||||||
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%)\n" +
|
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%)\n" +
|
||||||
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
|
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
|
||||||
|
(smb != 0 ? ("SMB" + ": " + DecimalFormatter.to2Decimal(smb) + " U") : "") +
|
||||||
MainApp.sResources.getString(R.string.reason) + ": " + reason;
|
MainApp.sResources.getString(R.string.reason) + ": " + reason;
|
||||||
} else
|
} else
|
||||||
return MainApp.sResources.getString(R.string.nochangerequested);
|
return MainApp.sResources.getString(R.string.nochangerequested);
|
||||||
|
@ -45,6 +51,7 @@ public class APSResult {
|
||||||
ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%) <br>" +
|
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%) <br>" +
|
||||||
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
|
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
|
||||||
|
(smb != 0 ? ("<b>" + "SMB" + "</b>: " + DecimalFormatter.to2Decimal(smb) + " U") : "") +
|
||||||
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">");
|
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">");
|
||||||
return Html.fromHtml(ret);
|
return Html.fromHtml(ret);
|
||||||
} else
|
} else
|
||||||
|
@ -60,6 +67,7 @@ public class APSResult {
|
||||||
newResult.rate = rate;
|
newResult.rate = rate;
|
||||||
newResult.duration = duration;
|
newResult.duration = duration;
|
||||||
newResult.changeRequested = changeRequested;
|
newResult.changeRequested = changeRequested;
|
||||||
|
newResult.iob = iob;
|
||||||
return newResult;
|
return newResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,7 @@ public class LoopPlugin implements PluginBase {
|
||||||
// check rate for constrais
|
// check rate for constrais
|
||||||
final APSResult resultAfterConstraints = result.clone();
|
final APSResult resultAfterConstraints = result.clone();
|
||||||
resultAfterConstraints.rate = constraintsInterface.applyBasalConstraints(resultAfterConstraints.rate);
|
resultAfterConstraints.rate = constraintsInterface.applyBasalConstraints(resultAfterConstraints.rate);
|
||||||
|
resultAfterConstraints.smb = constraintsInterface.applyBolusConstraints(resultAfterConstraints.smb);
|
||||||
|
|
||||||
if (lastRun == null) lastRun = new LastRun();
|
if (lastRun == null) lastRun = new LastRun();
|
||||||
lastRun.request = result;
|
lastRun.request = result;
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class DetermineBasalResultAMA extends APSResult {
|
||||||
public JSONObject json = new JSONObject();
|
public JSONObject json = new JSONObject();
|
||||||
public double eventualBG;
|
public double eventualBG;
|
||||||
public double snoozeBG;
|
public double snoozeBG;
|
||||||
public IobTotal iob;
|
|
||||||
|
|
||||||
public DetermineBasalResultAMA(V8Object result, JSONObject j) {
|
public DetermineBasalResultAMA(V8Object result, JSONObject j) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
|
|
|
@ -17,7 +17,6 @@ public class DetermineBasalResultMA extends APSResult {
|
||||||
public double eventualBG;
|
public double eventualBG;
|
||||||
public double snoozeBG;
|
public double snoozeBG;
|
||||||
public String mealAssist;
|
public String mealAssist;
|
||||||
public IobTotal iob;
|
|
||||||
|
|
||||||
public DetermineBasalResultMA(V8Object result, JSONObject j) {
|
public DetermineBasalResultMA(V8Object result, JSONObject j) {
|
||||||
json = j;
|
json = j;
|
||||||
|
|
|
@ -20,9 +20,6 @@ public class DetermineBasalResultSMB extends APSResult {
|
||||||
public JSONObject json = new JSONObject();
|
public JSONObject json = new JSONObject();
|
||||||
public double eventualBG;
|
public double eventualBG;
|
||||||
public double snoozeBG;
|
public double snoozeBG;
|
||||||
public IobTotal iob;
|
|
||||||
public double smbValue;
|
|
||||||
public long deliverAt;
|
|
||||||
|
|
||||||
public DetermineBasalResultSMB(JSONObject result) {
|
public DetermineBasalResultSMB(JSONObject result) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
|
@ -54,9 +51,9 @@ public class DetermineBasalResultSMB extends APSResult {
|
||||||
}
|
}
|
||||||
if (result.has("units")) {
|
if (result.has("units")) {
|
||||||
changeRequested = true;
|
changeRequested = true;
|
||||||
smbValue = result.getDouble("units");
|
smb = result.getDouble("units");
|
||||||
} else {
|
} else {
|
||||||
smbValue = 0.0;
|
smb = 0d;
|
||||||
//changeRequested as above
|
//changeRequested as above
|
||||||
}
|
}
|
||||||
if (result.has("deliverAt")) {
|
if (result.has("deliverAt")) {
|
||||||
|
@ -85,7 +82,8 @@ public class DetermineBasalResultSMB extends APSResult {
|
||||||
newResult.changeRequested = changeRequested;
|
newResult.changeRequested = changeRequested;
|
||||||
newResult.rate = rate;
|
newResult.rate = rate;
|
||||||
newResult.duration = duration;
|
newResult.duration = duration;
|
||||||
newResult.smbValue = smbValue;
|
newResult.smb = smb;
|
||||||
|
newResult.deliverAt = deliverAt;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newResult.json = new JSONObject(json.toString());
|
newResult.json = new JSONObject(json.toString());
|
||||||
|
|
|
@ -268,6 +268,19 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
return in5minback;
|
return in5minback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLastSMBTime() {
|
||||||
|
long last = 0;
|
||||||
|
for (Integer pos = 0; pos < treatments.size(); pos++) {
|
||||||
|
Treatment t = treatments.get(pos);
|
||||||
|
if (!t.isValid)
|
||||||
|
continue;
|
||||||
|
if (t.isSMB && t.date > last)
|
||||||
|
last = t.date;
|
||||||
|
}
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInHistoryRealTempBasalInProgress() {
|
public boolean isInHistoryRealTempBasalInProgress() {
|
||||||
return getRealTempBasalFromHistory(System.currentTimeMillis()) != null;
|
return getRealTempBasalFromHistory(System.currentTimeMillis()) != null;
|
||||||
|
|
|
@ -193,17 +193,8 @@ public class NSUpload {
|
||||||
apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
|
apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
|
||||||
deviceStatus.suggested = apsResult.json();
|
deviceStatus.suggested = apsResult.json();
|
||||||
|
|
||||||
if (lastRun.request instanceof DetermineBasalResultMA) {
|
deviceStatus.iob = lastRun.request.iob.json();
|
||||||
DetermineBasalResultMA result = (DetermineBasalResultMA) lastRun.request;
|
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
|
||||||
deviceStatus.iob = result.iob.json();
|
|
||||||
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastRun.request instanceof DetermineBasalResultAMA) {
|
|
||||||
DetermineBasalResultAMA result = (DetermineBasalResultAMA) lastRun.request;
|
|
||||||
deviceStatus.iob = result.iob.json();
|
|
||||||
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastRun.setByPump != null && lastRun.setByPump.enacted) { // enacted
|
if (lastRun.setByPump != null && lastRun.setByPump.enacted) { // enacted
|
||||||
deviceStatus.enacted = lastRun.request.json();
|
deviceStatus.enacted = lastRun.request.json();
|
||||||
|
|
Loading…
Reference in a new issue