From 5ef7506e5fd6282c99943382f91dda101a5823c2 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 1 May 2018 19:16:28 +0200 Subject: [PATCH 1/5] Clean up prediction colors. --- .../main/java/info/nightscout/androidaps/db/BgReading.java | 5 ++--- .../java/info/nightscout/androidaps/db/CareportalEvent.java | 5 ----- .../java/info/nightscout/androidaps/db/ExtendedBolus.java | 4 ---- .../java/info/nightscout/androidaps/db/ProfileSwitch.java | 5 ----- .../androidaps/plugins/IobCobCalculator/AutosensData.java | 5 ----- .../graphExtensions/DataPointWithLabelInterface.java | 1 - .../Overview/graphExtensions/PointsWithLabelGraphSeries.java | 1 - .../nightscout/androidaps/plugins/Treatments/Treatment.java | 5 ----- app/src/main/res/values/colors.xml | 2 +- 9 files changed, 3 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index 20b9040065..17a6d7d8e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -211,7 +211,7 @@ public class BgReading implements DataPointWithLabelInterface { } int color = MainApp.sResources.getColor(R.color.inrange); if (isPrediction()) - color = MainApp.sResources.getColor(R.color.prediction); + return getPredectionColor(); else if (valueToUnits(units) < lowLine) color = MainApp.sResources.getColor(R.color.low); else if (valueToUnits(units) > highLine) @@ -219,8 +219,7 @@ public class BgReading implements DataPointWithLabelInterface { return color; } - @Override - public int getSecondColor() { + private int getPredectionColor() { if (isIOBPrediction) return MainApp.sResources.getColor(R.color.iob); if (isCOBPrediction) diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index b0f69144c5..33fee529bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -263,9 +263,4 @@ public class CareportalEvent implements DataPointWithLabelInterface { return Color.GRAY; } - @Override - public int getSecondColor() { - return 0; - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java index 418de86c6c..1123cb58df 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java @@ -297,8 +297,4 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface { return Color.CYAN; } - @Override - public int getSecondColor() { - return 0; - } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 9dca91c595..40c8e50c6d 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -263,11 +263,6 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { return Color.CYAN; } - @Override - public int getSecondColor() { - return 0; - } - public String toString() { return "ProfileSwitch{" + "date=" + date + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 693a6fad55..79ab63e2ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -164,9 +164,4 @@ public class AutosensData implements DataPointWithLabelInterface { return MainApp.gc(R.color.cob); } - @Override - public int getSecondColor() { - return 0; - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java index 3f6280431c..20d478692a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java @@ -55,5 +55,4 @@ public interface DataPointWithLabelInterface extends DataPointInterface{ PointsWithLabelGraphSeries.Shape getShape(); float getSize(); int getColor(); - int getSecondColor(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java index 8ac3be0ad8..5f39cedafe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java @@ -211,7 +211,6 @@ public class PointsWithLabelGraphSeries e mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeWidth(0); canvas.drawCircle(endX, endY, scaledPxSize, mPaint); - mPaint.setColor(value.getSecondColor()); mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeWidth(0); canvas.drawCircle(endX, endY, scaledPxSize / 3, mPaint); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java index 31d44a3e30..1983c38242 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java @@ -193,11 +193,6 @@ public class Treatment implements DataPointWithLabelInterface { return MainApp.instance().getResources().getColor(android.R.color.holo_red_light); } - @Override - public int getSecondColor() { - return 0; - } - @Override public void setY(double y) { yValue = y; diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e5b645dcc6..58982405c0 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -6,7 +6,7 @@ #FFFFCC03 #FFFB8C00 #ffea00 - #ff9500 + #00ffff #FFFFFF #FFFFFF00 #FFFF00FF From ee61a7118114017e41ba65383c2e789ce9feb9ee Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 1 May 2018 19:23:12 +0200 Subject: [PATCH 2/5] Sort predictions so they're properly displayed in the graph. GraphView library requires a series to be ordered by the x-value. --- .../androidaps/plugins/Overview/OverviewFragment.java | 3 ++- .../androidaps/plugins/Overview/graphData/GraphData.java | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) 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 2536e8bf5c..3f126aba19 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 @@ -1359,7 +1359,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // **** BG **** if (predictionsAvailable && SP.getBoolean("showprediction", false)) - graphData.addBgReadings(fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed); + graphData.addBgReadings(fromTime, toTime, lowLine, highLine, + finalLastRun.constraintsProcessed.getPredictions()); else graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null); 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 25e7cb4af8..51e406af13 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 @@ -12,6 +12,7 @@ import com.jjoe64.graphview.series.LineGraphSeries; import com.jjoe64.graphview.series.Series; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import info.nightscout.androidaps.Constants; @@ -61,7 +62,7 @@ public class GraphData { this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; } - public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, APSResult apsResult) { + public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, List predictions) { double maxBgValue = 0d; bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true); List bgListArray = new ArrayList<>(); @@ -74,9 +75,9 @@ public class GraphData { if (bg.value > maxBgValue) maxBgValue = bg.value; bgListArray.add(bg); } - if (apsResult != null) { - List predArray = apsResult.getPredictions(); - bgListArray.addAll(predArray); + if (predictions != null) { + Collections.sort(predictions, (o1, o2) -> Double.compare(o1.getX(), o2.getX())); + bgListArray.addAll(predictions); } maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units); From 1e80ca22c646782118c646cdb19361630db5d1aa Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 1 May 2018 19:23:38 +0200 Subject: [PATCH 3/5] Don't draw invalidated SMBs. --- .../androidaps/plugins/Overview/graphData/GraphData.java | 1 + 1 file changed, 1 insertion(+) 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 51e406af13..a15fef8882 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 @@ -274,6 +274,7 @@ public class GraphData { for (int tx = 0; tx < treatments.size(); tx++) { Treatment t = treatments.get(tx); if (t.getX() < fromTime || t.getX() > endTime) continue; + if (t.isSMB && !t.isValid) continue; t.setY(getNearestBg((long) t.getX())); filteredTreatments.add(t); } From af563474d51a19750547fa77b8d41ced4ce19f14 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 1 May 2018 18:18:06 +0200 Subject: [PATCH 4/5] Skip predictions below 40. --- .../androidaps/plugins/Overview/graphData/GraphData.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 a15fef8882..177e7f9642 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 @@ -77,7 +77,10 @@ public class GraphData { } if (predictions != null) { Collections.sort(predictions, (o1, o2) -> Double.compare(o1.getX(), o2.getX())); - bgListArray.addAll(predictions); + for (BgReading prediction : predictions) { + if (prediction.value >= 40) + bgListArray.add(prediction); + } } maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units); From a362eeb31b3cc6bf334178303bf9540f0062b206 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 1 May 2018 13:25:12 +0200 Subject: [PATCH 5/5] Fix unit tests for added Combo plugin w/o engineering mode. --- app/src/test/java/info/nightscout/MainAppTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/test/java/info/nightscout/MainAppTest.java b/app/src/test/java/info/nightscout/MainAppTest.java index 7aa50158f2..7bb58797be 100644 --- a/app/src/test/java/info/nightscout/MainAppTest.java +++ b/app/src/test/java/info/nightscout/MainAppTest.java @@ -76,7 +76,7 @@ public class MainAppTest { if (Config.NSCLIENT || Config.G5UPLOADER) expected = 1; // VirtualPump only else - expected = 6; + expected = 7; Assert.assertEquals(expected, mainApp.getSpecificPluginsList(PluginType.PUMP).size()); } @@ -87,7 +87,7 @@ public class MainAppTest { if (Config.NSCLIENT || Config.G5UPLOADER) expected = 1; // VirtualPump only else - expected = 6; + expected = 7; Assert.assertEquals(expected, mainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size()); } @@ -98,7 +98,7 @@ public class MainAppTest { if (Config.NSCLIENT || Config.G5UPLOADER) expected = 1; // VirtualPump only else - expected = 6; + expected = 7; Assert.assertEquals(expected, mainApp.getSpecificPluginsListByInterface(PumpInterface.class).size()); } @@ -109,7 +109,7 @@ public class MainAppTest { if (Config.NSCLIENT || Config.G5UPLOADER) expected = 1; // VirtualPump only else - expected = 6; + expected = 7; Assert.assertEquals(expected, mainApp.getSpecificPluginsVisibleInListByInterface(PumpInterface.class, PluginType.PUMP).size()); }