Merge pull request #275 from AdrianLxM/fakeextended-fix
Fake extended fix
This commit is contained in:
commit
24259470ad
5 changed files with 76 additions and 34 deletions
|
@ -47,11 +47,16 @@ public class TemporaryBasal implements Interval {
|
||||||
public int durationInMinutes = 0; // duration == 0 means end of temp basal
|
public int durationInMinutes = 0; // duration == 0 means end of temp basal
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public boolean isAbsolute = false;
|
public boolean isAbsolute = false;
|
||||||
|
|
||||||
|
public boolean isFakeExtended = false;
|
||||||
|
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public int percentRate = 0;
|
public int percentRate = 0;
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public double absoluteRate = 0d;
|
public double absoluteRate = 0d;
|
||||||
|
|
||||||
|
public double netExtendedRate = 0d;
|
||||||
|
|
||||||
public TemporaryBasal() {
|
public TemporaryBasal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +72,8 @@ public class TemporaryBasal implements Interval {
|
||||||
this._id = extendedBolus._id;
|
this._id = extendedBolus._id;
|
||||||
this.durationInMinutes = extendedBolus.durationInMinutes;
|
this.durationInMinutes = extendedBolus.durationInMinutes;
|
||||||
this.isAbsolute = true;
|
this.isAbsolute = true;
|
||||||
|
this.isFakeExtended = true;
|
||||||
|
this.netExtendedRate = extendedBolus.absoluteRate();
|
||||||
this.absoluteRate = basal + extendedBolus.absoluteRate();
|
this.absoluteRate = basal + extendedBolus.absoluteRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +103,10 @@ public class TemporaryBasal implements Interval {
|
||||||
return false;
|
return false;
|
||||||
if (absoluteRate != other.absoluteRate)
|
if (absoluteRate != other.absoluteRate)
|
||||||
return false;
|
return false;
|
||||||
|
if (netExtendedRate != other.netExtendedRate)
|
||||||
|
return false;
|
||||||
|
if (isFakeExtended != other.isFakeExtended)
|
||||||
|
return false;
|
||||||
if (pumpId != other.pumpId)
|
if (pumpId != other.pumpId)
|
||||||
return false;
|
return false;
|
||||||
if (!Objects.equals(_id, other._id))
|
if (!Objects.equals(_id, other._id))
|
||||||
|
@ -111,6 +122,8 @@ public class TemporaryBasal implements Interval {
|
||||||
percentRate = t.percentRate;
|
percentRate = t.percentRate;
|
||||||
absoluteRate = t.absoluteRate;
|
absoluteRate = t.absoluteRate;
|
||||||
pumpId = t.pumpId;
|
pumpId = t.pumpId;
|
||||||
|
isFakeExtended = t.isFakeExtended;
|
||||||
|
netExtendedRate = t.netExtendedRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- Interval interface ---------
|
// -------- Interval interface ---------
|
||||||
|
@ -172,6 +185,12 @@ public class TemporaryBasal implements Interval {
|
||||||
// -------- Interval interface end ---------
|
// -------- Interval interface end ---------
|
||||||
|
|
||||||
public IobTotal iobCalc(long time) {
|
public IobTotal iobCalc(long time) {
|
||||||
|
|
||||||
|
if(isFakeExtended){
|
||||||
|
log.error("iobCalc should only be called on Extended boluses separately");
|
||||||
|
return new IobTotal(time);
|
||||||
|
}
|
||||||
|
|
||||||
IobTotal result = new IobTotal(time);
|
IobTotal result = new IobTotal(time);
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile(time);
|
Profile profile = MainApp.getConfigBuilder().getProfile(time);
|
||||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||||
|
@ -239,8 +258,11 @@ public class TemporaryBasal implements Interval {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double tempBasalConvertedToAbsolute(long time) {
|
public double tempBasalConvertedToAbsolute(long time) {
|
||||||
if (isAbsolute) return absoluteRate;
|
if(isFakeExtended){
|
||||||
else {
|
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) + netExtendedRate;
|
||||||
|
} else if (isAbsolute) {
|
||||||
|
return absoluteRate;
|
||||||
|
} else {
|
||||||
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) * percentRate / 100;
|
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) * percentRate / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,11 +278,21 @@ public class TemporaryBasal implements Interval {
|
||||||
", absoluteRate=" + absoluteRate +
|
", absoluteRate=" + absoluteRate +
|
||||||
", durationInMinutes=" + durationInMinutes +
|
", durationInMinutes=" + durationInMinutes +
|
||||||
", isAbsolute=" + isAbsolute +
|
", isAbsolute=" + isAbsolute +
|
||||||
|
", isFakeExtended=" + isFakeExtended +
|
||||||
|
", netExtendedRate=" + netExtendedRate +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toStringFull() {
|
public String toStringFull() {
|
||||||
if (isAbsolute) {
|
if(isFakeExtended){
|
||||||
|
|
||||||
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
Double currentBasalRate = profile.getBasal();
|
||||||
|
double rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate);
|
||||||
|
return DecimalFormatter.to2Decimal(rate) + "U/h ("+DecimalFormatter.to2Decimal(netExtendedRate)+"E) @" +
|
||||||
|
DateUtil.timeString(date) +
|
||||||
|
" " + getRealDuration() + "/" + durationInMinutes + "min";
|
||||||
|
} else if (isAbsolute) {
|
||||||
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h @" +
|
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h @" +
|
||||||
DateUtil.timeString(date) +
|
DateUtil.timeString(date) +
|
||||||
" " + getRealDuration() + "/" + durationInMinutes + "min";
|
" " + getRealDuration() + "/" + durationInMinutes + "min";
|
||||||
|
@ -272,28 +304,46 @@ public class TemporaryBasal implements Interval {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toStringShort() {
|
public String toStringShort() {
|
||||||
if (isAbsolute) {
|
if (isAbsolute || isFakeExtended) {
|
||||||
|
|
||||||
|
double rate = 0d;
|
||||||
|
if (isFakeExtended) {
|
||||||
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
Double currentBasalRate = profile.getBasal();
|
||||||
|
rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate);
|
||||||
|
} else if (isAbsolute){
|
||||||
|
rate = absoluteRate;
|
||||||
|
}
|
||||||
|
|
||||||
if(SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false) && SP.getBoolean(R.string.key_danar_useextended, false)){
|
if(SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false) && SP.getBoolean(R.string.key_danar_useextended, false)){
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
if(profile != null) {
|
if(profile != null) {
|
||||||
double basal = profile.getBasal(System.currentTimeMillis());
|
double basal = profile.getBasal();
|
||||||
if(basal != 0){
|
if(basal != 0){
|
||||||
return Math.round(absoluteRate*100d/basal) + "% ";
|
return Math.round(rate*100d/basal) + "% ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h ";
|
return DecimalFormatter.to2Decimal(rate) + "U/h ";
|
||||||
} else { // percent
|
} else { // percent
|
||||||
return percentRate + "% ";
|
return percentRate + "% ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toStringMedium() {
|
public String toStringVeryShort() {
|
||||||
if (isAbsolute) {
|
if (isAbsolute || isFakeExtended) {
|
||||||
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h ("
|
|
||||||
+ getRealDuration() + "/" + durationInMinutes + ") ";
|
double rate = 0d;
|
||||||
|
if (isFakeExtended) {
|
||||||
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
Double currentBasalRate = profile.getBasal();
|
||||||
|
rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate);
|
||||||
|
} else if (isAbsolute){
|
||||||
|
rate = absoluteRate;
|
||||||
|
}
|
||||||
|
return DecimalFormatter.to2Decimal(rate) + "U/h ";
|
||||||
} else { // percent
|
} else { // percent
|
||||||
return percentRate + "% (" + getRealDuration() + "/" + durationInMinutes + ") ";
|
return percentRate + "% ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1031,10 +1031,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
String basalText = "";
|
String basalText = "";
|
||||||
if (shorttextmode) {
|
if (shorttextmode) {
|
||||||
if (activeTemp != null) {
|
if (activeTemp != null) {
|
||||||
if (activeTemp.isAbsolute)
|
basalText = "T: " + activeTemp.toStringVeryShort();
|
||||||
basalText = "T: " + DecimalFormatter.to2Decimal(activeTemp.absoluteRate) + "U/h";
|
|
||||||
else
|
|
||||||
basalText = "T: " + DecimalFormatter.to0Decimal(activeTemp.percentRate) + "%";
|
|
||||||
} else {
|
} else {
|
||||||
basalText = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h";
|
basalText = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h";
|
||||||
}
|
}
|
||||||
|
@ -1054,9 +1051,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
basalText = activeTemp.toStringFull() + " ";
|
basalText = activeTemp.toStringFull() + " ";
|
||||||
}
|
}
|
||||||
if (Config.NSCLIENT)
|
if (Config.NSCLIENT)
|
||||||
basalText += "( " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h )";
|
basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)";
|
||||||
else if (pump.getPumpDescription().isTempBasalCapable) {
|
else if (pump.getPumpDescription().isTempBasalCapable) {
|
||||||
basalText += "( " + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h )";
|
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
baseBasalView.setText(basalText);
|
baseBasalView.setText(basalText);
|
||||||
|
|
|
@ -357,7 +357,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (tb != null) {
|
if (tb != null) {
|
||||||
if (tb.isAbsolute) {
|
if (tb.isFakeExtended){
|
||||||
|
double baseRate = pump.getBaseBasalRate();
|
||||||
|
double tempRate = baseRate + tb.netExtendedRate;
|
||||||
|
return tempRate;
|
||||||
|
} else if (tb.isAbsolute) {
|
||||||
return tb.absoluteRate;
|
return tb.absoluteRate;
|
||||||
} else {
|
} else {
|
||||||
double baseRate = pump.getBaseBasalRate();
|
double baseRate = pump.getBaseBasalRate();
|
||||||
|
|
|
@ -525,7 +525,6 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
@NonNull
|
@NonNull
|
||||||
private String generateStatusString() {
|
private String generateStatusString() {
|
||||||
String status = "";
|
String status = "";
|
||||||
boolean shortString = true;
|
|
||||||
|
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
|
@ -547,11 +546,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
|
|
||||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||||
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (shortString) {
|
status += activeTemp.toStringShort();
|
||||||
status += activeTemp.toStringShort();
|
|
||||||
} else {
|
|
||||||
status += activeTemp.toStringMedium();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//IOB
|
//IOB
|
||||||
|
@ -559,7 +555,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
|
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
|
||||||
treatmentsInterface.updateTotalIOBTempBasals();
|
treatmentsInterface.updateTotalIOBTempBasals();
|
||||||
IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
|
IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
|
||||||
status += (shortString ? "" : (getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
||||||
|
|
||||||
if (mPrefs.getBoolean("wear_detailediob", true)) {
|
if (mPrefs.getBoolean("wear_detailediob", true)) {
|
||||||
status += "("
|
status += "("
|
||||||
|
|
|
@ -160,8 +160,6 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
@NonNull
|
@NonNull
|
||||||
private String buildStatusString() {
|
private String buildStatusString() {
|
||||||
String status = "";
|
String status = "";
|
||||||
boolean shortString = true; // make setting?
|
|
||||||
|
|
||||||
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||||
|
|
||||||
if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) {
|
if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) {
|
||||||
|
@ -176,11 +174,8 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
|
|
||||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||||
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (shortString) {
|
status += activeTemp.toStringShort();
|
||||||
status += activeTemp.toStringShort();
|
|
||||||
} else {
|
|
||||||
status += activeTemp.toStringMedium();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//IOB
|
//IOB
|
||||||
|
@ -188,7 +183,7 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
|
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
|
||||||
treatmentsInterface.updateTotalIOBTempBasals();
|
treatmentsInterface.updateTotalIOBTempBasals();
|
||||||
IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
|
IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
|
||||||
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
||||||
|
|
||||||
|
|
||||||
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
|
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
|
||||||
|
|
Loading…
Reference in a new issue