different color for carbs deviations

This commit is contained in:
Milos Kozak 2017-05-04 20:40:43 +02:00
parent aabcee8ea7
commit db5dcc0064
2 changed files with 22 additions and 12 deletions

View file

@ -8,7 +8,7 @@ import java.util.Date;
public class AutosensData { public class AutosensData {
long time = 0L; long time = 0L;
String pastSensitivity = ""; public String pastSensitivity = "";
public double deviation = 0d; public double deviation = 0d;
boolean calculateWithDeviation = false; boolean calculateWithDeviation = false;
double absorbed = 0d; double absorbed = 0d;

View file

@ -1123,10 +1123,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
basalsLineSeries.setCustomPaint(paint); basalsLineSeries.setCustomPaint(paint);
} }
// **** IOB COB graph **** // **** IOB COB DEV graph ****
class DeviationDataPoint extends DataPoint {
public int color;
public DeviationDataPoint(double x, double y, int color) {
super(x, y);
this.color = color;
}
}
FixedLineGraphSeries<DataPoint> iobSeries; FixedLineGraphSeries<DataPoint> iobSeries;
FixedLineGraphSeries<DataPoint> cobSeries; FixedLineGraphSeries<DataPoint> cobSeries;
BarGraphSeries<DataPoint> devSeries; BarGraphSeries<DeviationDataPoint> devSeries;
Double maxIobValueFound = 0d; Double maxIobValueFound = 0d;
Double maxCobValueFound = 0d; Double maxCobValueFound = 0d;
Double maxDevValueFound = 0d; Double maxDevValueFound = 0d;
@ -1135,7 +1142,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
//Date start = new Date(); //Date start = new Date();
List<DataPoint> iobArray = new ArrayList<>(); List<DataPoint> iobArray = new ArrayList<>();
List<DataPoint> cobArray = new ArrayList<>(); List<DataPoint> cobArray = new ArrayList<>();
List<DataPoint> devArray = new ArrayList<>(); List<DeviationDataPoint> devArray = new ArrayList<>();
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) { for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
if (showIobView.isChecked()) { if (showIobView.isChecked()) {
IobTotal iob = IobCobCalculatorPlugin.calulateFromTreatmentsAndTemps(time); IobTotal iob = IobCobCalculatorPlugin.calulateFromTreatmentsAndTemps(time);
@ -1149,7 +1156,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
maxCobValueFound = Math.max(maxCobValueFound, autosensData.cob); maxCobValueFound = Math.max(maxCobValueFound, autosensData.cob);
} }
if (autosensData != null && showDeviationsView.isChecked()) { if (autosensData != null && showDeviationsView.isChecked()) {
devArray.add(new DataPoint(time, autosensData.deviation)); int color = Color.BLACK; // "="
if (autosensData.pastSensitivity.equals("C")) color = Color.BLUE;
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)); maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
} }
} }
@ -1166,12 +1177,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) { if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) {
List<DataPoint> cobArrayRescaled = new ArrayList<>(); List<DataPoint> cobArrayRescaled = new ArrayList<>();
List<DataPoint> devArrayRescaled = new ArrayList<>(); List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
for (int ci = 0; ci < cobArray.size(); ci++) { for (int ci = 0; ci < cobArray.size(); ci++) {
cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxIobValueFound / maxCobValueFound / 2)); cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxIobValueFound / maxCobValueFound / 2));
} }
for (int ci = 0; ci < devArray.size(); ci++) { for (int ci = 0; ci < devArray.size(); ci++) {
devArrayRescaled.add(new DataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxIobValueFound / maxDevValueFound)); devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxIobValueFound / maxDevValueFound, devArray.get(ci).color));
} }
cobArray = cobArrayRescaled; cobArray = cobArrayRescaled;
devArray = devArrayRescaled; devArray = devArrayRescaled;
@ -1186,14 +1197,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobSeries.setThickness(3); cobSeries.setThickness(3);
// DEVIATIONS // DEVIATIONS
DataPoint[] devData = new DataPoint[devArray.size()]; DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
devData = devArray.toArray(devData); devData = devArray.toArray(devData);
devSeries = new BarGraphSeries<>(devData); devSeries = new BarGraphSeries<>(devData);
devSeries.setValueDependentColor(new ValueDependentColor<DataPoint>() { devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
@Override @Override
public int get(DataPoint data) { public int get(DeviationDataPoint data) {
if (data.getY() < 0) return Color.RED; return data.color;
else return Color.GREEN;
} }
}); });
//devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50% //devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%