execute SMB

This commit is contained in:
Milos Kozak 2017-08-21 08:41:34 +02:00
parent 466ba2907b
commit ec114c3b38
9 changed files with 54 additions and 19 deletions

View file

@ -30,6 +30,7 @@ public interface TreatmentsInterface {
List<Treatment> getTreatmentsFromHistory();
List<Treatment> getTreatments5MinBackFromHistory(long time);
long getLastSMBTime();
// real basals (not faked by extended bolus)
boolean isInHistoryRealTempBasalInProgress();

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.Intervals;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileIntervals;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.TempTarget;
@ -442,6 +443,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
} else if (detailedBolusInfo.isSMB) {
// do not show bolus progress dialog
} else {
Intent i = new Intent();
i.putExtra("insulin", detailedBolusInfo.insulin);
@ -588,6 +591,23 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
log.debug("applyAPSRequest: setTempBasalAbsolute()");
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;
}
@ -797,6 +817,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return activeTreatments.getTreatments5MinBackFromHistory(time);
}
@Override
public long getLastSMBTime() {
return activeTreatments.getLastSMBTime();
}
@Override
public boolean isInHistoryRealTempBasalInProgress() {
return activeTreatments.isInHistoryRealTempBasalInProgress();

View file

@ -10,6 +10,7 @@ import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.DecimalFormatter;
@ -21,6 +22,10 @@ public class APSResult {
public double rate;
public int duration;
public boolean changeRequested = false;
public IobTotal iob;
public double smb = 0d; // super micro bolus in units
public long deliverAt = 0;
@Override
public String toString() {
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
@ -31,6 +36,7 @@ public class APSResult {
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%)\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;
} else
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 " +
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%) <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("<", "&lt;").replace(">", "&gt;");
return Html.fromHtml(ret);
} else
@ -60,6 +67,7 @@ public class APSResult {
newResult.rate = rate;
newResult.duration = duration;
newResult.changeRequested = changeRequested;
newResult.iob = iob;
return newResult;
}

View file

@ -260,6 +260,7 @@ public class LoopPlugin implements PluginBase {
// check rate for constrais
final APSResult resultAfterConstraints = result.clone();
resultAfterConstraints.rate = constraintsInterface.applyBasalConstraints(resultAfterConstraints.rate);
resultAfterConstraints.smb = constraintsInterface.applyBolusConstraints(resultAfterConstraints.smb);
if (lastRun == null) lastRun = new LastRun();
lastRun.request = result;

View file

@ -19,7 +19,6 @@ public class DetermineBasalResultAMA extends APSResult {
public JSONObject json = new JSONObject();
public double eventualBG;
public double snoozeBG;
public IobTotal iob;
public DetermineBasalResultAMA(V8Object result, JSONObject j) {
date = new Date();

View file

@ -17,7 +17,6 @@ public class DetermineBasalResultMA extends APSResult {
public double eventualBG;
public double snoozeBG;
public String mealAssist;
public IobTotal iob;
public DetermineBasalResultMA(V8Object result, JSONObject j) {
json = j;

View file

@ -20,9 +20,6 @@ public class DetermineBasalResultSMB extends APSResult {
public JSONObject json = new JSONObject();
public double eventualBG;
public double snoozeBG;
public IobTotal iob;
public double smbValue;
public long deliverAt;
public DetermineBasalResultSMB(JSONObject result) {
date = new Date();
@ -54,9 +51,9 @@ public class DetermineBasalResultSMB extends APSResult {
}
if (result.has("units")) {
changeRequested = true;
smbValue = result.getDouble("units");
smb = result.getDouble("units");
} else {
smbValue = 0.0;
smb = 0d;
//changeRequested as above
}
if (result.has("deliverAt")) {
@ -85,7 +82,8 @@ public class DetermineBasalResultSMB extends APSResult {
newResult.changeRequested = changeRequested;
newResult.rate = rate;
newResult.duration = duration;
newResult.smbValue = smbValue;
newResult.smb = smb;
newResult.deliverAt = deliverAt;
try {
newResult.json = new JSONObject(json.toString());

View file

@ -268,6 +268,19 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
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
public boolean isInHistoryRealTempBasalInProgress() {
return getRealTempBasalFromHistory(System.currentTimeMillis()) != null;

View file

@ -193,17 +193,8 @@ public class NSUpload {
apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
deviceStatus.suggested = apsResult.json();
if (lastRun.request instanceof DetermineBasalResultMA) {
DetermineBasalResultMA result = (DetermineBasalResultMA) lastRun.request;
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));
}
deviceStatus.iob = lastRun.request.iob.json();
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
if (lastRun.setByPump != null && lastRun.setByPump.enacted) { // enacted
deviceStatus.enacted = lastRun.request.json();