From f573265bc2de1caf4e2b9acfd82d329b84529c9c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 4 Feb 2018 00:31:36 +0100 Subject: [PATCH 1/2] Add target line to graph. Uses the middle if a range is specified to show what the loop aims for. --- .../plugins/Overview/OverviewFragment.java | 3 ++ .../plugins/Overview/graphData/GraphData.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) 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 13b81fe8be..adde4474de 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 @@ -1384,6 +1384,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2d); } + // add target line + graphData.addTargetLine(fromTime, toTime); + // **** NOW line **** graphData.addNowLine(now); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index f6cd2eecdc..916ee7596c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -22,12 +22,14 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.BasalData; import info.nightscout.androidaps.plugins.Loop.APSResult; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; @@ -36,6 +38,7 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLab import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale; import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint; import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.Round; /** @@ -215,6 +218,54 @@ public class GraphData { addSeries(absoluteBasalsLineSeries); } + public void addTargetLine(long fromTime, long toTime) { + Profile profile = MainApp.getConfigBuilder().getProfile(); + if (profile == null) { + return; + } + + LineGraphSeries targetsSeries; + + Scale targetsScale = new Scale(); + targetsScale.setMultiplier(1); + + List targetsSeriesArray = new ArrayList<>(); + double lastTarget = 0; + + if (LoopPlugin.lastRun != null && LoopPlugin.lastRun.constraintsProcessed != null) { + APSResult apsResult = LoopPlugin.lastRun.constraintsProcessed; + long latestPredictionsTime = apsResult.getLatestPredictionsTime(); + if (latestPredictionsTime > toTime) { + toTime = latestPredictionsTime; + } + } + + for (long time = fromTime; time < toTime; time += 60 * 1000L) { + TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time); + double value; + if (tt == null) { + value = (profile.getTargetLow() + profile.getTargetHigh()) / 2; + } else { + value = (tt.low + tt.high) / 2; + } + if (lastTarget > 0 && lastTarget != value) { + targetsSeriesArray.add(new DataPoint(time, lastTarget)); + } + lastTarget = value; + + targetsSeriesArray.add(new DataPoint(time, value)); + } + + DataPoint[] targets = new DataPoint[targetsSeriesArray.size()]; + targets = targetsSeriesArray.toArray(targets); + targetsSeries = new LineGraphSeries<>(targets); + targetsSeries.setDrawBackground(false); + targetsSeries.setColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); + targetsSeries.setThickness(2); + + addSeries(targetsSeries); + } + public void addTreatments(long fromTime, long endTime) { List filteredTreatments = new ArrayList<>(); From 6b4b044cd646208ca7a8edeeedddd270db5a83e8 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 4 Feb 2018 00:36:08 +0100 Subject: [PATCH 2/2] Remove nested layout for better performance. --- app/src/main/res/layout/overview_fragment.xml | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 10c89254e9..bc699bad3c 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -347,26 +347,17 @@ - + android:layout_weight="1" /> - - - - - +