fix counting and displaying iob

This commit is contained in:
Milos Kozak 2016-06-25 15:00:42 +02:00
parent 228c8b4f9f
commit 5dfddfdfee
6 changed files with 44 additions and 33 deletions

View file

@ -20,28 +20,34 @@ public class DetermineBasalResult extends APSResult {
public DetermineBasalResult(V8Object result, JSONObject j) { public DetermineBasalResult(V8Object result, JSONObject j) {
json = j; json = j;
reason = result.getString("reason"); if (result.contains("error")) {
eventualBG = result.getDouble("eventualBG"); reason = result.getString("error");
snoozeBG = result.getDouble("snoozeBG"); changeRequested = false;
if (result.contains("rate")) {
rate = result.getDouble("rate");
if (rate < 0d) rate = 0d;
changeRequested = true;
} else {
rate = -1; rate = -1;
changeRequested = false;
}
if (result.contains("duration")) {
duration = result.getInteger("duration");
changeRequested = changeRequested;
} else {
duration = -1; duration = -1;
changeRequested = false; mealAssist = "";
} else {
eventualBG = result.getDouble("eventualBG");
snoozeBG = result.getDouble("snoozeBG");
if (result.contains("rate")) {
rate = result.getDouble("rate");
if (rate < 0d) rate = 0d;
changeRequested = true;
} else {
rate = -1;
changeRequested = false;
}
if (result.contains("duration")) {
duration = result.getInteger("duration");
changeRequested = changeRequested;
} else {
duration = -1;
changeRequested = false;
}
if (result.contains("mealAssist")) {
mealAssist = result.getString("mealAssist");
} else mealAssist = "";
} }
if (result.contains("mealAssist")) {
mealAssist = result.getString("mealAssist");
} else mealAssist = "";
result.release(); result.release();
} }

View file

@ -30,11 +30,11 @@ public class IobTotal {
public IobTotal plus(IobTotal other) { public IobTotal plus(IobTotal other) {
iob += other.iob; iob += other.iob;
activity = other.activity; activity += other.activity;
bolussnooze = other.bolussnooze; bolussnooze += other.bolussnooze;
basaliob = other.iob; basaliob += other.basaliob;
netbasalinsulin = other.netbasalinsulin; netbasalinsulin += other.netbasalinsulin;
hightempinsulin = other.hightempinsulin; hightempinsulin += other.hightempinsulin;
netInsulin += other.netInsulin; netInsulin += other.netInsulin;
netRatio += other.netRatio; netRatio += other.netRatio;
return this; return this;

View file

@ -341,7 +341,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
if (basalIob == null) basalIob = new IobTotal(); if (basalIob == null) basalIob = new IobTotal();
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round(); IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
String iobtext = getString(R.string.treatments_iob_label_string) + " " + formatNumber2decimalplaces.format(iobTotal.iob) + "U (" + getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(bolusIob.iob) + "U " + getString(R.string.basal) + ": " + formatNumber2decimalplaces.format(basalIob.iob) + "U)"; String iobtext = getString(R.string.treatments_iob_label_string) + " " + formatNumber2decimalplaces.format(iobTotal.iob) + "U ("
+ getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(bolusIob.iob) + "U "
+ getString(R.string.basal) + ": " + formatNumber2decimalplaces.format(basalIob.basaliob) + "U)";
iobView.setText(iobtext); iobView.setText(iobtext);
// ****** GRAPH ******* // ****** GRAPH *******

View file

@ -44,7 +44,7 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
RecyclerView recyclerView; RecyclerView recyclerView;
LinearLayoutManager llm; LinearLayoutManager llm;
TextView iobTotal; TextView tempBasalTotalView;
public long lastCalculationTimestamp = 0; public long lastCalculationTimestamp = 0;
public IobTotal lastCalculation; public IobTotal lastCalculation;
@ -205,7 +205,8 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
IobTotal total = new IobTotal(); IobTotal total = new IobTotal();
for (Integer pos = 0; pos < tempBasals.size(); pos++) { for (Integer pos = 0; pos < tempBasals.size(); pos++) {
TempBasal t = tempBasals.get(pos); TempBasal t = tempBasals.get(pos);
total.plus(t.iobCalc(now)); IobTotal calc = t.iobCalc(now);
total.plus(calc);
} }
lastCalculationTimestamp = new Date().getTime(); lastCalculationTimestamp = new Date().getTime();
@ -348,8 +349,8 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
RecyclerViewAdapter adapter = new RecyclerViewAdapter(tempBasals); RecyclerViewAdapter adapter = new RecyclerViewAdapter(tempBasals);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
iobTotal = (TextView) view.findViewById(R.id.tempbasals_iobtotal); tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
updateGUI();
return view; return view;
} }
@ -374,9 +375,10 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
@Override @Override
public void run() { public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(tempBasals), false); recyclerView.swapAdapter(new RecyclerViewAdapter(tempBasals), false);
if (lastCalculation != null) if (lastCalculation != null) {
iobTotal.setText(formatNumber2decimalplaces.format(lastCalculation.basaliob)); String totalText = formatNumber2decimalplaces.format(lastCalculation.basaliob) + "U";
tempBasalTotalView.setText(totalText);
}
} }
}); });
} }

View file

@ -284,6 +284,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout); refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
refreshFromNS.setOnClickListener(this); refreshFromNS.setOnClickListener(this);
updateGUI();
return view; return view;
} }

View file

@ -28,7 +28,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/tempbasals_iobtotal" android:id="@+id/tempbasals_totaltempiob"
android:paddingLeft="10dp" /> android:paddingLeft="10dp" />
</LinearLayout> </LinearLayout>