move preparing graph series to extra class #2
This commit is contained in:
parent
d180d088f0
commit
1ad409754f
5 changed files with 251 additions and 217 deletions
|
@ -74,11 +74,9 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
|
||||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -111,9 +109,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
|
||||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
|
||||||
|
@ -1273,167 +1269,40 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
endTime = toTime;
|
endTime = toTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
LineGraphSeries<DataPoint> seriesNow, seriesNow2;
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
// **** IOB COB DEV graph ****
|
// 2nd graph
|
||||||
class DeviationDataPoint extends DataPoint {
|
// remove old data
|
||||||
public int color;
|
iobGraph.getSeries().clear();
|
||||||
|
|
||||||
public DeviationDataPoint(double x, double y, int color) {
|
GraphData secondGraphData = new GraphData();
|
||||||
super(x, y);
|
|
||||||
this.color = color;
|
boolean useIobForScale = false;
|
||||||
}
|
boolean useCobForScale = false;
|
||||||
|
boolean useDevForScale = false;
|
||||||
|
boolean useRatioForScale = false;
|
||||||
|
|
||||||
|
if (showIobView.isChecked()) {
|
||||||
|
useIobForScale = true;
|
||||||
|
} else if (showCobView.isChecked()) {
|
||||||
|
useCobForScale = true;
|
||||||
|
} else if (showDeviationsView.isChecked()) {
|
||||||
|
useDevForScale = true;
|
||||||
|
} else if (showRatiosView.isChecked()) {
|
||||||
|
useRatioForScale = true;
|
||||||
}
|
}
|
||||||
FixedLineGraphSeries<DataPoint> iobSeries;
|
|
||||||
FixedLineGraphSeries<DataPoint> cobSeries;
|
if (showIobView.isChecked())
|
||||||
BarGraphSeries<DeviationDataPoint> devSeries;
|
secondGraphData.addIob(iobGraph, fromTime, now, useIobForScale, 1d);
|
||||||
LineGraphSeries<DataPoint> ratioSeries;
|
if (showCobView.isChecked())
|
||||||
Double maxIobValueFound = 0d;
|
secondGraphData.addCob(iobGraph, fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d);
|
||||||
Double maxCobValueFound = 0d;
|
if (showDeviationsView.isChecked())
|
||||||
Double maxDevValueFound = 0d;
|
secondGraphData.addDeviations(iobGraph, fromTime, now, useDevForScale, 1d);
|
||||||
Double maxRatioValueFound = 0d;
|
if (showRatiosView.isChecked())
|
||||||
|
secondGraphData.addRatio(iobGraph, fromTime, now, useRatioForScale, 1d);
|
||||||
|
|
||||||
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
||||||
//Date start = new Date();
|
|
||||||
List<DataPoint> iobArray = new ArrayList<>();
|
|
||||||
List<DataPoint> cobArray = new ArrayList<>();
|
|
||||||
List<DeviationDataPoint> devArray = new ArrayList<>();
|
|
||||||
List<DataPoint> ratioArray = new ArrayList<>();
|
|
||||||
double lastIob = 0;
|
|
||||||
int lastCob = 0;
|
|
||||||
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
|
||||||
if (showIobView.isChecked()) {
|
|
||||||
double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob;
|
|
||||||
if (Math.abs(lastIob - iob) > 0.02) {
|
|
||||||
if (Math.abs(lastIob - iob) > 0.2)
|
|
||||||
iobArray.add(new DataPoint(time, lastIob));
|
|
||||||
iobArray.add(new DataPoint(time, iob));
|
|
||||||
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob));
|
|
||||||
lastIob = iob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
|
||||||
if (autosensData != null && showCobView.isChecked()) {
|
|
||||||
int cob = (int) autosensData.cob;
|
|
||||||
if (cob != lastCob) {
|
|
||||||
if (autosensData.carbsFromBolus > 0)
|
|
||||||
cobArray.add(new DataPoint(time, lastCob));
|
|
||||||
cobArray.add(new DataPoint(time, cob));
|
|
||||||
maxCobValueFound = Math.max(maxCobValueFound, cob);
|
|
||||||
lastCob = cob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (autosensData != null && showDeviationsView.isChecked()) {
|
|
||||||
int color = Color.BLACK; // "="
|
|
||||||
if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY;
|
|
||||||
if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN;
|
|
||||||
if (autosensData.pastSensitivity.equals("-")) color = Color.RED;
|
|
||||||
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color));
|
|
||||||
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
|
||||||
}
|
|
||||||
if (autosensData != null && showRatiosView.isChecked()) {
|
|
||||||
ratioArray.add(new DataPoint(time, autosensData.autosensRatio));
|
|
||||||
maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Profiler.log(log, "IOB processed", start);
|
|
||||||
DataPoint[] iobData = new DataPoint[iobArray.size()];
|
|
||||||
iobData = iobArray.toArray(iobData);
|
|
||||||
iobSeries = new FixedLineGraphSeries<>(iobData);
|
|
||||||
iobSeries.setDrawBackground(true);
|
|
||||||
iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.iob)); //50%
|
|
||||||
iobSeries.setColor(MainApp.sResources.getColor(R.color.iob));
|
|
||||||
iobSeries.setThickness(3);
|
|
||||||
|
|
||||||
|
|
||||||
Double maxByScale = null;
|
|
||||||
int graphsToShow = 0;
|
|
||||||
if (showIobView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxIobValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
if (showCobView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxCobValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
if (showDeviationsView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxDevValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
if (showRatiosView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxRatioValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (graphsToShow > 1) {
|
|
||||||
if (!maxByScale.equals(maxCobValueFound)) {
|
|
||||||
List<DataPoint> cobArrayRescaled = new ArrayList<>();
|
|
||||||
for (int ci = 0; ci < cobArray.size(); ci++) {
|
|
||||||
cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxByScale / maxCobValueFound / 2));
|
|
||||||
}
|
|
||||||
cobArray = cobArrayRescaled;
|
|
||||||
}
|
|
||||||
if (!maxByScale.equals(maxDevValueFound)) {
|
|
||||||
List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
|
|
||||||
for (int ci = 0; ci < devArray.size(); ci++) {
|
|
||||||
devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxByScale / maxDevValueFound, devArray.get(ci).color));
|
|
||||||
}
|
|
||||||
devArray = devArrayRescaled;
|
|
||||||
}
|
|
||||||
if (!maxByScale.equals(maxRatioValueFound)) {
|
|
||||||
List<DataPoint> ratioArrayRescaled = new ArrayList<>();
|
|
||||||
for (int ci = 0; ci < ratioArray.size(); ci++) {
|
|
||||||
ratioArrayRescaled.add(new DataPoint(ratioArray.get(ci).getX(), (ratioArray.get(ci).getY() - 1) * maxByScale / maxRatioValueFound));
|
|
||||||
}
|
|
||||||
ratioArray = ratioArrayRescaled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// COB
|
|
||||||
DataPoint[] cobData = new DataPoint[cobArray.size()];
|
|
||||||
cobData = cobArray.toArray(cobData);
|
|
||||||
cobSeries = new FixedLineGraphSeries<>(cobData);
|
|
||||||
cobSeries.setDrawBackground(true);
|
|
||||||
cobSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
|
|
||||||
cobSeries.setColor(MainApp.sResources.getColor(R.color.cob));
|
|
||||||
cobSeries.setThickness(3);
|
|
||||||
|
|
||||||
// DEVIATIONS
|
|
||||||
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
|
|
||||||
devData = devArray.toArray(devData);
|
|
||||||
devSeries = new BarGraphSeries<>(devData);
|
|
||||||
devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
|
|
||||||
@Override
|
|
||||||
public int get(DeviationDataPoint data) {
|
|
||||||
return data.color;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// RATIOS
|
|
||||||
DataPoint[] ratioData = new DataPoint[ratioArray.size()];
|
|
||||||
ratioData = ratioArray.toArray(ratioData);
|
|
||||||
ratioSeries = new LineGraphSeries<>(ratioData);
|
|
||||||
ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio));
|
|
||||||
ratioSeries.setThickness(3);
|
|
||||||
|
|
||||||
iobGraph.getSeries().clear();
|
|
||||||
|
|
||||||
if (showIobView.isChecked() && iobData.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(iobSeries, iobGraph);
|
|
||||||
}
|
|
||||||
if (showCobView.isChecked() && cobData.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(cobSeries, iobGraph);
|
|
||||||
}
|
|
||||||
if (showDeviationsView.isChecked() && devData.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(devSeries, iobGraph);
|
|
||||||
}
|
|
||||||
if (showRatiosView.isChecked() && ratioData.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(ratioSeries, iobGraph);
|
|
||||||
}
|
|
||||||
iobGraph.setVisibility(View.VISIBLE);
|
iobGraph.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
iobGraph.setVisibility(View.GONE);
|
iobGraph.setVisibility(View.GONE);
|
||||||
|
@ -1454,60 +1323,28 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null);
|
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null);
|
||||||
|
|
||||||
// set manual x bounds to have nice steps
|
// set manual x bounds to have nice steps
|
||||||
bgGraph.getViewport().setMaxX(endTime);
|
graphData.formatAxis(bgGraph, fromTime, endTime);
|
||||||
bgGraph.getViewport().setMinX(fromTime);
|
secondGraphData.formatAxis(iobGraph, fromTime, endTime);
|
||||||
bgGraph.getViewport().setXAxisBoundsManual(true);
|
|
||||||
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
// Treatments
|
// Treatments
|
||||||
graphData.addTreatmnets(bgGraph, fromTime, endTime);
|
graphData.addTreatments(bgGraph, fromTime, endTime);
|
||||||
|
|
||||||
// add basal data
|
// add basal data
|
||||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
||||||
graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxX / 1.2d);
|
graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxY / 1.2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// **** NOW line ****
|
// **** NOW line ****
|
||||||
DataPoint[] nowPoints = new DataPoint[]{
|
graphData.addNowLine(bgGraph, now);
|
||||||
new DataPoint(now, 0),
|
secondGraphData.addNowLine(iobGraph, now);
|
||||||
new DataPoint(now, graphData.maxX)
|
|
||||||
};
|
// finaly enforce drawing of graphs
|
||||||
addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph);
|
|
||||||
seriesNow.setDrawDataPoints(false);
|
|
||||||
DataPoint[] nowPoints2 = new DataPoint[]{
|
|
||||||
new DataPoint(now, 0),
|
|
||||||
new DataPoint(now, maxIobValueFound)
|
|
||||||
};
|
|
||||||
addSeriesWithoutInvalidate(seriesNow2 = new LineGraphSeries<>(nowPoints2), iobGraph);
|
|
||||||
seriesNow2.setDrawDataPoints(false);
|
|
||||||
//seriesNow.setThickness(1);
|
|
||||||
// custom paint to make a dotted line
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
|
||||||
paint.setStrokeWidth(2);
|
|
||||||
paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));
|
|
||||||
paint.setColor(Color.WHITE);
|
|
||||||
seriesNow.setCustomPaint(paint);
|
|
||||||
seriesNow2.setCustomPaint(paint);
|
|
||||||
bgGraph.onDataChanged(false, false);
|
bgGraph.onDataChanged(false, false);
|
||||||
iobGraph.onDataChanged(false, false);
|
iobGraph.onDataChanged(false, false);
|
||||||
|
|
||||||
Profiler.log(log, from, updateGUIStart);
|
Profiler.log(log, from, updateGUIStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSeriesWithoutInvalidate(Series s, GraphView graph) {
|
|
||||||
s.onGraphViewAttached(graph);
|
|
||||||
graph.getSeries().add(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
|
static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
package info.nightscout.androidaps.plugins.Overview.graphData;
|
package info.nightscout.androidaps.plugins.Overview.graphData;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.DashPathEffect;
|
import android.graphics.DashPathEffect;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.jjoe64.graphview.LabelFormatter;
|
import com.jjoe64.graphview.ValueDependentColor;
|
||||||
import com.jjoe64.graphview.Viewport;
|
import com.jjoe64.graphview.series.BarGraphSeries;
|
||||||
import com.jjoe64.graphview.series.DataPoint;
|
import com.jjoe64.graphview.series.DataPoint;
|
||||||
import com.jjoe64.graphview.series.LineGraphSeries;
|
import com.jjoe64.graphview.series.LineGraphSeries;
|
||||||
import com.jjoe64.graphview.series.Series;
|
import com.jjoe64.graphview.series.Series;
|
||||||
|
|
||||||
import org.mozilla.javascript.tools.debugger.Main;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -25,15 +24,18 @@ import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +48,7 @@ public class GraphData {
|
||||||
units = MainApp.getConfigBuilder().getProfileUnits();
|
units = MainApp.getConfigBuilder().getProfileUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double maxX = 0;
|
public double maxY = 0;
|
||||||
private List<BgReading> bgReadingsArray;
|
private List<BgReading> bgReadingsArray;
|
||||||
private String units;
|
private String units;
|
||||||
|
|
||||||
|
@ -82,9 +84,9 @@ public class GraphData {
|
||||||
addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(bg));
|
addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(bg));
|
||||||
}
|
}
|
||||||
|
|
||||||
maxX = maxBgValue;
|
maxY = maxBgValue;
|
||||||
// set manual y bounds to have nice steps
|
// set manual y bounds to have nice steps
|
||||||
bgGraph.getViewport().setMaxY(maxX);
|
bgGraph.getViewport().setMaxY(maxY);
|
||||||
bgGraph.getViewport().setMinY(0);
|
bgGraph.getViewport().setMinY(0);
|
||||||
bgGraph.getViewport().setYAxisBoundsManual(true);
|
bgGraph.getViewport().setYAxisBoundsManual(true);
|
||||||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines);
|
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines);
|
||||||
|
@ -205,7 +207,7 @@ public class GraphData {
|
||||||
absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal));
|
absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal));
|
||||||
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
|
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
|
||||||
|
|
||||||
basalScale.setValue(maxX * scale / maxBasalValueFound);
|
basalScale.setMultiplier(maxY * scale / maxBasalValueFound);
|
||||||
|
|
||||||
addSeriesWithoutInvalidate(bgGraph, baseBasalsSeries);
|
addSeriesWithoutInvalidate(bgGraph, baseBasalsSeries);
|
||||||
addSeriesWithoutInvalidate(bgGraph, tempBasalsSeries);
|
addSeriesWithoutInvalidate(bgGraph, tempBasalsSeries);
|
||||||
|
@ -213,7 +215,7 @@ public class GraphData {
|
||||||
addSeriesWithoutInvalidate(bgGraph, absoluteBasalsLineSeries);
|
addSeriesWithoutInvalidate(bgGraph, absoluteBasalsLineSeries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTreatmnets(GraphView bgGraph, long fromTime, long endTime) {
|
public void addTreatments(GraphView bgGraph, long fromTime, long endTime) {
|
||||||
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
||||||
|
|
||||||
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
|
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
|
||||||
|
@ -261,7 +263,8 @@ public class GraphData {
|
||||||
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
|
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
|
||||||
if (treatmentsArray.length > 0) {
|
if (treatmentsArray.length > 0) {
|
||||||
addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(treatmentsArray));
|
addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(treatmentsArray));
|
||||||
} }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double getNearestBg(long date) {
|
double getNearestBg(long date) {
|
||||||
double bg = 0;
|
double bg = 0;
|
||||||
|
@ -274,10 +277,191 @@ public class GraphData {
|
||||||
return bg;
|
return bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scale in % of vertical size (like 0.3)
|
||||||
|
public void addIob(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) {
|
||||||
|
FixedLineGraphSeries<ScaledDataPoint> iobSeries;
|
||||||
|
List<ScaledDataPoint> iobArray = new ArrayList<>();
|
||||||
|
Double maxIobValueFound = 0d;
|
||||||
|
double lastIob = 0;
|
||||||
|
Scale iobScale = new Scale();
|
||||||
|
|
||||||
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
|
double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob;
|
||||||
|
if (Math.abs(lastIob - iob) > 0.02) {
|
||||||
|
if (Math.abs(lastIob - iob) > 0.2)
|
||||||
|
iobArray.add(new ScaledDataPoint(time, lastIob, iobScale));
|
||||||
|
iobArray.add(new ScaledDataPoint(time, iob, iobScale));
|
||||||
|
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob));
|
||||||
|
lastIob = iob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScaledDataPoint[] iobData = new ScaledDataPoint[iobArray.size()];
|
||||||
|
iobData = iobArray.toArray(iobData);
|
||||||
|
iobSeries = new FixedLineGraphSeries<>(iobData);
|
||||||
|
iobSeries.setDrawBackground(true);
|
||||||
|
iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.iob)); //50%
|
||||||
|
iobSeries.setColor(MainApp.sResources.getColor(R.color.iob));
|
||||||
|
iobSeries.setThickness(3);
|
||||||
|
|
||||||
|
if (useForScale)
|
||||||
|
maxY = maxIobValueFound;
|
||||||
|
|
||||||
|
iobScale.setMultiplier(maxY * scale / maxIobValueFound);
|
||||||
|
|
||||||
|
addSeriesWithoutInvalidate(graph, iobSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale in % of vertical size (like 0.3)
|
||||||
|
public void addCob(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) {
|
||||||
|
FixedLineGraphSeries<ScaledDataPoint> cobSeries;
|
||||||
|
List<ScaledDataPoint> cobArray = new ArrayList<>();
|
||||||
|
Double maxCobValueFound = 0d;
|
||||||
|
int lastCob = 0;
|
||||||
|
Scale cobScale = new Scale();
|
||||||
|
|
||||||
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
|
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||||
|
if (autosensData != null) {
|
||||||
|
int cob = (int) autosensData.cob;
|
||||||
|
if (cob != lastCob) {
|
||||||
|
if (autosensData.carbsFromBolus > 0)
|
||||||
|
cobArray.add(new ScaledDataPoint(time, lastCob, cobScale));
|
||||||
|
cobArray.add(new ScaledDataPoint(time, cob, cobScale));
|
||||||
|
maxCobValueFound = Math.max(maxCobValueFound, cob);
|
||||||
|
lastCob = cob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// COB
|
||||||
|
ScaledDataPoint[] cobData = new ScaledDataPoint[cobArray.size()];
|
||||||
|
cobData = cobArray.toArray(cobData);
|
||||||
|
cobSeries = new FixedLineGraphSeries<>(cobData);
|
||||||
|
cobSeries.setDrawBackground(true);
|
||||||
|
cobSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
|
||||||
|
cobSeries.setColor(MainApp.sResources.getColor(R.color.cob));
|
||||||
|
cobSeries.setThickness(3);
|
||||||
|
|
||||||
|
if (useForScale)
|
||||||
|
maxY = maxCobValueFound;
|
||||||
|
|
||||||
|
cobScale.setMultiplier(maxY * scale / maxCobValueFound);
|
||||||
|
|
||||||
|
addSeriesWithoutInvalidate(graph, cobSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale in % of vertical size (like 0.3)
|
||||||
|
public void addDeviations(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) {
|
||||||
|
class DeviationDataPoint extends ScaledDataPoint {
|
||||||
|
public int color;
|
||||||
|
|
||||||
|
public DeviationDataPoint(double x, double y, int color, Scale scale) {
|
||||||
|
super(x, y, scale);
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BarGraphSeries<DeviationDataPoint> devSeries;
|
||||||
|
List<DeviationDataPoint> devArray = new ArrayList<>();
|
||||||
|
Double maxDevValueFound = 0d;
|
||||||
|
Scale devScale = new Scale();
|
||||||
|
|
||||||
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
|
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||||
|
if (autosensData != null) {
|
||||||
|
int color = Color.BLACK; // "="
|
||||||
|
if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY;
|
||||||
|
if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN;
|
||||||
|
if (autosensData.pastSensitivity.equals("-")) color = Color.RED;
|
||||||
|
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color, devScale));
|
||||||
|
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEVIATIONS
|
||||||
|
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
|
||||||
|
devData = devArray.toArray(devData);
|
||||||
|
devSeries = new BarGraphSeries<>(devData);
|
||||||
|
devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
|
||||||
|
@Override
|
||||||
|
public int get(DeviationDataPoint data) {
|
||||||
|
return data.color;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (useForScale)
|
||||||
|
maxY = maxDevValueFound;
|
||||||
|
|
||||||
|
devScale.setMultiplier(maxY * scale / maxDevValueFound);
|
||||||
|
|
||||||
|
addSeriesWithoutInvalidate(graph, devSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale in % of vertical size (like 0.3)
|
||||||
|
public void addRatio(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) {
|
||||||
|
LineGraphSeries<DataPoint> ratioSeries;
|
||||||
|
List<DataPoint> ratioArray = new ArrayList<>();
|
||||||
|
Double maxRatioValueFound = 0d;
|
||||||
|
Scale ratioScale = new Scale(-1d);
|
||||||
|
|
||||||
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
|
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||||
|
if (autosensData != null) {
|
||||||
|
ratioArray.add(new DataPoint(time, autosensData.autosensRatio));
|
||||||
|
maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RATIOS
|
||||||
|
DataPoint[] ratioData = new DataPoint[ratioArray.size()];
|
||||||
|
ratioData = ratioArray.toArray(ratioData);
|
||||||
|
ratioSeries = new LineGraphSeries<>(ratioData);
|
||||||
|
ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio));
|
||||||
|
ratioSeries.setThickness(3);
|
||||||
|
|
||||||
|
if (useForScale)
|
||||||
|
maxY = maxRatioValueFound;
|
||||||
|
|
||||||
|
ratioScale.setMultiplier(maxY * scale / maxRatioValueFound);
|
||||||
|
|
||||||
|
addSeriesWithoutInvalidate(graph, ratioSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale in % of vertical size (like 0.3)
|
||||||
|
public void addNowLine(GraphView graph, long now) {
|
||||||
|
LineGraphSeries<DataPoint> seriesNow;
|
||||||
|
DataPoint[] nowPoints = new DataPoint[]{
|
||||||
|
new DataPoint(now, 0),
|
||||||
|
new DataPoint(now, maxY)
|
||||||
|
};
|
||||||
|
|
||||||
|
seriesNow = new LineGraphSeries<>(nowPoints);
|
||||||
|
seriesNow.setDrawDataPoints(false);
|
||||||
|
// custom paint to make a dotted line
|
||||||
|
Paint paint = new Paint();
|
||||||
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
|
paint.setStrokeWidth(2);
|
||||||
|
paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));
|
||||||
|
paint.setColor(Color.WHITE);
|
||||||
|
seriesNow.setCustomPaint(paint);
|
||||||
|
|
||||||
|
addSeriesWithoutInvalidate(graph, seriesNow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void formatAxis(GraphView graph, long fromTime, long endTime) {
|
||||||
|
graph.getViewport().setMaxX(endTime);
|
||||||
|
graph.getViewport().setMinX(fromTime);
|
||||||
|
graph.getViewport().setXAxisBoundsManual(true);
|
||||||
|
graph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter("HH"));
|
||||||
|
graph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||||
|
}
|
||||||
|
|
||||||
private void addSeriesWithoutInvalidate(GraphView bgGraph, Series s) {
|
private void addSeriesWithoutInvalidate(GraphView bgGraph, Series s) {
|
||||||
s.onGraphViewAttached(bgGraph);
|
if (!s.isEmpty()) {
|
||||||
bgGraph.getSeries().add(s);
|
s.onGraphViewAttached(bgGraph);
|
||||||
|
bgGraph.getSeries().add(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,26 @@ package info.nightscout.androidaps.plugins.Overview.graphExtensions;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Scale {
|
public class Scale {
|
||||||
private double value;
|
private double multiplier;
|
||||||
|
private double shift;
|
||||||
|
|
||||||
public void setValue(double value) {
|
public Scale() {
|
||||||
this.value = value;
|
shift = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getValue() {
|
public Scale(double shift) {
|
||||||
return value;
|
this.shift = shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMultiplier(double value) {
|
||||||
|
this.multiplier = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double transform(double original) {
|
||||||
|
return original * multiplier + shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getShift() {
|
||||||
|
return shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class ScaledDataPoint implements DataPointInterface, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getY() {
|
public double getY() {
|
||||||
return y * scale.getValue();
|
return scale.transform(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class TimeAsXAxisLabelFormatter extends DefaultLabelFormatter {
|
||||||
|
|
||||||
protected final String mFormat;
|
protected final String mFormat;
|
||||||
|
|
||||||
public TimeAsXAxisLabelFormatter(Context context, String format) {
|
public TimeAsXAxisLabelFormatter(String format) {
|
||||||
mFormat = format;
|
mFormat = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue