From 88b9caa357de08ea55038aee365e657f1a7aaeed Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 5 Jun 2017 01:12:36 +0200 Subject: [PATCH] absolute basal line --- .../plugins/Overview/OverviewFragment.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 9a4697c86e..e81b4df96e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -1181,6 +1181,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } LineGraphSeries basalsLineSeries = null; + LineGraphSeries absoluteBasalsLineSeries = null; LineGraphSeries baseBasalsSeries = null; LineGraphSeries tempBasalsSeries = null; AreaGraphSeries areaSeries; @@ -1194,17 +1195,20 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, List baseBasalArray = new ArrayList<>(); List tempBasalArray = new ArrayList<>(); List basalLineArray = new ArrayList<>(); + List absoluteBasalLineArray = new ArrayList<>(); double lastLineBasal = 0; + double lastAbsoluteLineBasal = 0; double lastBaseBasal = 0; double lastTempBasal = 0; for (long time = fromTime; time < now; time += 1 * 60 * 1000L) { TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time); double baseBasalValue = MainApp.getConfigBuilder().getProfile(time).getBasal(Profile.secondsFromMidnight(time)); double baseLineValue = baseBasalValue; + double absoluteLineValue = baseBasalValue; double tempBasalValue = 0; double basal = 0d; if (tb != null) { - tempBasalValue = tb.tempBasalConvertedToAbsolute(new Date(time).getTime()); + absoluteLineValue = tempBasalValue = tb.tempBasalConvertedToAbsolute(new Date(time).getTime()); if (tempBasalValue != lastTempBasal) { tempBasalArray.add(new DataPoint(time, lastTempBasal)); tempBasalArray.add(new DataPoint(time, basal = tempBasalValue)); @@ -1230,7 +1234,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, basalLineArray.add(new DataPoint(time, lastLineBasal)); basalLineArray.add(new DataPoint(time, baseLineValue)); } + if (absoluteLineValue != lastAbsoluteLineBasal) { + absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal)); + absoluteBasalLineArray.add(new DataPoint(time, basal)); + } + lastAbsoluteLineBasal = absoluteLineValue; lastLineBasal = baseLineValue; lastTempBasal = tempBasalValue; maxBasalValueFound = Math.max(maxBasalValueFound, basal); @@ -1238,6 +1247,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, basalLineArray.add(new DataPoint(now, lastLineBasal)); baseBasalArray.add(new DataPoint(now, lastBaseBasal)); tempBasalArray.add(new DataPoint(now, lastTempBasal)); + absoluteBasalLineArray.add(new DataPoint(now, lastAbsoluteLineBasal)); DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()]; baseBasal = baseBasalArray.toArray(baseBasal); @@ -1262,6 +1272,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0)); paint.setColor(MainApp.sResources.getColor(R.color.basal)); basalsLineSeries.setCustomPaint(paint); + + DataPoint[] absoluteBasalLine = new DataPoint[absoluteBasalLineArray.size()]; + absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine); + absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine); + Paint absolutePaint = new Paint(); + absolutePaint.setStyle(Paint.Style.STROKE); + absolutePaint.setStrokeWidth(4); + absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal)); + absoluteBasalsLineSeries.setCustomPaint(absolutePaint); } // **** IOB COB DEV graph **** @@ -1492,6 +1511,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, bgGraph.getSecondScale().addSeries(baseBasalsSeries); bgGraph.getSecondScale().addSeries(tempBasalsSeries); bgGraph.getSecondScale().addSeries(basalsLineSeries); + bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries); bgGraph.getSecondScale().setMinY(0); bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d); }