absolute basal line

This commit is contained in:
Milos Kozak 2017-06-05 01:12:36 +02:00
parent dd7e777a24
commit 88b9caa357

View file

@ -1181,6 +1181,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
LineGraphSeries<DataPoint> basalsLineSeries = null; LineGraphSeries<DataPoint> basalsLineSeries = null;
LineGraphSeries<DataPoint> absoluteBasalsLineSeries = null;
LineGraphSeries<DataPoint> baseBasalsSeries = null; LineGraphSeries<DataPoint> baseBasalsSeries = null;
LineGraphSeries<DataPoint> tempBasalsSeries = null; LineGraphSeries<DataPoint> tempBasalsSeries = null;
AreaGraphSeries<DoubleDataPoint> areaSeries; AreaGraphSeries<DoubleDataPoint> areaSeries;
@ -1194,17 +1195,20 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
List<DataPoint> baseBasalArray = new ArrayList<>(); List<DataPoint> baseBasalArray = new ArrayList<>();
List<DataPoint> tempBasalArray = new ArrayList<>(); List<DataPoint> tempBasalArray = new ArrayList<>();
List<DataPoint> basalLineArray = new ArrayList<>(); List<DataPoint> basalLineArray = new ArrayList<>();
List<DataPoint> absoluteBasalLineArray = new ArrayList<>();
double lastLineBasal = 0; double lastLineBasal = 0;
double lastAbsoluteLineBasal = 0;
double lastBaseBasal = 0; double lastBaseBasal = 0;
double lastTempBasal = 0; double lastTempBasal = 0;
for (long time = fromTime; time < now; time += 1 * 60 * 1000L) { for (long time = fromTime; time < now; time += 1 * 60 * 1000L) {
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time); TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time);
double baseBasalValue = MainApp.getConfigBuilder().getProfile(time).getBasal(Profile.secondsFromMidnight(time)); double baseBasalValue = MainApp.getConfigBuilder().getProfile(time).getBasal(Profile.secondsFromMidnight(time));
double baseLineValue = baseBasalValue; double baseLineValue = baseBasalValue;
double absoluteLineValue = baseBasalValue;
double tempBasalValue = 0; double tempBasalValue = 0;
double basal = 0d; double basal = 0d;
if (tb != null) { if (tb != null) {
tempBasalValue = tb.tempBasalConvertedToAbsolute(new Date(time).getTime()); absoluteLineValue = tempBasalValue = tb.tempBasalConvertedToAbsolute(new Date(time).getTime());
if (tempBasalValue != lastTempBasal) { if (tempBasalValue != lastTempBasal) {
tempBasalArray.add(new DataPoint(time, lastTempBasal)); tempBasalArray.add(new DataPoint(time, lastTempBasal));
tempBasalArray.add(new DataPoint(time, basal = tempBasalValue)); tempBasalArray.add(new DataPoint(time, basal = tempBasalValue));
@ -1230,7 +1234,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
basalLineArray.add(new DataPoint(time, lastLineBasal)); basalLineArray.add(new DataPoint(time, lastLineBasal));
basalLineArray.add(new DataPoint(time, baseLineValue)); basalLineArray.add(new DataPoint(time, baseLineValue));
} }
if (absoluteLineValue != lastAbsoluteLineBasal) {
absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal));
absoluteBasalLineArray.add(new DataPoint(time, basal));
}
lastAbsoluteLineBasal = absoluteLineValue;
lastLineBasal = baseLineValue; lastLineBasal = baseLineValue;
lastTempBasal = tempBasalValue; lastTempBasal = tempBasalValue;
maxBasalValueFound = Math.max(maxBasalValueFound, basal); maxBasalValueFound = Math.max(maxBasalValueFound, basal);
@ -1238,6 +1247,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
basalLineArray.add(new DataPoint(now, lastLineBasal)); basalLineArray.add(new DataPoint(now, lastLineBasal));
baseBasalArray.add(new DataPoint(now, lastBaseBasal)); baseBasalArray.add(new DataPoint(now, lastBaseBasal));
tempBasalArray.add(new DataPoint(now, lastTempBasal)); tempBasalArray.add(new DataPoint(now, lastTempBasal));
absoluteBasalLineArray.add(new DataPoint(now, lastAbsoluteLineBasal));
DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()]; DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()];
baseBasal = baseBasalArray.toArray(baseBasal); baseBasal = baseBasalArray.toArray(baseBasal);
@ -1262,6 +1272,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0)); paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0));
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()];
absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine);
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
Paint absolutePaint = new Paint();
absolutePaint.setStyle(Paint.Style.STROKE);
absolutePaint.setStrokeWidth(4);
absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal));
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
} }
// **** IOB COB DEV graph **** // **** IOB COB DEV graph ****
@ -1492,6 +1511,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
bgGraph.getSecondScale().addSeries(baseBasalsSeries); bgGraph.getSecondScale().addSeries(baseBasalsSeries);
bgGraph.getSecondScale().addSeries(tempBasalsSeries); bgGraph.getSecondScale().addSeries(tempBasalsSeries);
bgGraph.getSecondScale().addSeries(basalsLineSeries); bgGraph.getSecondScale().addSeries(basalsLineSeries);
bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries);
bgGraph.getSecondScale().setMinY(0); bgGraph.getSecondScale().setMinY(0);
bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d); bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d);
} }