IOB graph

This commit is contained in:
Milos Kozak 2017-04-24 13:17:14 +02:00
parent 1a474f7983
commit a07a8755b1
4 changed files with 164 additions and 20 deletions

View file

@ -26,6 +26,7 @@ import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.Answers;
@ -125,8 +126,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
LinearLayout loopStatusLayout; LinearLayout loopStatusLayout;
LinearLayout pumpStatusLayout; LinearLayout pumpStatusLayout;
GraphView bgGraph; GraphView bgGraph;
GraphView iobGraph;
RelativeLayout iobGraphLayout;
CheckBox showPredictionView; CheckBox showPredictionView;
CheckBox showBasalsView; CheckBox showBasalsView;
CheckBox showIobView;
CheckBox showCobView;
RecyclerView notificationsView; RecyclerView notificationsView;
LinearLayoutManager llm; LinearLayoutManager llm;
@ -177,7 +183,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
iobView = (TextView) view.findViewById(R.id.overview_iob); iobView = (TextView) view.findViewById(R.id.overview_iob);
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget); tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget);
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
iobGraphLayout = (RelativeLayout) view.findViewById(R.id.overview_iobgraphlayout);
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltempbutton); cancelTempButton = (Button) view.findViewById(R.id.overview_canceltempbutton);
cancelTempButton.setOnClickListener(this); cancelTempButton.setOnClickListener(this);
@ -201,6 +210,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showPredictionView.setOnCheckedChangeListener(this); showPredictionView.setOnCheckedChangeListener(this);
showBasalsView = (CheckBox) view.findViewById(R.id.overview_showbasals); showBasalsView = (CheckBox) view.findViewById(R.id.overview_showbasals);
showBasalsView.setOnCheckedChangeListener(this); showBasalsView.setOnCheckedChangeListener(this);
showIobView = (CheckBox) view.findViewById(R.id.overview_showiob);
showIobView.setOnCheckedChangeListener(this);
showCobView = (CheckBox) view.findViewById(R.id.overview_showcob);
showCobView.setOnCheckedChangeListener(this);
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications); notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
notificationsView.setHasFixedSize(true); notificationsView.setHasFixedSize(true);
@ -209,9 +222,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showPredictionView.setChecked(SP.getBoolean("showprediction", false)); showPredictionView.setChecked(SP.getBoolean("showprediction", false));
showBasalsView.setChecked(SP.getBoolean("showbasals", false)); showBasalsView.setChecked(SP.getBoolean("showbasals", false));
showIobView.setChecked(SP.getBoolean("showiob", false));
showCobView.setChecked(SP.getBoolean("showcob", false));
bgGraph.getGridLabelRenderer().setGridColor(Color.rgb(0x75, 0x75, 0x75)); bgGraph.getGridLabelRenderer().setGridColor(Color.rgb(0x75, 0x75, 0x75));
bgGraph.getGridLabelRenderer().reloadStyles(); bgGraph.getGridLabelRenderer().reloadStyles();
iobGraph.getGridLabelRenderer().setGridColor(Color.rgb(0x75, 0x75, 0x75));
iobGraph.getGridLabelRenderer().reloadStyles();
iobGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
bgGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
iobGraph.getGridLabelRenderer().setNumVerticalLabels(5);
return view; return view;
} }
@ -254,6 +275,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
SP.putBoolean("showbasals", showPredictionView.isChecked()); SP.putBoolean("showbasals", showPredictionView.isChecked());
updateGUI("onBasalsCheckedChanged"); updateGUI("onBasalsCheckedChanged");
break; break;
case R.id.overview_showiob:
SP.putBoolean("showiob", showIobView.isChecked());
updateGUI("onIobCheckedChanged");
break;
case R.id.overview_showcob:
SP.putBoolean("showcob", showCobView.isChecked());
updateGUI("onCobCheckedChanged");
break;
} }
} }
@ -926,12 +955,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
LineGraphSeries<DataPoint> basalsLineSeries = null; LineGraphSeries<DataPoint> basalsLineSeries = null;
LineGraphSeries<DataPoint> baseBasalsSeries = null; LineGraphSeries<DataPoint> baseBasalsSeries = null;
LineGraphSeries<DataPoint> tempBasalsSeries = null; LineGraphSeries<DataPoint> tempBasalsSeries = null;
AreaGraphSeries<DoubleDataPoint> areaSeries = null; AreaGraphSeries<DoubleDataPoint> areaSeries;
LineGraphSeries<DataPoint> seriesNow = null; LineGraphSeries<DataPoint> seriesNow, seriesNow2;
PointsGraphSeries<BgReading> seriesInRage = null; PointsGraphSeries<BgReading> seriesInRage;
PointsGraphSeries<BgReading> seriesOutOfRange = null; PointsGraphSeries<BgReading> seriesOutOfRange;
PointsGraphSeries<BgReading> predSeries = null; PointsGraphSeries<BgReading> predSeries;
PointsWithLabelGraphSeries<Treatment> seriesTreatments = null; PointsWithLabelGraphSeries<Treatment> seriesTreatments;
// **** TEMP BASALS graph **** // **** TEMP BASALS graph ****
Double maxBasalValueFound = 0d; Double maxBasalValueFound = 0d;
@ -1011,6 +1040,69 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
basalsLineSeries.setCustomPaint(paint); basalsLineSeries.setCustomPaint(paint);
} }
// **** IOB COB graph ****
LineGraphSeries<DataPoint> iobSeries;
LineGraphSeries<DataPoint> cobSeries;
Double maxIobValueFound = 0d;
Double maxCobValueFound = 0d;
if (showIobView.isChecked() || showCobView.isChecked()) {
List<DataPoint> iobArray = new ArrayList<>();
List<DataPoint> cobArray = new ArrayList<>();
for (long time = fromTime; time <= endTime; time += 5 * 60 * 1000L) {
if (showIobView.isChecked()) {
IobTotal iob = IobTotal.calulateFromTreatmentsAndTemps(time);
iobArray.add(new DataPoint(time, iob.iob));
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob.iob));
}
if (showCobView.isChecked()) {
//MealData mealData = MainApp.getConfigBuilder().getActiveTreatments().getMealData();
//cobArray.add(new DataPoint(time, mealData.mealCOB));
//maxCobValueFound = Math.max(maxCobValueFound, mealData.mealCOB);
}
}
iobArray.add(iobArray.get(0)); // close the path
DataPoint[] iobData = new DataPoint[iobArray.size()];
iobData = iobArray.toArray(iobData);
iobSeries = new LineGraphSeries<>(iobData);
iobSeries.setDrawBackground(true);
iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.ioborange)); //50%
iobSeries.setColor(MainApp.sResources.getColor(R.color.ioborange));
iobSeries.setThickness(3);
iobSeries.setTitle("IOB");
iobGraph.getGridLabelRenderer().setVerticalLabelsAlign(Paint.Align.LEFT);
DataPoint[] cobData = new DataPoint[cobArray.size()];
cobData = cobArray.toArray(cobData);
cobSeries = new LineGraphSeries<>(cobData);
cobSeries.setDrawBackground(true);
cobSeries.setBackgroundColor(Color.RED);
cobSeries.setThickness(0);
iobGraph.removeAllSeries();
if (showIobView.isChecked()) {
iobGraph.addSeries(iobSeries);
}
if (showCobView.isChecked()) {
iobGraph.getSecondScale().addSeries(cobSeries);
iobGraph.getSecondScale().setLabelFormatter(new LabelFormatter() {
@Override
public String formatLabel(double value, boolean isValueX) {
return "";
}
@Override
public void setViewport(Viewport viewport) {
}
});
}
iobGraphLayout.setVisibility(View.VISIBLE);
} else {
iobGraphLayout.setVisibility(View.GONE);
}
// remove old data from graph // remove old data from graph
bgGraph.getSecondScale().getSeries().clear(); bgGraph.getSecondScale().getSeries().clear();
bgGraph.removeAllSeries(); bgGraph.removeAllSeries();
@ -1031,6 +1123,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
bgGraph.getViewport().setXAxisBoundsManual(true); bgGraph.getViewport().setXAxisBoundsManual(true);
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH")); bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
iobGraph.getViewport().setMaxX(endTime);
iobGraph.getViewport().setMinX(fromTime);
iobGraph.getViewport().setXAxisBoundsManual(true);
iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
// **** BG graph **** // **** BG graph ****
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true); List<BgReading> bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
@ -1093,9 +1190,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
new DataPoint(now, 0), new DataPoint(now, 0),
new DataPoint(now, maxBgValue) new DataPoint(now, maxBgValue)
}; };
bgGraph.addSeries(seriesNow = new LineGraphSeries<DataPoint>(nowPoints)); bgGraph.addSeries(seriesNow = new LineGraphSeries<>(nowPoints));
seriesNow.setColor(Color.GREEN);
seriesNow.setDrawDataPoints(false); seriesNow.setDrawDataPoints(false);
DataPoint[] nowPoints2 = new DataPoint[]{
new DataPoint(now, 0),
new DataPoint(now, maxIobValueFound)
};
iobGraph.addSeries(seriesNow2 = new LineGraphSeries<>(nowPoints2));
seriesNow2.setDrawDataPoints(false);
//seriesNow.setThickness(1); //seriesNow.setThickness(1);
// custom paint to make a dotted line // custom paint to make a dotted line
Paint paint = new Paint(); Paint paint = new Paint();
@ -1104,6 +1206,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0)); paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));
paint.setColor(Color.WHITE); paint.setColor(Color.WHITE);
seriesNow.setCustomPaint(paint); seriesNow.setCustomPaint(paint);
seriesNow2.setCustomPaint(paint);
// Treatments // Treatments
@ -1150,6 +1253,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
}); });
} }
//Notifications //Notifications

View file

@ -85,10 +85,10 @@
android:id="@+id/overview_pumpstatus" android:id="@+id/overview_pumpstatus"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/initializingborder"
android:gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:background="@drawable/initializingborder"
android:gravity="center_vertical|center_horizontal"
android:text="@string/initializing" android:text="@string/initializing"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout> </LinearLayout>
@ -197,11 +197,40 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<com.jjoe64.graphview.GraphView <LinearLayout
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="160dip" android:layout_height="match_parent"
android:layout_weight="1" /> android:layout_weight="1"
android:orientation="vertical">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content"
android:layout_height="160dip" />
<RelativeLayout
android:id="@+id/overview_iobgraphlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_iobgraph"
android:layout_width="wrap_content"
android:layout_height="80dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:text="@string/iob"
android:textColor="@color/ioborange"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -212,17 +241,25 @@
android:id="@+id/overview_showprediction" android:id="@+id/overview_showprediction"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:buttonTint="@color/magenta" app:buttonTint="@color/magenta" />
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<CheckBox <CheckBox
android:id="@+id/overview_showbasals" android:id="@+id/overview_showbasals"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" app:buttonTint="@color/cyan" />
android:layout_alignWithParentIfMissing="false"
android:layout_below="@+id/overview_showprediction" <CheckBox
android:id="@+id/overview_showiob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="@color/ioborange" />
<CheckBox
android:id="@+id/overview_showcob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:buttonTint="@color/cyan" /> app:buttonTint="@color/cyan" />
</LinearLayout> </LinearLayout>

View file

@ -2,6 +2,7 @@
<resources> <resources>
<color name="magenta">#ff00ff</color> <color name="magenta">#ff00ff</color>
<color name="cyan">#00ffff</color> <color name="cyan">#00ffff</color>
<color name="ioborange">#FFFB8C00</color>
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#303F9F</color>

View file

@ -592,4 +592,5 @@
<string name="key_usesuperbolus" translatable="false">key_usersuperbolus</string> <string name="key_usesuperbolus" translatable="false">key_usersuperbolus</string>
<string name="enablesuperbolus">Enable superbolus in wizard</string> <string name="enablesuperbolus">Enable superbolus in wizard</string>
<string name="enablesuperbolus_summary">Enable superbolus functionality in wizard. Do not enable until you learn what it really does. IT MAY CAUSE INSULIN OVERDOSE IF USED BLINDLY!</string> <string name="enablesuperbolus_summary">Enable superbolus functionality in wizard. Do not enable until you learn what it really does. IT MAY CAUSE INSULIN OVERDOSE IF USED BLINDLY!</string>
<string name="iob">IOB</string>
</resources> </resources>