better display pump results

This commit is contained in:
Milos Kozak 2016-07-13 18:57:23 +02:00
parent 4a7987ef83
commit 4a8ecb3a79
3 changed files with 40 additions and 12 deletions

View file

@ -11,6 +11,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.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
public class PumpEnactResult extends Object implements Parcelable { public class PumpEnactResult extends Object implements Parcelable {
@ -28,8 +29,10 @@ public class PumpEnactResult extends Object implements Parcelable {
public Double bolusDelivered = 0d; // real value of delivered insulin public Double bolusDelivered = 0d; // real value of delivered insulin
public Integer carbsDelivered = 0; // real value of delivered carbs public Integer carbsDelivered = 0; // real value of delivered carbs
public boolean queued = false;
public String log() { public String log() {
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent; return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
} }
public String toString() { public String toString() {
@ -57,8 +60,10 @@ public class PumpEnactResult extends Object implements Parcelable {
} }
public Spanned toSpanned() { public Spanned toSpanned() {
String ret = "<b>" + MainApp.sResources.getString(R.string.success) + "</b>: " + success; String ret = MainApp.sResources.getString(R.string.success) + ": " + success;
if (enacted) { if (queued) {
ret = MainApp.sResources.getString(R.string.waitingforpumpresult);
} else if (enacted) {
if (isTempCancel) { if (isTempCancel) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted; ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment + ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment +
@ -72,7 +77,7 @@ public class PumpEnactResult extends Object implements Parcelable {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted; ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment; ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
ret += "<br><b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + duration + " min"; ret += "<br><b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + duration + " min";
ret += "<br><b>" + MainApp.sResources.getString(R.string.absolute) + "</b>: " + absolute + " U/h"; ret += "<br><b>" + MainApp.sResources.getString(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
} }
} else { } else {
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment; ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;

View file

@ -9,6 +9,8 @@ import android.app.TaskStackBuilder;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -51,6 +53,10 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
TextView constraintsProcessedView; TextView constraintsProcessedView;
TextView setByPumpView; TextView setByPumpView;
Handler mHandler;
public static HandlerThread mHandlerThread;
public class LastRun implements Parcelable { public class LastRun implements Parcelable {
public APSResult request = null; public APSResult request = null;
public APSResult constraintsProcessed = null; public APSResult constraintsProcessed = null;
@ -142,6 +148,9 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
public LoopFragment() { public LoopFragment() {
super(); super();
mHandlerThread = new HandlerThread(LoopFragment.class.getSimpleName());
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
registerBus(); registerBus();
} }
@ -226,7 +235,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
}); });
return; return;
} }
ConfigBuilderFragment configBuilder = MainApp.getConfigBuilder(); final ConfigBuilderFragment configBuilder = MainApp.getConfigBuilder();
APSResult result = null; APSResult result = null;
if (constraintsInterface == null || configBuilder == null || !isEnabled(PluginBase.GENERAL)) if (constraintsInterface == null || configBuilder == null || !isEnabled(PluginBase.GENERAL))
@ -262,7 +271,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
} }
// check rate for constrais // check rate for constrais
APSResult resultAfterConstraints = result.clone(); final APSResult resultAfterConstraints = result.clone();
resultAfterConstraints.rate = constraintsInterface.applyBasalConstraints(resultAfterConstraints.rate); resultAfterConstraints.rate = constraintsInterface.applyBasalConstraints(resultAfterConstraints.rate);
if (lastRun == null) lastRun = new LastRun(); if (lastRun == null) lastRun = new LastRun();
@ -274,11 +283,24 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
if (constraintsInterface.isClosedModeEnabled()) { if (constraintsInterface.isClosedModeEnabled()) {
if (result.changeRequested) { if (result.changeRequested) {
PumpEnactResult applyResult = configBuilder.applyAPSRequest(resultAfterConstraints); final PumpEnactResult waiting = new PumpEnactResult();
final PumpEnactResult previousResult = lastRun.setByPump;
waiting.queued = true;
lastRun.setByPump = waiting;
updateGUI();
mHandler.post(new Runnable() {
@Override
public void run() {
final PumpEnactResult applyResult = configBuilder.applyAPSRequest(resultAfterConstraints);
if (applyResult.enacted) { if (applyResult.enacted) {
lastRun.setByPump = applyResult; lastRun.setByPump = applyResult;
lastRun.lastEnact = lastRun.lastAPSRun; lastRun.lastEnact = lastRun.lastAPSRun;
} else {
lastRun.setByPump = previousResult;
} }
updateGUI();
}
});
} else { } else {
lastRun.setByPump = null; lastRun.setByPump = null;
lastRun.source = null; lastRun.source = null;

View file

@ -244,5 +244,6 @@
<string name="canceltemp">Cancel temp basal</string> <string name="canceltemp">Cancel temp basal</string>
<string name="smscommunicator">Sms Communicator</string> <string name="smscommunicator">Sms Communicator</string>
<string name="mm640g">MM 640g</string> <string name="mm640g">MM 640g</string>
<string name="waitingforpumpresult">Waiting for result</string>
</resources> </resources>