iob & basal on overview tab

This commit is contained in:
Milos Kozak 2016-06-24 23:17:46 +02:00
parent 3d16e874ad
commit 35ff53dbb4
5 changed files with 43 additions and 5 deletions

View file

@ -906,11 +906,12 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
if (lastRun.lastAPSRun.getTime() < new Date().getTime() - 60 * 1000L) if (lastRun.lastAPSRun.getTime() < new Date().getTime() - 60 * 1000L)
return; // do not send if result is older than 1 min return; // do not send if result is older than 1 min
String openapsmaPluginName = MainApp.resources.getString(R.string.openapsma); APSResult apsResult = lastRun.request;
if (lastRun.source != null && lastRun.source.equals(openapsmaPluginName)) { apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
deviceStatus.suggested = apsResult.json();
if (lastRun.request instanceof DetermineBasalResult) {
DetermineBasalResult result = (DetermineBasalResult) lastRun.request; DetermineBasalResult result = (DetermineBasalResult) lastRun.request;
result.json.put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
deviceStatus.suggested = result.json;
deviceStatus.iob = result.iob.json(); deviceStatus.iob = result.iob.json();
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun)); deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
} }

View file

@ -277,7 +277,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
lastRun.request = result; lastRun.request = result;
lastRun.constraintsProcessed = resultAfterConstraints; lastRun.constraintsProcessed = resultAfterConstraints;
lastRun.setByPump = null; lastRun.setByPump = null;
lastRun.source = ((PluginBase) usedAPS).getName(); lastRun.source = null;
lastRun.lastAPSRun = new Date(); lastRun.lastAPSRun = new Date();
} }
updateGUI(); updateGUI();

View file

@ -27,6 +27,7 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -45,6 +46,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
@ -59,6 +61,8 @@ public class OverviewFragment extends Fragment implements PluginBase {
TextView bgView; TextView bgView;
TextView timeAgoView; TextView timeAgoView;
TextView deltaView; TextView deltaView;
TextView runningTempView;
TextView iobView;
GraphView bgGraph; GraphView bgGraph;
LinearLayout cancelTempLayout; LinearLayout cancelTempLayout;
@ -149,6 +153,8 @@ public class OverviewFragment extends Fragment implements PluginBase {
bgView = (TextView) view.findViewById(R.id.overview_bg); bgView = (TextView) view.findViewById(R.id.overview_bg);
timeAgoView = (TextView) view.findViewById(R.id.overview_timeago); timeAgoView = (TextView) view.findViewById(R.id.overview_timeago);
deltaView = (TextView) view.findViewById(R.id.overview_delta); deltaView = (TextView) view.findViewById(R.id.overview_delta);
runningTempView = (TextView) view.findViewById(R.id.overview_runningtemp);
iobView = (TextView) view.findViewById(R.id.overview_iob);
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp); cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp);
treatmentButton = (Button) view.findViewById(R.id.overview_treatment); treatmentButton = (Button) view.findViewById(R.id.overview_treatment);
@ -274,6 +280,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
} }
public void updateGUI() { public void updateGUI() {
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
BgReading actualBG = MainApp.getDbHelper().actualBg(); BgReading actualBG = MainApp.getDbHelper().actualBg();
BgReading lastBG = MainApp.getDbHelper().lastBg(); BgReading lastBG = MainApp.getDbHelper().lastBg();
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
@ -296,9 +303,12 @@ public class OverviewFragment extends Fragment implements PluginBase {
cancelTempLayout.setVisibility(View.VISIBLE); cancelTempLayout.setVisibility(View.VISIBLE);
setTempLayout.setVisibility(View.GONE); setTempLayout.setVisibility(View.GONE);
cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + ": " + activeTemp.toString()); cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + ": " + activeTemp.toString());
runningTempView.setText(activeTemp.toString());
} else { } else {
cancelTempLayout.setVisibility(View.GONE); cancelTempLayout.setVisibility(View.GONE);
setTempLayout.setVisibility(View.VISIBLE); setTempLayout.setVisibility(View.VISIBLE);
Double currentBasal = pump.getBaseBasalRate();
runningTempView.setText(formatNumber2decimalplaces.format(currentBasal) + " U/h");
} }
// **** BG value **** // **** BG value ****
@ -322,6 +332,18 @@ public class OverviewFragment extends Fragment implements PluginBase {
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
timeAgoView.setText(agoMin + " " + getString(R.string.minago)); timeAgoView.setText(agoMin + " " + getString(R.string.minago));
// iob
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation();
if (bolusIob == null) bolusIob = new IobTotal();
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation();
if (basalIob == null) basalIob = new IobTotal();
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)";
iobView.setText(iobtext);
// ****** GRAPH ******* // ****** GRAPH *******
// allign to hours // allign to hours

View file

@ -43,6 +43,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/overview_runningtemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/overview_iob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -139,6 +139,7 @@
<string name="confirmation">Confirmation</string> <string name="confirmation">Confirmation</string>
<string name="entertreatmentquestion">Enter new treatment:</string> <string name="entertreatmentquestion">Enter new treatment:</string>
<string name="bolus">Bolus</string> <string name="bolus">Bolus</string>
<string name="basal">Basal</string>
<string name="carbs">Carbs</string> <string name="carbs">Carbs</string>
<string name="changeyourinput">Change your input!</string> <string name="changeyourinput">Change your input!</string>
<string name="setextendedbolusquestion">Set new extended bolus:</string> <string name="setextendedbolusquestion">Set new extended bolus:</string>