remove profile dependency from pump drivers, TRB optimalization
This commit is contained in:
parent
db7671cd23
commit
b6ce7c03c6
32 changed files with 183 additions and 171 deletions
|
@ -366,7 +366,7 @@ public class DataService extends IntentService {
|
|||
String activeProfile = bundles.getString("activeprofile");
|
||||
String profile = bundles.getString("profile");
|
||||
ProfileStore profileStore = new ProfileStore(new JSONObject(profile));
|
||||
NSProfilePlugin.storeNewProfile(profileStore);
|
||||
NSProfilePlugin.getPlugin().storeNewProfile(profileStore);
|
||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||
// if there are no profile switches this should lead to profile update
|
||||
if (MainApp.getConfigBuilder().getProfileSwitchesFromHistory().size() == 0)
|
||||
|
|
|
@ -154,7 +154,7 @@ public class PumpEnactResult extends Object {
|
|||
public PumpEnactResult() {
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
public JSONObject json(Profile profile) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
if (bolusDelivered > 0) {
|
||||
|
@ -164,7 +164,7 @@ public class PumpEnactResult extends Object {
|
|||
result.put("duration", 0);
|
||||
} else if (isPercent) {
|
||||
// Nightscout is expecting absolute value
|
||||
Double abs = Round.roundTo(MainApp.getConfigBuilder().getProfile().getBasal() * percent / 100, 0.01);
|
||||
Double abs = Round.roundTo(profile.getBasal() * percent / 100, 0.01);
|
||||
result.put("rate", abs);
|
||||
result.put("duration", duration);
|
||||
} else {
|
||||
|
|
|
@ -262,13 +262,13 @@ public class TemporaryBasal implements Interval {
|
|||
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
|
||||
}
|
||||
|
||||
public double tempBasalConvertedToAbsolute(long time) {
|
||||
public double tempBasalConvertedToAbsolute(long time, Profile profile) {
|
||||
if(isFakeExtended){
|
||||
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) + netExtendedRate;
|
||||
return profile.getBasal(time) + netExtendedRate;
|
||||
} else if (isAbsolute) {
|
||||
return absoluteRate;
|
||||
} else {
|
||||
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) * percentRate / 100;
|
||||
return profile.getBasal(time) * percentRate / 100;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public interface PumpInterface {
|
|||
PumpEnactResult cancelExtendedBolus();
|
||||
|
||||
// Status to be passed to NS
|
||||
JSONObject getJSONStatus();
|
||||
JSONObject getJSONStatus(Profile profile, String profileName);
|
||||
String deviceID();
|
||||
|
||||
// Pump capabilities
|
||||
|
|
|
@ -41,8 +41,6 @@ public interface TreatmentsInterface {
|
|||
// basal that can be faked by extended boluses
|
||||
boolean isTempBasalInProgress();
|
||||
TemporaryBasal getTempBasalFromHistory(long time);
|
||||
double getTempBasalAbsoluteRateHistory();
|
||||
double getTempBasalRemainingMinutesFromHistory();
|
||||
Intervals<TemporaryBasal> getTemporaryBasalsFromHistory();
|
||||
|
||||
boolean isInHistoryExtendedBoluslInProgress();
|
||||
|
|
|
@ -353,10 +353,12 @@ 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, Callback callback) {
|
||||
public void applyTBRRequest(APSResult request, Profile profile, Callback callback) {
|
||||
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) {
|
||||
|
@ -377,8 +379,9 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
|
|||
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 (isTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
if (Config.logCongigBuilderActions)
|
||||
log.debug("applyAPSRequest: cancelTempBasal()");
|
||||
getCommandQueue().cancelTempBasal(false, callback);
|
||||
|
@ -389,13 +392,13 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
|
|||
callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
|
||||
}
|
||||
}
|
||||
} else if (isTempBasalInProgress()
|
||||
&& getTempBasalRemainingMinutesFromHistory() > 5
|
||||
&& Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < pump.getPumpDescription().basalStep) {
|
||||
} 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(getTempBasalAbsoluteRateHistory()).duration(getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
|
||||
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)
|
||||
|
@ -644,16 +647,6 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
|
|||
return activeTreatments != null ? activeTreatments.getTempBasalFromHistory(time) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalAbsoluteRateHistory() {
|
||||
return activeTreatments.getTempBasalAbsoluteRateHistory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalRemainingMinutesFromHistory() {
|
||||
return activeTreatments.getTempBasalRemainingMinutesFromHistory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
||||
return activeTreatments.getTemporaryBasalsFromHistory();
|
||||
|
|
|
@ -389,11 +389,12 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
BasalData retval = basalDataTable.get(time);
|
||||
if (retval == null) {
|
||||
retval = new BasalData();
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile(time);
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time);
|
||||
retval.basal = MainApp.getConfigBuilder().getProfile(time).getBasal(time);
|
||||
retval.basal = profile.getBasal(time);
|
||||
if (tb != null) {
|
||||
retval.isTempBasalRunning = true;
|
||||
retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time);
|
||||
retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time, profile);
|
||||
} else {
|
||||
retval.isTempBasalRunning = false;
|
||||
retval.tempBasalAbsolute = retval.basal;
|
||||
|
|
|
@ -59,7 +59,7 @@ public class IobCobThread extends Thread {
|
|||
log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from);
|
||||
return; // app still initializing
|
||||
}
|
||||
if (MainApp.getConfigBuilder().getProfile() == null) {
|
||||
if (!MainApp.getConfigBuilder().isProfileValid("IobCobThread")) {
|
||||
log.debug("Aborting calculation thread (No profile): " + from);
|
||||
return; // app still initializing
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainActivity;
|
||||
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.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
|
@ -266,6 +267,8 @@ public class LoopPlugin implements PluginBase {
|
|||
if (!isEnabled(PluginBase.LOOP))
|
||||
return;
|
||||
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (!MainApp.getConfigBuilder().isProfileValid("Loop")) {
|
||||
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
|
||||
|
@ -328,7 +331,7 @@ public class LoopPlugin implements PluginBase {
|
|||
lastRun.tbrSetByPump = waiting;
|
||||
MainApp.bus().post(new EventLoopUpdateGui());
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("APSRequest"));
|
||||
MainApp.getConfigBuilder().applyTBRRequest(resultAfterConstraints, new Callback() {
|
||||
MainApp.getConfigBuilder().applyTBRRequest(resultAfterConstraints, profile, new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (result.enacted || result.success) {
|
||||
|
|
|
@ -217,12 +217,14 @@ public class DetermineBasalAdapterAMAJS {
|
|||
if (units.equals(Constants.MMOL)) {
|
||||
mProfile.put("out_units", "mmol/L");
|
||||
}
|
||||
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
|
||||
mCurrentTemp = new JSONObject();
|
||||
mCurrentTemp.put("temp", "absolute");
|
||||
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
||||
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
||||
mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
|
||||
mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
|
||||
|
||||
// as we have non default temps longer than 30 mintues
|
||||
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -248,11 +249,13 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
|||
determineBasalResultAMA.tempBasalReqested = false;
|
||||
// limit requests on openloop mode
|
||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {
|
||||
// going to cancel
|
||||
} else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) {
|
||||
} else if (activeTemp != null && Math.abs(determineBasalResultAMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
|
||||
determineBasalResultAMA.tempBasalReqested = false;
|
||||
} else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||
} else if (activeTemp == null && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||
determineBasalResultAMA.tempBasalReqested = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.data.GlucoseStatus;
|
|||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
@ -179,9 +180,12 @@ public class DetermineBasalAdapterMAJS {
|
|||
mProfile.put("out_units", "mmol/L");
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
|
||||
mCurrentTemp = new JSONObject();
|
||||
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
||||
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
||||
mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
|
||||
mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
|
||||
|
||||
mIobData = new JSONObject();
|
||||
mIobData.put("iob", iobData.iob); //netIob
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -173,8 +174,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
|||
|
||||
String units = profile.getUnits();
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
double maxIob = SP.getDouble("openapsma_max_iob", 1.5d);
|
||||
double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
|
||||
double minBg = Profile.toMgdl(profile.getTargetLow(), units);
|
||||
|
@ -231,17 +230,20 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
|||
Profiler.log(log, "MA calculation", start);
|
||||
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
|
||||
// Fix bug determinef basal
|
||||
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
|
||||
determineBasalResultMA.tempBasalReqested = false;
|
||||
// limit requests on openloop mode
|
||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) {
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) {
|
||||
// going to cancel
|
||||
} else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) {
|
||||
} else if (activeTemp != null && Math.abs(determineBasalResultMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
|
||||
determineBasalResultMA.tempBasalReqested = false;
|
||||
} else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||
} else if (activeTemp == null && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||
determineBasalResultMA.tempBasalReqested = false;
|
||||
}
|
||||
|
||||
|
@ -255,7 +257,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
|||
|
||||
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
|
||||
lastAPSResult = determineBasalResultMA;
|
||||
lastAPSRun = now;
|
||||
lastAPSRun = new Date(now);
|
||||
MainApp.bus().post(new EventOpenAPSUpdateGui());
|
||||
}
|
||||
|
||||
|
|
|
@ -264,10 +264,13 @@ public class DetermineBasalAdapterSMBJS {
|
|||
}
|
||||
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
|
||||
mCurrentTemp = new JSONObject();
|
||||
mCurrentTemp.put("temp", "absolute");
|
||||
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
||||
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
||||
mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
|
||||
mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
|
||||
|
||||
// as we have non default temps longer than 30 mintues
|
||||
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -243,6 +244,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
|
||||
Profiler.log(log, "SMB calculation", start);
|
||||
|
@ -252,17 +254,16 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
|||
determineBasalResultSMB.tempBasalReqested = false;
|
||||
// limit requests on openloop mode
|
||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) {
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) {
|
||||
// going to cancel
|
||||
} else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) {
|
||||
} else if (activeTemp != null && Math.abs(determineBasalResultSMB.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
|
||||
determineBasalResultSMB.tempBasalReqested = false;
|
||||
} else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - pump.getBaseBasalRate()) < 0.1) {
|
||||
} else if (activeTemp == null && Math.abs(determineBasalResultSMB.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||
determineBasalResultSMB.tempBasalReqested = false;
|
||||
}
|
||||
}
|
||||
|
||||
determineBasalResultSMB.iob = iobArray[0];
|
||||
Date now = new Date();
|
||||
|
||||
try {
|
||||
determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now));
|
||||
|
@ -272,7 +273,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
|||
|
||||
lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS;
|
||||
lastAPSResult = determineBasalResultSMB;
|
||||
lastAPSRun = now;
|
||||
lastAPSRun = new Date(now);
|
||||
MainApp.bus().post(new EventOpenAPSUpdateGui());
|
||||
|
||||
//deviceStatus.suggested = determineBasalResultAMA.json;
|
||||
|
|
|
@ -627,7 +627,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
private void onClickAcceptTemp() {
|
||||
if (ConfigBuilderPlugin.getActiveLoop() != null) {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (ConfigBuilderPlugin.getActiveLoop() != null && profile != null) {
|
||||
ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false);
|
||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) {
|
||||
|
@ -638,11 +640,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
public void onClick(DialogInterface dialog, int id) {
|
||||
hideTempRecommendation();
|
||||
clearNotification();
|
||||
MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed, new Callback() {
|
||||
MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (result.enacted) {
|
||||
finalLastRun.setByPump = result;
|
||||
finalLastRun.tbrSetByPump = result;
|
||||
finalLastRun.lastEnact = new Date();
|
||||
finalLastRun.lastOpenModeAccept = new Date();
|
||||
NSUpload.uploadDeviceStatus();
|
||||
|
@ -946,7 +948,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
if (timeView != null) { //must not exists
|
||||
timeView.setText(DateUtil.timeString(new Date()));
|
||||
}
|
||||
if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
|
||||
if (!MainApp.getConfigBuilder().isProfileValid("Overview")) {// app not initialized yet
|
||||
pumpStatusView.setText(R.string.noprofileset);
|
||||
pumpStatusLayout.setVisibility(View.VISIBLE);
|
||||
loopStatusLayout.setVisibility(View.GONE);
|
||||
|
|
|
@ -119,7 +119,7 @@ public class PersistentNotificationPlugin implements PluginBase {
|
|||
|
||||
String line1 = ctx.getString(R.string.noprofile);
|
||||
|
||||
if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || MainApp.getConfigBuilder().getProfile() == null)
|
||||
if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || !MainApp.getConfigBuilder().isProfileValid("Notificiation"))
|
||||
return;
|
||||
String units = MainApp.getConfigBuilder().getProfileUnits();
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
|||
private boolean fragmentEnabled = true;
|
||||
private boolean fragmentVisible = true;
|
||||
|
||||
private static ProfileStore profile = null;
|
||||
private ProfileStore profile = null;
|
||||
|
||||
private NSProfilePlugin() {
|
||||
MainApp.bus().register(this);
|
||||
|
@ -116,7 +116,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public static void storeNewProfile(ProfileStore newProfile) {
|
||||
public void storeNewProfile(ProfileStore newProfile) {
|
||||
profile = new ProfileStore(newProfile.getData());
|
||||
storeNSProfile();
|
||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||
|
@ -133,7 +133,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
|||
});
|
||||
}
|
||||
|
||||
private static void storeNSProfile() {
|
||||
private void storeNSProfile() {
|
||||
SP.putString("profile", profile.getData().toString());
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Storing profile");
|
||||
|
|
|
@ -228,7 +228,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
}
|
||||
if (percent > getPumpDescription().maxTempPercent)
|
||||
percent = getPumpDescription().maxTempPercent;
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
|
||||
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
|
@ -236,7 +237,6 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: Correct value already set");
|
||||
|
@ -251,7 +251,6 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
result.isTempCancel = false;
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
|
@ -365,7 +364,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
public JSONObject getJSONStatus(Profile profile, String profilename) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -383,13 +383,13 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
|
||||
extended.put("LastBolusAmount", pump.lastBolusAmount);
|
||||
}
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
|
||||
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
|
||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||
}
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
|
||||
if (eb != null) {
|
||||
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
||||
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
|
||||
|
@ -397,7 +397,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
}
|
||||
extended.put("BaseBasalRate", getBaseBasalRate());
|
||||
try {
|
||||
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
||||
extended.put("ActiveProfile", profilename);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
|
@ -178,15 +179,19 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
|
||||
final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
|
||||
ExtendedBolus activeExtended = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
|
||||
|
||||
if (doTempOff) {
|
||||
// If extended in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
if (activeExtended != null && useExtendedBoluses) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
|
||||
return cancelExtendedBolus();
|
||||
}
|
||||
// If temp in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
|
||||
return cancelRealTempBasal();
|
||||
|
@ -212,7 +217,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
|
||||
|
||||
// If extended in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
if (activeExtended != null && useExtendedBoluses) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
|
||||
result = cancelExtendedBolus();
|
||||
|
@ -222,20 +227,18 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
}
|
||||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
// Correct basal already set ?
|
||||
TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: currently running: " + running.toString());
|
||||
if (running.percentRate == percentRate) {
|
||||
log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
|
||||
if (activeTemp.percentRate == percentRate) {
|
||||
if (enforceNew) {
|
||||
cancelTempBasal(true);
|
||||
} else {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.enacted = false;
|
||||
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
if (Config.logPumpActions)
|
||||
|
@ -251,7 +254,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
if (doExtendedTemp) {
|
||||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
|
||||
result = cancelRealTempBasal();
|
||||
|
@ -272,12 +275,12 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
|
||||
// What is current rate of extended bolusing in u/h?
|
||||
if (Config.logPumpActions) {
|
||||
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
|
||||
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
|
||||
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
|
||||
}
|
||||
|
||||
// Compare with extended rate in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
if (activeExtended != null && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
// correct extended already set
|
||||
result.success = true;
|
||||
result.absolute = pump.extendedBolusAbsoluteRate;
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
|
@ -179,15 +180,19 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
|
||||
final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
|
||||
ExtendedBolus activeExtended = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
|
||||
|
||||
if (doTempOff) {
|
||||
// If extended in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
if (activeExtended != null && useExtendedBoluses) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
|
||||
return cancelExtendedBolus();
|
||||
}
|
||||
// If temp in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
|
||||
return cancelRealTempBasal();
|
||||
|
@ -213,7 +218,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
|
||||
|
||||
// If extended in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
if (activeExtended != null && useExtendedBoluses) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
|
||||
result = cancelExtendedBolus();
|
||||
|
@ -223,20 +228,18 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
}
|
||||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
// Correct basal already set ?
|
||||
TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: currently running: " + running.toString());
|
||||
if (running.percentRate == percentRate) {
|
||||
log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
|
||||
if (activeTemp.percentRate == percentRate) {
|
||||
if (enforceNew) {
|
||||
cancelTempBasal(true);
|
||||
} else {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.enacted = false;
|
||||
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
if (Config.logPumpActions)
|
||||
|
@ -252,7 +255,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
if (doExtendedTemp) {
|
||||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
if (activeTemp != null) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
|
||||
result = cancelRealTempBasal();
|
||||
|
@ -273,12 +276,12 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
|
||||
// What is current rate of extended bolusing in u/h?
|
||||
if (Config.logPumpActions) {
|
||||
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
|
||||
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
|
||||
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
|
||||
}
|
||||
|
||||
// Compare with extended rate in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
if (activeExtended != null && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
// correct extended already set
|
||||
result.success = true;
|
||||
result.absolute = pump.extendedBolusAbsoluteRate;
|
||||
|
|
|
@ -554,15 +554,17 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
if (percentRate > 500) // Special high temp 500/15min
|
||||
percentRate = 500;
|
||||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
|
||||
// Correct basal already set ?
|
||||
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
|
||||
if (activeTemp.percentRate == percentRate) {
|
||||
if (!enforceNew) {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.enacted = false;
|
||||
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
if (Config.logPumpActions)
|
||||
|
@ -606,7 +608,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
if (percent > getPumpDescription().maxTempPercent)
|
||||
percent = getPumpDescription().maxTempPercent;
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
|
@ -614,7 +617,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: Correct value already set");
|
||||
|
@ -634,7 +636,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isTempCancel = false;
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
|
@ -760,7 +761,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -778,13 +780,13 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
|
||||
extended.put("LastBolusAmount", pump.lastBolusAmount);
|
||||
}
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
|
||||
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
|
||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||
}
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
|
||||
if (eb != null) {
|
||||
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
||||
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
|
||||
|
@ -800,7 +802,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
pumpjson.put("status", status);
|
||||
pumpjson.put("extended", extended);
|
||||
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
|
||||
pumpjson.put("clock", DateUtil.toISOString(new Date()));
|
||||
pumpjson.put("clock", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -225,15 +225,15 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
if (percentRate > 500) // Special high temp 500/15min
|
||||
percentRate = 500;
|
||||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
// Correct basal already set ?
|
||||
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
|
||||
if (activeTemp.percentRate == percentRate) {
|
||||
if (!enforceNew) {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.enacted = false;
|
||||
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
if (Config.logPumpActions)
|
||||
|
@ -277,7 +277,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
if (percent > getPumpDescription().maxTempPercent)
|
||||
percent = getPumpDescription().maxTempPercent;
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
|
||||
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
|
@ -285,7 +286,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: Correct value already set");
|
||||
|
@ -305,7 +305,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
result.isTempCancel = false;
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
|
|
|
@ -790,8 +790,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
|||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
|
||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (Helpers.msSince(connector.getLastContactTime()) > (60 * 60 * 1000)) {
|
||||
log("getJSONStatus not returning as data likely stale");
|
||||
return null;
|
||||
|
@ -810,26 +810,26 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
|||
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
|
||||
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
|
||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||
}
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
|
||||
if (eb != null) {
|
||||
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
||||
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
|
||||
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
|
||||
}
|
||||
extended.put("BaseBasalRate", getBaseBasalRate());
|
||||
status.put("timestamp", DateUtil.toISOString(new Date()));
|
||||
status.put("timestamp", DateUtil.toISOString(now));
|
||||
|
||||
pump.put("battery", battery);
|
||||
pump.put("status", status);
|
||||
pump.put("extended", extended);
|
||||
pump.put("reservoir", reservoirInUnits);
|
||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||
pump.put("clock", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -244,7 +244,8 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||
long now = System.currentTimeMillis();
|
||||
JSONObject pump = new JSONObject();
|
||||
JSONObject status = new JSONObject();
|
||||
JSONObject extended = new JSONObject();
|
||||
|
@ -252,14 +253,14 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
|||
status.put("status", "normal");
|
||||
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||
try {
|
||||
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
||||
extended.put("ActiveProfile", profileName);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
status.put("timestamp", DateUtil.toISOString(new Date()));
|
||||
status.put("timestamp", DateUtil.toISOString(now));
|
||||
|
||||
pump.put("status", status);
|
||||
pump.put("extended", extended);
|
||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||
pump.put("clock", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
return pump;
|
||||
|
|
|
@ -409,7 +409,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -422,28 +423,28 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
status.put("status", "normal");
|
||||
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||
try {
|
||||
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
||||
extended.put("ActiveProfile", profileName);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
|
||||
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
|
||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||
}
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
|
||||
if (eb != null) {
|
||||
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
||||
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
|
||||
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
|
||||
}
|
||||
status.put("timestamp", DateUtil.toISOString(new Date()));
|
||||
status.put("timestamp", DateUtil.toISOString(now));
|
||||
|
||||
pump.put("battery", battery);
|
||||
pump.put("status", status);
|
||||
pump.put("extended", extended);
|
||||
pump.put("reservoir", reservoirInUnits);
|
||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||
pump.put("clock", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -124,6 +124,13 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
}
|
||||
|
||||
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
if (profile == null) {
|
||||
if (Config.logAutosensData)
|
||||
log.debug("No profile available");
|
||||
return new AutosensResult();
|
||||
}
|
||||
|
||||
String pastSensitivity = "";
|
||||
int index = 0;
|
||||
LongSparseArray<Double> data = new LongSparseArray<>();
|
||||
|
@ -181,8 +188,6 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
return new AutosensResult();
|
||||
}
|
||||
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
double sens = profile.getIsf();
|
||||
|
||||
String ratioLimit = "";
|
||||
|
|
|
@ -346,7 +346,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
if (!t.isEndingEvent()) {
|
||||
total.lastTempDate = t.date;
|
||||
total.lastTempDuration = t.durationInMinutes;
|
||||
total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date);
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
|
||||
total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date, profile);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -363,7 +364,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
if (!t.isEndingEvent() && t.date > total.lastTempDate) {
|
||||
total.lastTempDate = t.date;
|
||||
total.lastTempDuration = t.durationInMinutes;
|
||||
total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date);
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
|
||||
total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date, profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -410,34 +412,6 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
return extendedBoluses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalAbsoluteRateHistory() {
|
||||
TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (tb != null) {
|
||||
if (tb.isFakeExtended) {
|
||||
double baseRate = ConfigBuilderPlugin.getActivePump().getBaseBasalRate();
|
||||
double tempRate = baseRate + tb.netExtendedRate;
|
||||
return tempRate;
|
||||
} else if (tb.isAbsolute) {
|
||||
return tb.absoluteRate;
|
||||
} else {
|
||||
double baseRate = ConfigBuilderPlugin.getActivePump().getBaseBasalRate();
|
||||
double tempRate = baseRate * (tb.percentRate / 100d);
|
||||
return tempRate;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalRemainingMinutesFromHistory() {
|
||||
TemporaryBasal activeTemp = getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
return activeTemp.getPlannedRemainingMinutes();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
||||
return tempBasals;
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
|
@ -86,7 +87,8 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
|
|||
}
|
||||
holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.durationInMinutes) + " min");
|
||||
if (tempBasal.isAbsolute) {
|
||||
holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date)) + " U/h");
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile(tempBasal.date);
|
||||
holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile)) + " U/h");
|
||||
holder.percent.setText("");
|
||||
} else {
|
||||
holder.absolute.setText("");
|
||||
|
|
|
@ -388,13 +388,14 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
if (tb1 != null) {
|
||||
tb_before = beginBasalValue;
|
||||
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime);
|
||||
Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
|
||||
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB);
|
||||
tb_start = runningTime;
|
||||
}
|
||||
|
||||
|
||||
for (; runningTime < now; runningTime += 5 * 60 * 1000) {
|
||||
|
||||
Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
|
||||
//basal rate
|
||||
endBasalValue = profile.getBasal(runningTime);
|
||||
if (endBasalValue != beginBasalValue) {
|
||||
|
@ -422,10 +423,10 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
tb1 = tb2;
|
||||
tb_start = runningTime;
|
||||
tb_before = endBasalValue;
|
||||
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime);
|
||||
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB);
|
||||
|
||||
} else if (tb1 != null && tb2 != null) {
|
||||
double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime);
|
||||
double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime, profileTB);
|
||||
if (currentAmount != tb_amount) {
|
||||
temps.add(tempDatamap(tb_start, tb_before, runningTime, currentAmount, tb_amount));
|
||||
tb_start = runningTime;
|
||||
|
@ -446,7 +447,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount));
|
||||
} else {
|
||||
//express currently running temp by painting it a bit into the future
|
||||
double currentAmount = tb2.tempBasalConvertedToAbsolute(now);
|
||||
Profile profileNow = MainApp.getConfigBuilder().getProfile(now);
|
||||
double currentAmount = tb2.tempBasalConvertedToAbsolute(now, profileNow);
|
||||
if (currentAmount != tb_amount) {
|
||||
temps.add(tempDatamap(tb_start, tb_before, now, tb_amount, tb_amount));
|
||||
temps.add(tempDatamap(now, tb_amount, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
|
||||
|
@ -458,7 +460,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(now); //use "now" to express current situation
|
||||
if (tb2 != null) {
|
||||
//onset at the end
|
||||
double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime);
|
||||
Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
|
||||
double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime, profileTB);
|
||||
temps.add(tempDatamap(now - 1 * 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
|
|
@ -188,6 +188,14 @@ public class NSUpload {
|
|||
}
|
||||
|
||||
public static void uploadDeviceStatus() {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
String profileName = MainApp.getConfigBuilder().getProfileName();
|
||||
|
||||
if (profile == null || profileName == null) {
|
||||
log.error("Profile is null. Skipping upload");
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceStatus deviceStatus = new DeviceStatus();
|
||||
try {
|
||||
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
|
||||
|
@ -204,8 +212,8 @@ public class NSUpload {
|
|||
|
||||
if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted
|
||||
deviceStatus.enacted = lastRun.request.json();
|
||||
deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json().get("rate"));
|
||||
deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json().get("duration"));
|
||||
deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json(profile).get("rate"));
|
||||
deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json(profile).get("duration"));
|
||||
deviceStatus.enacted.put("recieved", true);
|
||||
requested.put("duration", lastRun.request.duration);
|
||||
requested.put("rate", lastRun.request.rate);
|
||||
|
@ -224,7 +232,7 @@ public class NSUpload {
|
|||
log.debug("OpenAPS data too old to upload");
|
||||
}
|
||||
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
||||
JSONObject pumpstatus = ConfigBuilderPlugin.getActivePump().getJSONStatus();
|
||||
JSONObject pumpstatus = ConfigBuilderPlugin.getActivePump().getJSONStatus(profile, profileName);
|
||||
if (pumpstatus != null) {
|
||||
deviceStatus.pump = pumpstatus;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue