move preparing graph series to extra class #2
This commit is contained in:
parent
55b1dcb992
commit
19f107fe53
4 changed files with 182 additions and 121 deletions
|
@ -1440,19 +1440,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove old data from graph
|
// remove old data from graph
|
||||||
bgGraph.getSecondScale().getSeries().clear();
|
|
||||||
bgGraph.getSeries().clear();
|
bgGraph.getSeries().clear();
|
||||||
|
|
||||||
GraphData graphData = new GraphData(bgGraph);
|
GraphData graphData = new GraphData();
|
||||||
|
|
||||||
// **** In range Area ****
|
// **** In range Area ****
|
||||||
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
graphData.addInRangeArea(bgGraph, fromTime, endTime, lowLine, highLine);
|
||||||
|
|
||||||
// **** BG ****
|
// **** BG ****
|
||||||
if (showPrediction)
|
if (showPrediction)
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, (DetermineBasalResultAMA) finalLastRun.constraintsProcessed);
|
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, (DetermineBasalResultAMA) finalLastRun.constraintsProcessed);
|
||||||
else
|
else
|
||||||
graphData.addBgReadings(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);
|
bgGraph.getViewport().setMaxX(endTime);
|
||||||
|
@ -1468,70 +1467,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
|
|
||||||
// Treatments
|
// Treatments
|
||||||
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
graphData.addTreatmnets(bgGraph, fromTime, endTime);
|
||||||
|
|
||||||
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
|
|
||||||
|
|
||||||
for (int tx = 0; tx < treatments.size(); tx++) {
|
|
||||||
Treatment t = treatments.get(tx);
|
|
||||||
if (t.getX() < fromTime || t.getX() > endTime) continue;
|
|
||||||
t.setY(graphData.getNearestBg((long) t.getX()));
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProfileSwitch
|
|
||||||
List<ProfileSwitch> profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList();
|
|
||||||
|
|
||||||
for (int tx = 0; tx < profileSwitches.size(); tx++) {
|
|
||||||
DataPointWithLabelInterface t = profileSwitches.get(tx);
|
|
||||||
if (t.getX() < fromTime || t.getX() > endTime) continue;
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extended bolus
|
|
||||||
if (!pump.isFakingTempsByExtendedBoluses()) {
|
|
||||||
List<ExtendedBolus> extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList();
|
|
||||||
|
|
||||||
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
|
||||||
DataPointWithLabelInterface t = extendedBoluses.get(tx);
|
|
||||||
if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue;
|
|
||||||
if (t.getDuration() == 0) continue;
|
|
||||||
t.setY(graphData.getNearestBg((long) t.getX()));
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Careportal
|
|
||||||
List<CareportalEvent> careportalEvents = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, true);
|
|
||||||
|
|
||||||
for (int tx = 0; tx < careportalEvents.size(); tx++) {
|
|
||||||
DataPointWithLabelInterface t = careportalEvents.get(tx);
|
|
||||||
if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue;
|
|
||||||
t.setY(graphData.getNearestBg((long) t.getX()));
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()];
|
|
||||||
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
|
|
||||||
if (treatmentsArray.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(treatmentsArray), bgGraph);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set manual y bounds to have nice steps
|
|
||||||
bgGraph.getViewport().setMaxY(graphData.maxBgValue);
|
|
||||||
bgGraph.getViewport().setMinY(0);
|
|
||||||
bgGraph.getViewport().setYAxisBoundsManual(true);
|
|
||||||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(graphData.numOfVertLines);
|
|
||||||
|
|
||||||
// add basal data
|
// add basal data
|
||||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
||||||
graphData.addBasalsToSecondScale(fromTime, now, graphData.maxBgValue / lowLine * 1.2d);
|
graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxX / 1.2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// **** NOW line ****
|
// **** NOW line ****
|
||||||
DataPoint[] nowPoints = new DataPoint[]{
|
DataPoint[] nowPoints = new DataPoint[]{
|
||||||
new DataPoint(now, 0),
|
new DataPoint(now, 0),
|
||||||
new DataPoint(now, graphData.maxBgValue)
|
new DataPoint(now, graphData.maxX)
|
||||||
};
|
};
|
||||||
addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph);
|
addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph);
|
||||||
seriesNow.setDrawDataPoints(false);
|
seriesNow.setDrawDataPoints(false);
|
||||||
|
|
|
@ -10,6 +10,8 @@ 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;
|
||||||
|
@ -19,6 +21,10 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
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.Treatment;
|
||||||
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;
|
||||||
|
@ -26,6 +32,8 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeri
|
||||||
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.PointsWithLabelGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,19 +42,16 @@ import info.nightscout.utils.Round;
|
||||||
|
|
||||||
public class GraphData {
|
public class GraphData {
|
||||||
|
|
||||||
public GraphData(GraphView bgGraph) {
|
public GraphData() {
|
||||||
this.bgGraph = bgGraph;
|
|
||||||
units = MainApp.getConfigBuilder().getProfileUnits();
|
units = MainApp.getConfigBuilder().getProfileUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GraphView bgGraph;
|
public double maxX = 0;
|
||||||
public double maxBgValue = 0d;
|
|
||||||
public int numOfVertLines;
|
|
||||||
private List<BgReading> bgReadingsArray;
|
private List<BgReading> bgReadingsArray;
|
||||||
private String units;
|
private String units;
|
||||||
|
|
||||||
public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, DetermineBasalResultAMA amaResult) {
|
public void addBgReadings(GraphView bgGraph, long fromTime, long toTime, double lowLine, double highLine, DetermineBasalResultAMA amaResult) {
|
||||||
maxBgValue = 0d;
|
double maxBgValue = 0d;
|
||||||
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
||||||
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -68,18 +73,25 @@ public class GraphData {
|
||||||
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
|
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
|
||||||
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
|
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
|
||||||
if (highLine > maxBgValue) maxBgValue = highLine;
|
if (highLine > maxBgValue) maxBgValue = highLine;
|
||||||
numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
|
int numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
|
||||||
|
|
||||||
DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()];
|
DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()];
|
||||||
bg = bgListArray.toArray(bg);
|
bg = bgListArray.toArray(bg);
|
||||||
|
|
||||||
if (bg.length > 0) {
|
if (bg.length > 0) {
|
||||||
addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(bg));
|
addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(bg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxX = maxBgValue;
|
||||||
|
// set manual y bounds to have nice steps
|
||||||
|
bgGraph.getViewport().setMaxY(maxX);
|
||||||
|
bgGraph.getViewport().setMinY(0);
|
||||||
|
bgGraph.getViewport().setYAxisBoundsManual(true);
|
||||||
|
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addInRangeArea(long fromTime, long toTime, double lowLine, double highLine) {
|
public void addInRangeArea(GraphView bgGraph, long fromTime, long toTime, double lowLine, double highLine) {
|
||||||
AreaGraphSeries<DoubleDataPoint> inRangeAreaSeries;
|
AreaGraphSeries<DoubleDataPoint> inRangeAreaSeries;
|
||||||
|
|
||||||
DoubleDataPoint[] inRangeAreaDataPoints = new DoubleDataPoint[]{
|
DoubleDataPoint[] inRangeAreaDataPoints = new DoubleDataPoint[]{
|
||||||
|
@ -87,24 +99,26 @@ public class GraphData {
|
||||||
new DoubleDataPoint(toTime, lowLine, highLine)
|
new DoubleDataPoint(toTime, lowLine, highLine)
|
||||||
};
|
};
|
||||||
inRangeAreaSeries = new AreaGraphSeries<>(inRangeAreaDataPoints);
|
inRangeAreaSeries = new AreaGraphSeries<>(inRangeAreaDataPoints);
|
||||||
addSeriesWithoutInvalidate(inRangeAreaSeries);
|
addSeriesWithoutInvalidate(bgGraph, inRangeAreaSeries);
|
||||||
inRangeAreaSeries.setColor(0);
|
inRangeAreaSeries.setColor(0);
|
||||||
inRangeAreaSeries.setDrawBackground(true);
|
inRangeAreaSeries.setDrawBackground(true);
|
||||||
inRangeAreaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground));
|
inRangeAreaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBasalsToSecondScale(long fromTime, long toTime, double scale) {
|
// scale in % of vertical size (like 0.3)
|
||||||
LineGraphSeries<DataPoint> basalsLineSeries;
|
public void addBasals(GraphView bgGraph, long fromTime, long toTime, double scale) {
|
||||||
LineGraphSeries<DataPoint> absoluteBasalsLineSeries;
|
LineGraphSeries<ScaledDataPoint> basalsLineSeries;
|
||||||
LineGraphSeries<DataPoint> baseBasalsSeries;
|
LineGraphSeries<ScaledDataPoint> absoluteBasalsLineSeries;
|
||||||
LineGraphSeries<DataPoint> tempBasalsSeries;
|
LineGraphSeries<ScaledDataPoint> baseBasalsSeries;
|
||||||
|
LineGraphSeries<ScaledDataPoint> tempBasalsSeries;
|
||||||
|
|
||||||
Double maxBasalValueFound = 0d;
|
double maxBasalValueFound = 0d;
|
||||||
|
Scale basalScale = new Scale();
|
||||||
|
|
||||||
List<DataPoint> baseBasalArray = new ArrayList<>();
|
List<ScaledDataPoint> baseBasalArray = new ArrayList<>();
|
||||||
List<DataPoint> tempBasalArray = new ArrayList<>();
|
List<ScaledDataPoint> tempBasalArray = new ArrayList<>();
|
||||||
List<DataPoint> basalLineArray = new ArrayList<>();
|
List<ScaledDataPoint> basalLineArray = new ArrayList<>();
|
||||||
List<DataPoint> absoluteBasalLineArray = new ArrayList<>();
|
List<ScaledDataPoint> absoluteBasalLineArray = new ArrayList<>();
|
||||||
double lastLineBasal = 0;
|
double lastLineBasal = 0;
|
||||||
double lastAbsoluteLineBasal = 0;
|
double lastAbsoluteLineBasal = 0;
|
||||||
double lastBaseBasal = 0;
|
double lastBaseBasal = 0;
|
||||||
|
@ -118,33 +132,33 @@ public class GraphData {
|
||||||
if (basalData.isTempBasalRunning) {
|
if (basalData.isTempBasalRunning) {
|
||||||
absoluteLineValue = tempBasalValue = basalData.tempBasalAbsolute;
|
absoluteLineValue = tempBasalValue = basalData.tempBasalAbsolute;
|
||||||
if (tempBasalValue != lastTempBasal) {
|
if (tempBasalValue != lastTempBasal) {
|
||||||
tempBasalArray.add(new DataPoint(time, lastTempBasal));
|
tempBasalArray.add(new ScaledDataPoint(time, lastTempBasal, basalScale));
|
||||||
tempBasalArray.add(new DataPoint(time, basal = tempBasalValue));
|
tempBasalArray.add(new ScaledDataPoint(time, basal = tempBasalValue, basalScale));
|
||||||
}
|
}
|
||||||
if (lastBaseBasal != 0d) {
|
if (lastBaseBasal != 0d) {
|
||||||
baseBasalArray.add(new DataPoint(time, lastBaseBasal));
|
baseBasalArray.add(new ScaledDataPoint(time, lastBaseBasal, basalScale));
|
||||||
baseBasalArray.add(new DataPoint(time, 0d));
|
baseBasalArray.add(new ScaledDataPoint(time, 0d, basalScale));
|
||||||
lastBaseBasal = 0d;
|
lastBaseBasal = 0d;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (baseBasalValue != lastBaseBasal) {
|
if (baseBasalValue != lastBaseBasal) {
|
||||||
baseBasalArray.add(new DataPoint(time, lastBaseBasal));
|
baseBasalArray.add(new ScaledDataPoint(time, lastBaseBasal, basalScale));
|
||||||
baseBasalArray.add(new DataPoint(time, basal = baseBasalValue));
|
baseBasalArray.add(new ScaledDataPoint(time, basal = baseBasalValue, basalScale));
|
||||||
lastBaseBasal = baseBasalValue;
|
lastBaseBasal = baseBasalValue;
|
||||||
}
|
}
|
||||||
if (lastTempBasal != 0) {
|
if (lastTempBasal != 0) {
|
||||||
tempBasalArray.add(new DataPoint(time, lastTempBasal));
|
tempBasalArray.add(new ScaledDataPoint(time, lastTempBasal, basalScale));
|
||||||
tempBasalArray.add(new DataPoint(time, 0d));
|
tempBasalArray.add(new ScaledDataPoint(time, 0d, basalScale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseBasalValue != lastLineBasal) {
|
if (baseBasalValue != lastLineBasal) {
|
||||||
basalLineArray.add(new DataPoint(time, lastLineBasal));
|
basalLineArray.add(new ScaledDataPoint(time, lastLineBasal, basalScale));
|
||||||
basalLineArray.add(new DataPoint(time, baseBasalValue));
|
basalLineArray.add(new ScaledDataPoint(time, baseBasalValue, basalScale));
|
||||||
}
|
}
|
||||||
if (absoluteLineValue != lastAbsoluteLineBasal) {
|
if (absoluteLineValue != lastAbsoluteLineBasal) {
|
||||||
absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal));
|
absoluteBasalLineArray.add(new ScaledDataPoint(time, lastAbsoluteLineBasal, basalScale));
|
||||||
absoluteBasalLineArray.add(new DataPoint(time, basal));
|
absoluteBasalLineArray.add(new ScaledDataPoint(time, basal, basalScale));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastAbsoluteLineBasal = absoluteLineValue;
|
lastAbsoluteLineBasal = absoluteLineValue;
|
||||||
|
@ -153,26 +167,26 @@ public class GraphData {
|
||||||
maxBasalValueFound = Math.max(maxBasalValueFound, basal);
|
maxBasalValueFound = Math.max(maxBasalValueFound, basal);
|
||||||
}
|
}
|
||||||
|
|
||||||
basalLineArray.add(new DataPoint(toTime, lastLineBasal));
|
basalLineArray.add(new ScaledDataPoint(toTime, lastLineBasal, basalScale));
|
||||||
baseBasalArray.add(new DataPoint(toTime, lastBaseBasal));
|
baseBasalArray.add(new ScaledDataPoint(toTime, lastBaseBasal, basalScale));
|
||||||
tempBasalArray.add(new DataPoint(toTime, lastTempBasal));
|
tempBasalArray.add(new ScaledDataPoint(toTime, lastTempBasal, basalScale));
|
||||||
absoluteBasalLineArray.add(new DataPoint(toTime, lastAbsoluteLineBasal));
|
absoluteBasalLineArray.add(new ScaledDataPoint(toTime, lastAbsoluteLineBasal, basalScale));
|
||||||
|
|
||||||
DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()];
|
ScaledDataPoint[] baseBasal = new ScaledDataPoint[baseBasalArray.size()];
|
||||||
baseBasal = baseBasalArray.toArray(baseBasal);
|
baseBasal = baseBasalArray.toArray(baseBasal);
|
||||||
baseBasalsSeries = new LineGraphSeries<>(baseBasal);
|
baseBasalsSeries = new LineGraphSeries<>(baseBasal);
|
||||||
baseBasalsSeries.setDrawBackground(true);
|
baseBasalsSeries.setDrawBackground(true);
|
||||||
baseBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.basebasal));
|
baseBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.basebasal));
|
||||||
baseBasalsSeries.setThickness(0);
|
baseBasalsSeries.setThickness(0);
|
||||||
|
|
||||||
DataPoint[] tempBasal = new DataPoint[tempBasalArray.size()];
|
ScaledDataPoint[] tempBasal = new ScaledDataPoint[tempBasalArray.size()];
|
||||||
tempBasal = tempBasalArray.toArray(tempBasal);
|
tempBasal = tempBasalArray.toArray(tempBasal);
|
||||||
tempBasalsSeries = new LineGraphSeries<>(tempBasal);
|
tempBasalsSeries = new LineGraphSeries<>(tempBasal);
|
||||||
tempBasalsSeries.setDrawBackground(true);
|
tempBasalsSeries.setDrawBackground(true);
|
||||||
tempBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.tempbasal));
|
tempBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.tempbasal));
|
||||||
tempBasalsSeries.setThickness(0);
|
tempBasalsSeries.setThickness(0);
|
||||||
|
|
||||||
DataPoint[] basalLine = new DataPoint[basalLineArray.size()];
|
ScaledDataPoint[] basalLine = new ScaledDataPoint[basalLineArray.size()];
|
||||||
basalLine = basalLineArray.toArray(basalLine);
|
basalLine = basalLineArray.toArray(basalLine);
|
||||||
basalsLineSeries = new LineGraphSeries<>(basalLine);
|
basalsLineSeries = new LineGraphSeries<>(basalLine);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
|
@ -182,7 +196,7 @@ public class GraphData {
|
||||||
paint.setColor(MainApp.sResources.getColor(R.color.basal));
|
paint.setColor(MainApp.sResources.getColor(R.color.basal));
|
||||||
basalsLineSeries.setCustomPaint(paint);
|
basalsLineSeries.setCustomPaint(paint);
|
||||||
|
|
||||||
DataPoint[] absoluteBasalLine = new DataPoint[absoluteBasalLineArray.size()];
|
ScaledDataPoint[] absoluteBasalLine = new ScaledDataPoint[absoluteBasalLineArray.size()];
|
||||||
absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine);
|
absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine);
|
||||||
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
|
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
|
||||||
Paint absolutePaint = new Paint();
|
Paint absolutePaint = new Paint();
|
||||||
|
@ -191,27 +205,65 @@ 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);
|
||||||
|
|
||||||
bgGraph.getSecondScale().setMinY(0);
|
basalScale.setValue(maxX * scale / maxBasalValueFound);
|
||||||
bgGraph.getSecondScale().setMaxY(scale * maxBasalValueFound);
|
|
||||||
bgGraph.getSecondScale().addSeries(baseBasalsSeries);
|
|
||||||
bgGraph.getSecondScale().addSeries(tempBasalsSeries);
|
|
||||||
bgGraph.getSecondScale().addSeries(basalsLineSeries);
|
|
||||||
bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries);
|
|
||||||
|
|
||||||
bgGraph.getSecondScale().setLabelFormatter(new LabelFormatter() {
|
addSeriesWithoutInvalidate(bgGraph, baseBasalsSeries);
|
||||||
@Override
|
addSeriesWithoutInvalidate(bgGraph, tempBasalsSeries);
|
||||||
public String formatLabel(double value, boolean isValueX) {
|
addSeriesWithoutInvalidate(bgGraph, basalsLineSeries);
|
||||||
return "";
|
addSeriesWithoutInvalidate(bgGraph, absoluteBasalsLineSeries);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setViewport(Viewport viewport) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getNearestBg(long date) {
|
public void addTreatmnets(GraphView bgGraph, long fromTime, long endTime) {
|
||||||
|
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
|
||||||
|
|
||||||
|
for (int tx = 0; tx < treatments.size(); tx++) {
|
||||||
|
Treatment t = treatments.get(tx);
|
||||||
|
if (t.getX() < fromTime || t.getX() > endTime) continue;
|
||||||
|
t.setY(getNearestBg((long) t.getX()));
|
||||||
|
filteredTreatments.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileSwitch
|
||||||
|
List<ProfileSwitch> profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList();
|
||||||
|
|
||||||
|
for (int tx = 0; tx < profileSwitches.size(); tx++) {
|
||||||
|
DataPointWithLabelInterface t = profileSwitches.get(tx);
|
||||||
|
if (t.getX() < fromTime || t.getX() > endTime) continue;
|
||||||
|
filteredTreatments.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extended bolus
|
||||||
|
if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
||||||
|
List<ExtendedBolus> extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList();
|
||||||
|
|
||||||
|
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
||||||
|
DataPointWithLabelInterface t = extendedBoluses.get(tx);
|
||||||
|
if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue;
|
||||||
|
if (t.getDuration() == 0) continue;
|
||||||
|
t.setY(getNearestBg((long) t.getX()));
|
||||||
|
filteredTreatments.add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Careportal
|
||||||
|
List<CareportalEvent> careportalEvents = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, true);
|
||||||
|
|
||||||
|
for (int tx = 0; tx < careportalEvents.size(); tx++) {
|
||||||
|
DataPointWithLabelInterface t = careportalEvents.get(tx);
|
||||||
|
if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue;
|
||||||
|
t.setY(getNearestBg((long) t.getX()));
|
||||||
|
filteredTreatments.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()];
|
||||||
|
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
|
||||||
|
if (treatmentsArray.length > 0) {
|
||||||
|
addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(treatmentsArray));
|
||||||
|
} }
|
||||||
|
|
||||||
|
double getNearestBg(long date) {
|
||||||
double bg = 0;
|
double bg = 0;
|
||||||
for (int r = bgReadingsArray.size() - 1; r >= 0; r--) {
|
for (int r = bgReadingsArray.size() - 1; r >= 0; r--) {
|
||||||
BgReading reading = bgReadingsArray.get(r);
|
BgReading reading = bgReadingsArray.get(r);
|
||||||
|
@ -223,7 +275,7 @@ public class GraphData {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addSeriesWithoutInvalidate(Series s) {
|
private void addSeriesWithoutInvalidate(GraphView bgGraph, Series s) {
|
||||||
s.onGraphViewAttached(bgGraph);
|
s.onGraphViewAttached(bgGraph);
|
||||||
bgGraph.getSeries().add(s);
|
bgGraph.getSeries().add(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.graphExtensions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 18.10.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Scale {
|
||||||
|
private double value;
|
||||||
|
|
||||||
|
public void setValue(double value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.graphExtensions;
|
||||||
|
|
||||||
|
import com.jjoe64.graphview.series.DataPointInterface;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 18.10.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ScaledDataPoint implements DataPointInterface, Serializable {
|
||||||
|
private static final long serialVersionUID=1428263342645L;
|
||||||
|
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
|
||||||
|
private Scale scale;
|
||||||
|
|
||||||
|
public ScaledDataPoint(double x, double y, Scale scale) {
|
||||||
|
this.x=x;
|
||||||
|
this.y=y;
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScaledDataPoint(Date x, double y, Scale scale) {
|
||||||
|
this.x = x.getTime();
|
||||||
|
this.y = y;
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getY() {
|
||||||
|
return y * scale.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "["+x+"/"+y+"]";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue