remove profile dependency from pump drivers, TRB optimalization

This commit is contained in:
Milos Kozak 2018-03-16 16:53:38 +01:00
parent db7671cd23
commit b6ce7c03c6
32 changed files with 183 additions and 171 deletions

View file

@ -366,7 +366,7 @@ public class DataService extends IntentService {
String activeProfile = bundles.getString("activeprofile"); String activeProfile = bundles.getString("activeprofile");
String profile = bundles.getString("profile"); String profile = bundles.getString("profile");
ProfileStore profileStore = new ProfileStore(new JSONObject(profile)); ProfileStore profileStore = new ProfileStore(new JSONObject(profile));
NSProfilePlugin.storeNewProfile(profileStore); NSProfilePlugin.getPlugin().storeNewProfile(profileStore);
MainApp.bus().post(new EventNSProfileUpdateGUI()); MainApp.bus().post(new EventNSProfileUpdateGUI());
// if there are no profile switches this should lead to profile update // if there are no profile switches this should lead to profile update
if (MainApp.getConfigBuilder().getProfileSwitchesFromHistory().size() == 0) if (MainApp.getConfigBuilder().getProfileSwitchesFromHistory().size() == 0)

View file

@ -154,7 +154,7 @@ public class PumpEnactResult extends Object {
public PumpEnactResult() { public PumpEnactResult() {
} }
public JSONObject json() { public JSONObject json(Profile profile) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
try { try {
if (bolusDelivered > 0) { if (bolusDelivered > 0) {
@ -164,7 +164,7 @@ public class PumpEnactResult extends Object {
result.put("duration", 0); result.put("duration", 0);
} else if (isPercent) { } else if (isPercent) {
// Nightscout is expecting absolute value // 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("rate", abs);
result.put("duration", duration); result.put("duration", duration);
} else { } else {

View file

@ -262,13 +262,13 @@ public class TemporaryBasal implements Interval {
return (remainingMin < 0) ? 0 : Math.round(remainingMin); return (remainingMin < 0) ? 0 : Math.round(remainingMin);
} }
public double tempBasalConvertedToAbsolute(long time) { public double tempBasalConvertedToAbsolute(long time, Profile profile) {
if(isFakeExtended){ if(isFakeExtended){
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) + netExtendedRate; return profile.getBasal(time) + netExtendedRate;
} else if (isAbsolute) { } else if (isAbsolute) {
return absoluteRate; return absoluteRate;
} else { } else {
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) * percentRate / 100; return profile.getBasal(time) * percentRate / 100;
} }
} }

View file

@ -44,7 +44,7 @@ public interface PumpInterface {
PumpEnactResult cancelExtendedBolus(); PumpEnactResult cancelExtendedBolus();
// Status to be passed to NS // Status to be passed to NS
JSONObject getJSONStatus(); JSONObject getJSONStatus(Profile profile, String profileName);
String deviceID(); String deviceID();
// Pump capabilities // Pump capabilities

View file

@ -41,8 +41,6 @@ public interface TreatmentsInterface {
// basal that can be faked by extended boluses // basal that can be faked by extended boluses
boolean isTempBasalInProgress(); boolean isTempBasalInProgress();
TemporaryBasal getTempBasalFromHistory(long time); TemporaryBasal getTempBasalFromHistory(long time);
double getTempBasalAbsoluteRateHistory();
double getTempBasalRemainingMinutesFromHistory();
Intervals<TemporaryBasal> getTemporaryBasalsFromHistory(); Intervals<TemporaryBasal> getTemporaryBasalsFromHistory();
boolean isInHistoryExtendedBoluslInProgress(); boolean isInHistoryExtendedBoluslInProgress();

View file

@ -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 * 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(); PumpInterface pump = getActivePump();
request.rate = applyBasalConstraints(request.rate); request.rate = applyBasalConstraints(request.rate);
long now = System.currentTimeMillis();
if (!pump.isInitialized()) { if (!pump.isInitialized()) {
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized)); log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
if (callback != null) { if (callback != null) {
@ -377,8 +379,9 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
log.debug("applyAPSRequest: " + request.toString()); log.debug("applyAPSRequest: " + request.toString());
if (request.tempBasalReqested) { if (request.tempBasalReqested) {
TemporaryBasal activeTemp = getTempBasalFromHistory(now);
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) { if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) {
if (isTempBasalInProgress()) { if (activeTemp != null) {
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: cancelTempBasal()"); log.debug("applyAPSRequest: cancelTempBasal()");
getCommandQueue().cancelTempBasal(false, callback); 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(); callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
} }
} }
} else if (isTempBasalInProgress() } else if (activeTemp != null
&& getTempBasalRemainingMinutesFromHistory() > 5 && activeTemp.getPlannedRemainingMinutes() > 5
&& Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < pump.getPumpDescription().basalStep) { && Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) {
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: Temp basal set correctly"); log.debug("applyAPSRequest: Temp basal set correctly");
if (callback != null) { 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 { } else {
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
@ -644,16 +647,6 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
return activeTreatments != null ? activeTreatments.getTempBasalFromHistory(time) : null; return activeTreatments != null ? activeTreatments.getTempBasalFromHistory(time) : null;
} }
@Override
public double getTempBasalAbsoluteRateHistory() {
return activeTreatments.getTempBasalAbsoluteRateHistory();
}
@Override
public double getTempBasalRemainingMinutesFromHistory() {
return activeTreatments.getTempBasalRemainingMinutesFromHistory();
}
@Override @Override
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() { public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
return activeTreatments.getTemporaryBasalsFromHistory(); return activeTreatments.getTemporaryBasalsFromHistory();

View file

@ -389,11 +389,12 @@ public class IobCobCalculatorPlugin implements PluginBase {
BasalData retval = basalDataTable.get(time); BasalData retval = basalDataTable.get(time);
if (retval == null) { if (retval == null) {
retval = new BasalData(); retval = new BasalData();
Profile profile = MainApp.getConfigBuilder().getProfile(time);
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time); TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time);
retval.basal = MainApp.getConfigBuilder().getProfile(time).getBasal(time); retval.basal = profile.getBasal(time);
if (tb != null) { if (tb != null) {
retval.isTempBasalRunning = true; retval.isTempBasalRunning = true;
retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time); retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time, profile);
} else { } else {
retval.isTempBasalRunning = false; retval.isTempBasalRunning = false;
retval.tempBasalAbsolute = retval.basal; retval.tempBasalAbsolute = retval.basal;

View file

@ -59,7 +59,7 @@ public class IobCobThread extends Thread {
log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from); log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from);
return; // app still initializing return; // app still initializing
} }
if (MainApp.getConfigBuilder().getProfile() == null) { if (!MainApp.getConfigBuilder().isProfileValid("IobCobThread")) {
log.debug("Aborting calculation thread (No profile): " + from); log.debug("Aborting calculation thread (No profile): " + from);
return; // app still initializing return; // app still initializing
} }

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainActivity;
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.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
@ -266,6 +267,8 @@ public class LoopPlugin implements PluginBase {
if (!isEnabled(PluginBase.LOOP)) if (!isEnabled(PluginBase.LOOP))
return; return;
Profile profile = MainApp.getConfigBuilder().getProfile();
if (!MainApp.getConfigBuilder().isProfileValid("Loop")) { if (!MainApp.getConfigBuilder().isProfileValid("Loop")) {
log.debug(MainApp.sResources.getString(R.string.noprofileselected)); log.debug(MainApp.sResources.getString(R.string.noprofileselected));
MainApp.bus().post(new EventLoopSetLastRunGui(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; lastRun.tbrSetByPump = waiting;
MainApp.bus().post(new EventLoopUpdateGui()); MainApp.bus().post(new EventLoopUpdateGui());
FabricPrivacy.getInstance().logCustom(new CustomEvent("APSRequest")); FabricPrivacy.getInstance().logCustom(new CustomEvent("APSRequest"));
MainApp.getConfigBuilder().applyTBRRequest(resultAfterConstraints, new Callback() { MainApp.getConfigBuilder().applyTBRRequest(resultAfterConstraints, profile, new Callback() {
@Override @Override
public void run() { public void run() {
if (result.enacted || result.success) { if (result.enacted || result.success) {

View file

@ -217,12 +217,14 @@ public class DetermineBasalAdapterAMAJS {
if (units.equals(Constants.MMOL)) { if (units.equals(Constants.MMOL)) {
mProfile.put("out_units", "mmol/L"); mProfile.put("out_units", "mmol/L");
} }
long now = System.currentTimeMillis();
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
mCurrentTemp = new JSONObject(); mCurrentTemp = new JSONObject();
mCurrentTemp.put("temp", "absolute"); mCurrentTemp.put("temp", "absolute");
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()); mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()); mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
// as we have non default temps longer than 30 mintues // as we have non default temps longer than 30 mintues
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
@ -248,11 +249,13 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
determineBasalResultAMA.tempBasalReqested = false; determineBasalResultAMA.tempBasalReqested = false;
// limit requests on openloop mode // limit requests on openloop mode
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { 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 // 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; 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; determineBasalResultAMA.tempBasalReqested = false;
} }

View file

@ -23,6 +23,7 @@ import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -179,9 +180,12 @@ public class DetermineBasalAdapterMAJS {
mProfile.put("out_units", "mmol/L"); mProfile.put("out_units", "mmol/L");
} }
long now = System.currentTimeMillis();
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
mCurrentTemp = new JSONObject(); mCurrentTemp = new JSONObject();
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()); mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()); mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
mIobData = new JSONObject(); mIobData = new JSONObject();
mIobData.put("iob", iobData.iob); //netIob mIobData.put("iob", iobData.iob); //netIob

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
@ -173,8 +174,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
String units = profile.getUnits(); String units = profile.getUnits();
Date now = new Date();
double maxIob = SP.getDouble("openapsma_max_iob", 1.5d); double maxIob = SP.getDouble("openapsma_max_iob", 1.5d);
double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1")); double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
double minBg = Profile.toMgdl(profile.getTargetLow(), units); double minBg = Profile.toMgdl(profile.getTargetLow(), units);
@ -231,17 +230,20 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
Profiler.log(log, "MA calculation", start); Profiler.log(log, "MA calculation", start);
long now = System.currentTimeMillis();
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke(); DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
// Fix bug determinef basal // Fix bug determinef basal
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultMA.tempBasalReqested = false; determineBasalResultMA.tempBasalReqested = false;
// limit requests on openloop mode // limit requests on openloop mode
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { 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 // 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; 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; determineBasalResultMA.tempBasalReqested = false;
} }
@ -255,7 +257,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS; lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
lastAPSResult = determineBasalResultMA; lastAPSResult = determineBasalResultMA;
lastAPSRun = now; lastAPSRun = new Date(now);
MainApp.bus().post(new EventOpenAPSUpdateGui()); MainApp.bus().post(new EventOpenAPSUpdateGui());
} }

View file

@ -264,10 +264,13 @@ public class DetermineBasalAdapterSMBJS {
} }
long now = System.currentTimeMillis();
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
mCurrentTemp = new JSONObject(); mCurrentTemp = new JSONObject();
mCurrentTemp.put("temp", "absolute"); mCurrentTemp.put("temp", "absolute");
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()); mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()); mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
// as we have non default temps longer than 30 mintues // as we have non default temps longer than 30 mintues
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
@ -243,6 +244,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
return; return;
} }
long now = System.currentTimeMillis();
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke(); DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
Profiler.log(log, "SMB calculation", start); Profiler.log(log, "SMB calculation", start);
@ -252,17 +254,16 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
determineBasalResultSMB.tempBasalReqested = false; determineBasalResultSMB.tempBasalReqested = false;
// limit requests on openloop mode // limit requests on openloop mode
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { 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 // 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; 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.tempBasalReqested = false;
}
} }
determineBasalResultSMB.iob = iobArray[0]; determineBasalResultSMB.iob = iobArray[0];
Date now = new Date();
try { try {
determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now)); determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now));
@ -272,7 +273,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS; lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS;
lastAPSResult = determineBasalResultSMB; lastAPSResult = determineBasalResultSMB;
lastAPSRun = now; lastAPSRun = new Date(now);
MainApp.bus().post(new EventOpenAPSUpdateGui()); MainApp.bus().post(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json; //deviceStatus.suggested = determineBasalResultAMA.json;

View file

@ -627,7 +627,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
private void onClickAcceptTemp() { 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); ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false);
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) { 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) { public void onClick(DialogInterface dialog, int id) {
hideTempRecommendation(); hideTempRecommendation();
clearNotification(); clearNotification();
MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed, new Callback() { MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
@Override @Override
public void run() { public void run() {
if (result.enacted) { if (result.enacted) {
finalLastRun.setByPump = result; finalLastRun.tbrSetByPump = result;
finalLastRun.lastEnact = new Date(); finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date(); finalLastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus(); NSUpload.uploadDeviceStatus();
@ -946,7 +948,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (timeView != null) { //must not exists if (timeView != null) { //must not exists
timeView.setText(DateUtil.timeString(new Date())); 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); pumpStatusView.setText(R.string.noprofileset);
pumpStatusLayout.setVisibility(View.VISIBLE); pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE); loopStatusLayout.setVisibility(View.GONE);

View file

@ -119,7 +119,7 @@ public class PersistentNotificationPlugin implements PluginBase {
String line1 = ctx.getString(R.string.noprofile); 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; return;
String units = MainApp.getConfigBuilder().getProfileUnits(); String units = MainApp.getConfigBuilder().getProfileUnits();

View file

@ -46,7 +46,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
private boolean fragmentEnabled = true; private boolean fragmentEnabled = true;
private boolean fragmentVisible = true; private boolean fragmentVisible = true;
private static ProfileStore profile = null; private ProfileStore profile = null;
private NSProfilePlugin() { private NSProfilePlugin() {
MainApp.bus().register(this); MainApp.bus().register(this);
@ -116,7 +116,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
} }
@Subscribe @Subscribe
public static void storeNewProfile(ProfileStore newProfile) { public void storeNewProfile(ProfileStore newProfile) {
profile = new ProfileStore(newProfile.getData()); profile = new ProfileStore(newProfile.getData());
storeNSProfile(); storeNSProfile();
MainApp.bus().post(new EventNSProfileUpdateGUI()); 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()); SP.putString("profile", profile.getData().toString());
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Storing profile"); log.debug("Storing profile");

View file

@ -228,7 +228,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
} }
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
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) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
@ -236,7 +237,6 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
@ -251,7 +251,6 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
result.isTempCancel = false; result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK"); log.debug("setTempBasalPercent: OK");
@ -365,7 +364,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
} }
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus(Profile profile, String profilename) {
long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) { if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null; return null;
} }
@ -383,13 +383,13 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount); extended.put("LastBolusAmount", pump.lastBolusAmount);
} }
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
if (tb != null) { 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("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
} }
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) { if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
@ -397,7 +397,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
} }
extended.put("BaseBasalRate", getBaseBasalRate()); extended.put("BaseBasalRate", getBaseBasalRate());
try { try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); extended.put("ActiveProfile", profilename);
} catch (Exception e) { } catch (Exception e) {
} }

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
@ -178,15 +179,19 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses; final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
final boolean doExtendedTemp = 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 (doTempOff) {
// If extended in progress // If extended in progress
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
return cancelExtendedBolus(); return cancelExtendedBolus();
} }
// If temp in progress // If temp in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (activeTemp != null) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelRealTempBasal(); return cancelRealTempBasal();
@ -212,7 +217,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate); log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
// If extended in progress // If extended in progress
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
result = cancelExtendedBolus(); result = cancelExtendedBolus();
@ -222,20 +227,18 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
} }
} }
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (activeTemp != null) {
// Correct basal already set ? // Correct basal already set ?
TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: currently running: " + running.toString()); log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
if (running.percentRate == percentRate) { if (activeTemp.percentRate == percentRate) {
if (enforceNew) { if (enforceNew) {
cancelTempBasal(true); cancelTempBasal(true);
} else { } else {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false; result.enacted = false;
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue(); result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true; result.isPercent = true;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
@ -251,7 +254,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (activeTemp != null) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
result = cancelRealTempBasal(); result = cancelRealTempBasal();
@ -272,12 +275,12 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) { 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"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
} }
// Compare with extended rate in progress // 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 // correct extended already set
result.success = true; result.success = true;
result.absolute = pump.extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
@ -179,15 +180,19 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses; final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
final boolean doExtendedTemp = 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 (doTempOff) {
// If extended in progress // If extended in progress
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
return cancelExtendedBolus(); return cancelExtendedBolus();
} }
// If temp in progress // If temp in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (activeTemp != null) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelRealTempBasal(); return cancelRealTempBasal();
@ -213,7 +218,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate); log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
// If extended in progress // If extended in progress
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
result = cancelExtendedBolus(); result = cancelExtendedBolus();
@ -223,20 +228,18 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
} }
} }
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (activeTemp != null) {
// Correct basal already set ? // Correct basal already set ?
TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: currently running: " + running.toString()); log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
if (running.percentRate == percentRate) { if (activeTemp.percentRate == percentRate) {
if (enforceNew) { if (enforceNew) {
cancelTempBasal(true); cancelTempBasal(true);
} else { } else {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false; result.enacted = false;
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue(); result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true; result.isPercent = true;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
@ -252,7 +255,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (activeTemp != null) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
result = cancelRealTempBasal(); result = cancelRealTempBasal();
@ -273,12 +276,12 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) { 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"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
} }
// Compare with extended rate in progress // 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 // correct extended already set
result.success = true; result.success = true;
result.absolute = pump.extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;

View file

@ -554,15 +554,17 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
if (percentRate > 500) // Special high temp 500/15min if (percentRate > 500) // Special high temp 500/15min
percentRate = 500; percentRate = 500;
// Check if some temp is already in progress // 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 ? // Correct basal already set ?
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) { if (activeTemp.percentRate == percentRate) {
if (!enforceNew) { if (!enforceNew) {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false; result.enacted = false;
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue(); result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true; result.isPercent = true;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
@ -606,7 +608,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
} }
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
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) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
@ -614,7 +617,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
@ -634,7 +636,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
result.isTempCancel = false; result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK"); log.debug("setTempBasalPercent: OK");
@ -760,7 +761,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
} }
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus(Profile profile, String profileName) {
long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) { if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null; return null;
} }
@ -778,13 +780,13 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount); extended.put("LastBolusAmount", pump.lastBolusAmount);
} }
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (tb != null) { 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("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
} }
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) { if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
@ -800,7 +802,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
pumpjson.put("status", status); pumpjson.put("status", status);
pumpjson.put("extended", extended); pumpjson.put("extended", extended);
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
pumpjson.put("clock", DateUtil.toISOString(new Date())); pumpjson.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }

View file

@ -225,15 +225,15 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (percentRate > 500) // Special high temp 500/15min if (percentRate > 500) // Special high temp 500/15min
percentRate = 500; percentRate = 500;
// Check if some temp is already in progress // 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 ? // Correct basal already set ?
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) { if (activeTemp.percentRate == percentRate) {
if (!enforceNew) { if (!enforceNew) {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false; result.enacted = false;
result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue(); result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true; result.isPercent = true;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
@ -277,7 +277,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
} }
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
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) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
@ -285,7 +286,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
@ -305,7 +305,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.isTempCancel = false; result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK"); log.debug("setTempBasalPercent: OK");

View file

@ -790,8 +790,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
} }
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus(Profile profile, String profileName) {
long now = System.currentTimeMillis();
if (Helpers.msSince(connector.getLastContactTime()) > (60 * 60 * 1000)) { if (Helpers.msSince(connector.getLastContactTime()) > (60 * 60 * 1000)) {
log("getJSONStatus not returning as data likely stale"); log("getJSONStatus not returning as data likely stale");
return null; return null;
@ -810,26 +810,26 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
} catch (Exception e) { } catch (Exception e) {
} }
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (tb != null) { 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("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
} }
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) { if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
} }
extended.put("BaseBasalRate", getBaseBasalRate()); extended.put("BaseBasalRate", getBaseBasalRate());
status.put("timestamp", DateUtil.toISOString(new Date())); status.put("timestamp", DateUtil.toISOString(now));
pump.put("battery", battery); pump.put("battery", battery);
pump.put("status", status); pump.put("status", status);
pump.put("extended", extended); pump.put("extended", extended);
pump.put("reservoir", reservoirInUnits); pump.put("reservoir", reservoirInUnits);
pump.put("clock", DateUtil.toISOString(new Date())); pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }

View file

@ -244,7 +244,8 @@ public class MDIPlugin implements PluginBase, PumpInterface {
} }
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus(Profile profile, String profileName) {
long now = System.currentTimeMillis();
JSONObject pump = new JSONObject(); JSONObject pump = new JSONObject();
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
JSONObject extended = new JSONObject(); JSONObject extended = new JSONObject();
@ -252,14 +253,14 @@ public class MDIPlugin implements PluginBase, PumpInterface {
status.put("status", "normal"); status.put("status", "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try { try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); extended.put("ActiveProfile", profileName);
} catch (Exception e) { } catch (Exception e) {
} }
status.put("timestamp", DateUtil.toISOString(new Date())); status.put("timestamp", DateUtil.toISOString(now));
pump.put("status", status); pump.put("status", status);
pump.put("extended", extended); pump.put("extended", extended);
pump.put("clock", DateUtil.toISOString(new Date())); pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
} }
return pump; return pump;

View file

@ -409,7 +409,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
} }
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus(Profile profile, String profileName) {
long now = System.currentTimeMillis();
if (!SP.getBoolean("virtualpump_uploadstatus", false)) { if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
return null; return null;
} }
@ -422,28 +423,28 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
status.put("status", "normal"); status.put("status", "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try { try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); extended.put("ActiveProfile", profileName);
} catch (Exception e) { } catch (Exception e) {
} }
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (tb != null) { 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("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
} }
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) { if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
} }
status.put("timestamp", DateUtil.toISOString(new Date())); status.put("timestamp", DateUtil.toISOString(now));
pump.put("battery", battery); pump.put("battery", battery);
pump.put("status", status); pump.put("status", status);
pump.put("extended", extended); pump.put("extended", extended);
pump.put("reservoir", reservoirInUnits); pump.put("reservoir", reservoirInUnits);
pump.put("clock", DateUtil.toISOString(new Date())); pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }

View file

@ -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 = ""; String pastSensitivity = "";
int index = 0; int index = 0;
LongSparseArray<Double> data = new LongSparseArray<>(); LongSparseArray<Double> data = new LongSparseArray<>();
@ -181,8 +188,6 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
return new AutosensResult(); return new AutosensResult();
} }
Profile profile = MainApp.getConfigBuilder().getProfile();
double sens = profile.getIsf(); double sens = profile.getIsf();
String ratioLimit = ""; String ratioLimit = "";

View file

@ -346,7 +346,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
if (!t.isEndingEvent()) { if (!t.isEndingEvent()) {
total.lastTempDate = t.date; total.lastTempDate = t.date;
total.lastTempDuration = t.durationInMinutes; 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) { if (!t.isEndingEvent() && t.date > total.lastTempDate) {
total.lastTempDate = t.date; total.lastTempDate = t.date;
total.lastTempDuration = t.durationInMinutes; 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; 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 @Override
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() { public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
return tempBasals; return tempBasals;

View file

@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
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.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
@ -86,7 +87,8 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
} }
holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.durationInMinutes) + " min"); holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.durationInMinutes) + " min");
if (tempBasal.isAbsolute) { 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(""); holder.percent.setText("");
} else { } else {
holder.absolute.setText(""); holder.absolute.setText("");

View file

@ -388,13 +388,14 @@ public class WatchUpdaterService extends WearableListenerService implements
if (tb1 != null) { if (tb1 != null) {
tb_before = beginBasalValue; tb_before = beginBasalValue;
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime); Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB);
tb_start = runningTime; tb_start = runningTime;
} }
for (; runningTime < now; runningTime += 5 * 60 * 1000) { for (; runningTime < now; runningTime += 5 * 60 * 1000) {
Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
//basal rate //basal rate
endBasalValue = profile.getBasal(runningTime); endBasalValue = profile.getBasal(runningTime);
if (endBasalValue != beginBasalValue) { if (endBasalValue != beginBasalValue) {
@ -422,10 +423,10 @@ public class WatchUpdaterService extends WearableListenerService implements
tb1 = tb2; tb1 = tb2;
tb_start = runningTime; tb_start = runningTime;
tb_before = endBasalValue; tb_before = endBasalValue;
tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime); tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB);
} else if (tb1 != null && tb2 != null) { } else if (tb1 != null && tb2 != null) {
double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime); double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime, profileTB);
if (currentAmount != tb_amount) { if (currentAmount != tb_amount) {
temps.add(tempDatamap(tb_start, tb_before, runningTime, currentAmount, tb_amount)); temps.add(tempDatamap(tb_start, tb_before, runningTime, currentAmount, tb_amount));
tb_start = runningTime; 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)); temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount));
} else { } else {
//express currently running temp by painting it a bit into the future //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) { if (currentAmount != tb_amount) {
temps.add(tempDatamap(tb_start, tb_before, now, tb_amount, 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)); 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 tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(now); //use "now" to express current situation
if (tb2 != null) { if (tb2 != null) {
//onset at the end //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)); temps.add(tempDatamap(now - 1 * 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
} }
} }

View file

@ -4,7 +4,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;

View file

@ -188,6 +188,14 @@ public class NSUpload {
} }
public static void uploadDeviceStatus() { 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(); DeviceStatus deviceStatus = new DeviceStatus();
try { try {
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun; LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
@ -204,8 +212,8 @@ public class NSUpload {
if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted
deviceStatus.enacted = lastRun.request.json(); deviceStatus.enacted = lastRun.request.json();
deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json().get("rate")); deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json(profile).get("rate"));
deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json().get("duration")); deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json(profile).get("duration"));
deviceStatus.enacted.put("recieved", true); deviceStatus.enacted.put("recieved", true);
requested.put("duration", lastRun.request.duration); requested.put("duration", lastRun.request.duration);
requested.put("rate", lastRun.request.rate); requested.put("rate", lastRun.request.rate);
@ -224,7 +232,7 @@ public class NSUpload {
log.debug("OpenAPS data too old to upload"); log.debug("OpenAPS data too old to upload");
} }
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL; deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
JSONObject pumpstatus = ConfigBuilderPlugin.getActivePump().getJSONStatus(); JSONObject pumpstatus = ConfigBuilderPlugin.getActivePump().getJSONStatus(profile, profileName);
if (pumpstatus != null) { if (pumpstatus != null) {
deviceStatus.pump = pumpstatus; deviceStatus.pump = pumpstatus;
} }