better display pump results
This commit is contained in:
parent
4a7987ef83
commit
4a8ecb3a79
|
@ -11,6 +11,7 @@ import org.json.JSONObject;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.Round;
|
||||
|
||||
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 Integer carbsDelivered = 0; // real value of delivered carbs
|
||||
|
||||
public String log() {
|
||||
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent;
|
||||
public boolean queued = false;
|
||||
|
||||
public String log() {
|
||||
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -57,8 +60,10 @@ public class PumpEnactResult extends Object implements Parcelable {
|
|||
}
|
||||
|
||||
public Spanned toSpanned() {
|
||||
String ret = "<b>" + MainApp.sResources.getString(R.string.success) + "</b>: " + success;
|
||||
if (enacted) {
|
||||
String ret = MainApp.sResources.getString(R.string.success) + ": " + success;
|
||||
if (queued) {
|
||||
ret = MainApp.sResources.getString(R.string.waitingforpumpresult);
|
||||
} else if (enacted) {
|
||||
if (isTempCancel) {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
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.comment) + "</b>: " + comment;
|
||||
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 {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
|
||||
|
|
|
@ -9,6 +9,8 @@ import android.app.TaskStackBuilder;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -51,6 +53,10 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
TextView constraintsProcessedView;
|
||||
TextView setByPumpView;
|
||||
|
||||
Handler mHandler;
|
||||
public static HandlerThread mHandlerThread;
|
||||
|
||||
|
||||
public class LastRun implements Parcelable {
|
||||
public APSResult request = null;
|
||||
public APSResult constraintsProcessed = null;
|
||||
|
@ -142,6 +148,9 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
|
||||
public LoopFragment() {
|
||||
super();
|
||||
mHandlerThread = new HandlerThread(LoopFragment.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
mHandler = new Handler(mHandlerThread.getLooper());
|
||||
registerBus();
|
||||
}
|
||||
|
||||
|
@ -226,7 +235,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
});
|
||||
return;
|
||||
}
|
||||
ConfigBuilderFragment configBuilder = MainApp.getConfigBuilder();
|
||||
final ConfigBuilderFragment configBuilder = MainApp.getConfigBuilder();
|
||||
APSResult result = null;
|
||||
|
||||
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
|
||||
APSResult resultAfterConstraints = result.clone();
|
||||
final APSResult resultAfterConstraints = result.clone();
|
||||
resultAfterConstraints.rate = constraintsInterface.applyBasalConstraints(resultAfterConstraints.rate);
|
||||
|
||||
if (lastRun == null) lastRun = new LastRun();
|
||||
|
@ -274,11 +283,24 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
|
||||
if (constraintsInterface.isClosedModeEnabled()) {
|
||||
if (result.changeRequested) {
|
||||
PumpEnactResult applyResult = configBuilder.applyAPSRequest(resultAfterConstraints);
|
||||
if (applyResult.enacted) {
|
||||
lastRun.setByPump = applyResult;
|
||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||
}
|
||||
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) {
|
||||
lastRun.setByPump = applyResult;
|
||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||
} else {
|
||||
lastRun.setByPump = previousResult;
|
||||
}
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
lastRun.setByPump = null;
|
||||
lastRun.source = null;
|
||||
|
|
|
@ -244,5 +244,6 @@
|
|||
<string name="canceltemp">Cancel temp basal</string>
|
||||
<string name="smscommunicator">Sms Communicator</string>
|
||||
<string name="mm640g">MM 640g</string>
|
||||
<string name="waitingforpumpresult">Waiting for result</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue