refactor IOB calculation & fix iob_array.time
This commit is contained in:
parent
9d8d925f75
commit
d9fffc5625
|
@ -23,13 +23,16 @@ public class IobTotal {
|
|||
public Double netInsulin = 0d; // for calculations from temp basals only
|
||||
public Double netRatio = 0d; // for calculations from temp basals only
|
||||
|
||||
public IobTotal() {
|
||||
long time;
|
||||
|
||||
public IobTotal(long time) {
|
||||
this.iob = 0d;
|
||||
this.activity = 0d;
|
||||
this.bolussnooze = 0d;
|
||||
this.basaliob = 0d;
|
||||
this.netbasalinsulin = 0d;
|
||||
this.hightempinsulin = 0d;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public IobTotal plus(IobTotal other) {
|
||||
|
@ -45,7 +48,7 @@ public class IobTotal {
|
|||
}
|
||||
|
||||
public static IobTotal combine(IobTotal bolusIOB, IobTotal basalIob) {
|
||||
IobTotal result = new IobTotal();
|
||||
IobTotal result = new IobTotal(bolusIOB.time);
|
||||
result.iob = bolusIOB.iob + basalIob.basaliob;
|
||||
result.activity = bolusIOB.activity + basalIob.activity;
|
||||
result.bolussnooze = bolusIOB.bolussnooze;
|
||||
|
@ -85,7 +88,7 @@ public class IobTotal {
|
|||
json.put("basaliob", basaliob);
|
||||
json.put("bolussnooze", bolussnooze);
|
||||
json.put("activity", activity);
|
||||
json.put("time", DateUtil.toISOString(new Date()));
|
||||
json.put("time", DateUtil.toISOString(new Date(time)));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -95,19 +98,15 @@ public class IobTotal {
|
|||
public static IobTotal calulateFromTreatmentsAndTemps() {
|
||||
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculation().round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculation().round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||
return iobTotal;
|
||||
}
|
||||
|
||||
public static IobTotal calulateFromTreatmentsAndTemps(long time) {
|
||||
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTime(time).round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
IobTotal basalIob = ConfigBuilderPlugin.getActiveTempBasals().getCalculationToTime(time).round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||
return iobTotal;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TempBasal {
|
|||
|
||||
|
||||
public IobTotal iobCalc(Date time) {
|
||||
IobTotal result = new IobTotal();
|
||||
IobTotal result = new IobTotal(time.getTime());
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
|
||||
if (profile == null)
|
||||
|
|
|
@ -621,10 +621,8 @@ public class OverviewFragment extends Fragment {
|
|||
// iob
|
||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
|
||||
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
|
|
|
@ -219,10 +219,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
|
||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
|
||||
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
|
|
|
@ -174,7 +174,7 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface {
|
|||
checkForExpired(tempBasals);
|
||||
checkForExpired(extendedBoluses);
|
||||
Date now = new Date(time);
|
||||
IobTotal total = new IobTotal();
|
||||
IobTotal total = new IobTotal(time);
|
||||
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
||||
TempBasal t = tempBasals.get(pos);
|
||||
IobTotal calc = t.iobCalc(now);
|
||||
|
|
|
@ -110,7 +110,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
|
||||
@Override
|
||||
public IobTotal getCalculationToTime(long time) {
|
||||
IobTotal total = new IobTotal();
|
||||
IobTotal total = new IobTotal(time);
|
||||
|
||||
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
||||
return total;
|
||||
|
|
|
@ -444,10 +444,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
//IOB
|
||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "("
|
||||
+ DecimalFormatter.to2Decimal(bolusIob.iob) + "|"
|
||||
+ DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
|
||||
|
|
|
@ -126,10 +126,8 @@ public class PersistentNotificationPlugin implements PluginBase{
|
|||
//IOB
|
||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
+ ctx.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
||||
|
|
Loading…
Reference in a new issue