From 4b5189403ccb128fd8f8cc20fc8b09eef1040141 Mon Sep 17 00:00:00 2001 From: Paulus Date: Fri, 5 Jul 2019 12:12:19 +0200 Subject: [PATCH] #1851 initial commit --- .../general/overview/OverviewFragment.java | 3 ++ .../general/overview/graphData/GraphData.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 6d41303540..9afa7adda8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -1523,6 +1523,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // set manual x bounds to have nice steps graphData.formatAxis(fromTime, endTime); + // insulin activity + graphData.addActivity(fromTime, endTime, graphData.maxY); + // Treatments graphData.addTreatments(fromTime, endTime); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java index c081567a4c..9b1ff1edb9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java @@ -21,6 +21,7 @@ import java.util.List; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; @@ -344,6 +345,35 @@ public class GraphData { ? Profile.fromMgdlToUnits(bgReadingsArray.get(0).value, units) : Profile.fromMgdlToUnits(100, units); } + public void addActivity(long fromTime, long toTime, double scale) { + FixedLineGraphSeries actSeries; + List actArray = new ArrayList<>(); + double lastAct = 0; + Scale actScale = new Scale(); + IobTotal total = null; + + for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { + Profile profile = ProfileFunctions.getInstance().getProfile(time); + double act = 0d; + if (profile != null) + total = iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time, profile); + act = total.activity; + + actArray.add(new ScaledDataPoint(time, act, actScale)); + lastAct = act; + } + + ScaledDataPoint[] actData = new ScaledDataPoint[actArray.size()]; + actData = actArray.toArray(actData); + actSeries = new FixedLineGraphSeries<>(actData); + actSeries.setDrawBackground(false); + actSeries.setColor(MainApp.gc(R.color.mdtp_white)); + actSeries.setThickness(3); + actScale.setMultiplier(scale / 0.04d); //TODO for clarity should be fixed scale, but what max? For now 0.04d seems reasonable. + + addSeries(actSeries); + } + // scale in % of vertical size (like 0.3) public void addIob(long fromTime, long toTime, boolean useForScale, double scale) { FixedLineGraphSeries iobSeries;