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
|
||||
@DatabaseField
|
||||
public boolean isAbsolute = false;
|
||||
|
||||
public boolean isFakeExtended = false;
|
||||
|
||||
@DatabaseField
|
||||
public int percentRate = 0;
|
||||
@DatabaseField
|
||||
public double absoluteRate = 0d;
|
||||
|
||||
public double netExtendedRate = 0d;
|
||||
|
||||
public TemporaryBasal() {
|
||||
}
|
||||
|
||||
|
@ -67,6 +72,8 @@ public class TemporaryBasal implements Interval {
|
|||
this._id = extendedBolus._id;
|
||||
this.durationInMinutes = extendedBolus.durationInMinutes;
|
||||
this.isAbsolute = true;
|
||||
this.isFakeExtended = true;
|
||||
this.netExtendedRate = extendedBolus.absoluteRate();
|
||||
this.absoluteRate = basal + extendedBolus.absoluteRate();
|
||||
}
|
||||
|
||||
|
@ -96,6 +103,10 @@ public class TemporaryBasal implements Interval {
|
|||
return false;
|
||||
if (absoluteRate != other.absoluteRate)
|
||||
return false;
|
||||
if (netExtendedRate != other.netExtendedRate)
|
||||
return false;
|
||||
if (isFakeExtended != other.isFakeExtended)
|
||||
return false;
|
||||
if (pumpId != other.pumpId)
|
||||
return false;
|
||||
if (!Objects.equals(_id, other._id))
|
||||
|
@ -111,6 +122,8 @@ public class TemporaryBasal implements Interval {
|
|||
percentRate = t.percentRate;
|
||||
absoluteRate = t.absoluteRate;
|
||||
pumpId = t.pumpId;
|
||||
isFakeExtended = t.isFakeExtended;
|
||||
netExtendedRate = t.netExtendedRate;
|
||||
}
|
||||
|
||||
// -------- Interval interface ---------
|
||||
|
@ -172,6 +185,12 @@ public class TemporaryBasal implements Interval {
|
|||
// -------- Interval interface end ---------
|
||||
|
||||
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);
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile(time);
|
||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||
|
@ -239,8 +258,11 @@ public class TemporaryBasal implements Interval {
|
|||
}
|
||||
|
||||
public double tempBasalConvertedToAbsolute(long time) {
|
||||
if (isAbsolute) return absoluteRate;
|
||||
else {
|
||||
if(isFakeExtended){
|
||||
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) + netExtendedRate;
|
||||
} else if (isAbsolute) {
|
||||
return absoluteRate;
|
||||
} else {
|
||||
return MainApp.getConfigBuilder().getProfile(time).getBasal(time) * percentRate / 100;
|
||||
}
|
||||
}
|
||||
|
@ -256,11 +278,21 @@ public class TemporaryBasal implements Interval {
|
|||
", absoluteRate=" + absoluteRate +
|
||||
", durationInMinutes=" + durationInMinutes +
|
||||
", isAbsolute=" + isAbsolute +
|
||||
", isFakeExtended=" + isFakeExtended +
|
||||
", netExtendedRate=" + netExtendedRate +
|
||||
'}';
|
||||
}
|
||||
|
||||
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 @" +
|
||||
DateUtil.timeString(date) +
|
||||
" " + getRealDuration() + "/" + durationInMinutes + "min";
|
||||
|
@ -272,28 +304,46 @@ public class TemporaryBasal implements Interval {
|
|||
}
|
||||
|
||||
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)){
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
if(profile != null) {
|
||||
double basal = profile.getBasal(System.currentTimeMillis());
|
||||
double basal = profile.getBasal();
|
||||
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
|
||||
return percentRate + "% ";
|
||||
}
|
||||
}
|
||||
|
||||
public String toStringMedium() {
|
||||
if (isAbsolute) {
|
||||
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h ("
|
||||
+ getRealDuration() + "/" + durationInMinutes + ") ";
|
||||
public String toStringVeryShort() {
|
||||
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;
|
||||
}
|
||||
return DecimalFormatter.to2Decimal(rate) + "U/h ";
|
||||
} else { // percent
|
||||
return percentRate + "% (" + getRealDuration() + "/" + durationInMinutes + ") ";
|
||||
return percentRate + "% ";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1031,10 +1031,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
String basalText = "";
|
||||
if (shorttextmode) {
|
||||
if (activeTemp != null) {
|
||||
if (activeTemp.isAbsolute)
|
||||
basalText = "T: " + DecimalFormatter.to2Decimal(activeTemp.absoluteRate) + "U/h";
|
||||
else
|
||||
basalText = "T: " + DecimalFormatter.to0Decimal(activeTemp.percentRate) + "%";
|
||||
basalText = "T: " + activeTemp.toStringVeryShort();
|
||||
} else {
|
||||
basalText = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h";
|
||||
}
|
||||
|
@ -1054,9 +1051,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
basalText = activeTemp.toStringFull() + " ";
|
||||
}
|
||||
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) {
|
||||
basalText += "( " + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h )";
|
||||
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
|
||||
}
|
||||
}
|
||||
baseBasalView.setText(basalText);
|
||||
|
|
|
@ -357,7 +357,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
|
||||
TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
|
||||
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;
|
||||
} else {
|
||||
double baseRate = pump.getBaseBasalRate();
|
||||
|
|
|
@ -525,7 +525,6 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
@NonNull
|
||||
private String generateStatusString() {
|
||||
String status = "";
|
||||
boolean shortString = true;
|
||||
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
if (profile == null) {
|
||||
|
@ -547,11 +546,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (shortString) {
|
||||
status += activeTemp.toStringShort();
|
||||
} else {
|
||||
status += activeTemp.toStringMedium();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//IOB
|
||||
|
@ -559,7 +555,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
|
||||
treatmentsInterface.updateTotalIOBTempBasals();
|
||||
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)) {
|
||||
status += "("
|
||||
|
|
|
@ -160,8 +160,6 @@ public class StatuslinePlugin implements PluginBase {
|
|||
@NonNull
|
||||
private String buildStatusString() {
|
||||
String status = "";
|
||||
boolean shortString = true; // make setting?
|
||||
|
||||
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
|
||||
if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) {
|
||||
|
@ -176,11 +174,8 @@ public class StatuslinePlugin implements PluginBase {
|
|||
|
||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (shortString) {
|
||||
status += activeTemp.toStringShort();
|
||||
} else {
|
||||
status += activeTemp.toStringMedium();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//IOB
|
||||
|
@ -188,7 +183,7 @@ public class StatuslinePlugin implements PluginBase {
|
|||
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
|
||||
treatmentsInterface.updateTotalIOBTempBasals();
|
||||
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)) {
|
||||
|
|
Loading…
Reference in a new issue