Merge pull request #971 from jotomo/watch-pred-colors

Watch: colored preds.
This commit is contained in:
Milos Kozak 2018-05-02 16:38:01 +02:00 committed by GitHub
commit 6697c66435
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 32 deletions

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.db; package info.nightscout.androidaps.db;
import android.content.res.Resources;
import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.DatabaseTable;
@ -219,7 +221,7 @@ public class BgReading implements DataPointWithLabelInterface {
return color; return color;
} }
private int getPredectionColor() { public int getPredectionColor() {
if (isIOBPrediction) if (isIOBPrediction)
return MainApp.sResources.getColor(R.color.iob); return MainApp.sResources.getColor(R.color.iob);
if (isCOBPrediction) if (isCOBPrediction)

View file

@ -477,7 +477,8 @@ public class WatchUpdaterService extends WearableListenerService implements
if (!predArray.isEmpty()) { if (!predArray.isEmpty()) {
for (BgReading bg : predArray) { for (BgReading bg : predArray) {
predictions.add(predictionMap(bg.date, bg.value)); if (bg.value < 40) continue;
predictions.add(predictionMap(bg.date, bg.value, bg.getPredectionColor()));
} }
} }
} }
@ -520,10 +521,11 @@ public class WatchUpdaterService extends WearableListenerService implements
return dm; return dm;
} }
private DataMap predictionMap(long timestamp, double sgv) { private DataMap predictionMap(long timestamp, double sgv, int color) {
DataMap dm = new DataMap(); DataMap dm = new DataMap();
dm.putLong("timestamp", timestamp); dm.putLong("timestamp", timestamp);
dm.putDouble("sgv", sgv); dm.putDouble("sgv", sgv);
dm.putInt("color", color);
return dm; return dm;
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.data; package info.nightscout.androidaps.data;
import java.util.Objects;
/** /**
* Created by emmablack on 1/7/15. * Created by emmablack on 1/7/15.
*/ */
@ -8,12 +10,14 @@ public class BgWatchData implements Comparable<BgWatchData>{
public double high; public double high;
public double low; public double low;
public long timestamp; public long timestamp;
public int color;
public BgWatchData(double aSgv, double aHigh, double aLow, long aTimestamp) { public BgWatchData(double aSgv, double aHigh, double aLow, long aTimestamp, int aColor) {
this.sgv = aSgv; this.sgv = aSgv;
this.high = aHigh; this.high = aHigh;
this.low = aLow; this.low = aLow;
this.timestamp = aTimestamp; this.timestamp = aTimestamp;
this.color = aColor;
} }
public BgWatchData(){ public BgWatchData(){
@ -25,12 +29,14 @@ public class BgWatchData implements Comparable<BgWatchData>{
if(! (that instanceof BgWatchData)){ if(! (that instanceof BgWatchData)){
return false; return false;
} }
if (this.color != ((BgWatchData) that).color)
return false;
return this.timestamp == ((BgWatchData) that).timestamp; return this.timestamp == ((BgWatchData) that).timestamp;
} }
@Override @Override
public int hashCode(){ public int hashCode() {
return (int) (timestamp%Integer.MAX_VALUE); return Objects.hash(timestamp, color);
} }
@Override @Override

View file

@ -428,6 +428,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
BgWatchData bwd = new BgWatchData(); BgWatchData bwd = new BgWatchData();
bwd.timestamp = prediction.getLong("timestamp"); bwd.timestamp = prediction.getLong("timestamp");
bwd.sgv = prediction.getDouble("sgv"); bwd.sgv = prediction.getDouble("sgv");
bwd.color = prediction.getInt("color");
predictionList.add(bwd); predictionList.add(bwd);
} }
} }
@ -649,13 +650,15 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
double high = entry.getDouble("high"); double high = entry.getDouble("high");
double low = entry.getDouble("low"); double low = entry.getDouble("low");
long timestamp = entry.getLong("timestamp"); long timestamp = entry.getLong("timestamp");
bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); int color = entry.getInt("color", 0);
bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
} }
} else { } else {
double sgv = dataMap.getDouble("sgvDouble"); double sgv = dataMap.getDouble("sgvDouble");
double high = dataMap.getDouble("high"); double high = dataMap.getDouble("high");
double low = dataMap.getDouble("low"); double low = dataMap.getDouble("low");
long timestamp = dataMap.getLong("timestamp"); long timestamp = dataMap.getLong("timestamp");
int color = dataMap.getInt("color", 0);
final int size = bgDataList.size(); final int size = bgDataList.size();
if (size > 0) { if (size > 0) {
@ -663,7 +666,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
return; // Ignore duplicates. return; // Ignore duplicates.
} }
bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
} }
for (int i = 0; i < bgDataList.size(); i++) { for (int i = 0; i < bgDataList.size(); i++) {

View file

@ -604,13 +604,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
double high = entry.getDouble("high"); double high = entry.getDouble("high");
double low = entry.getDouble("low"); double low = entry.getDouble("low");
long timestamp = entry.getLong("timestamp"); long timestamp = entry.getLong("timestamp");
bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); int color = entry.getInt("color", 0);
bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
} }
} else { } else {
double sgv = dataMap.getDouble("sgvDouble"); double sgv = dataMap.getDouble("sgvDouble");
double high = dataMap.getDouble("high"); double high = dataMap.getDouble("high");
double low = dataMap.getDouble("low"); double low = dataMap.getDouble("low");
long timestamp = dataMap.getLong("timestamp"); long timestamp = dataMap.getLong("timestamp");
int color = dataMap.getInt("color", 0);
final int size = bgDataList.size(); final int size = bgDataList.size();
if (size > 0) { if (size > 0) {
@ -618,7 +620,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
return; // Ignore duplicates. return; // Ignore duplicates.
} }
bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
} }
for (int i = 0; i < bgDataList.size(); i++) { for (int i = 0; i < bgDataList.size(); i++) {
@ -689,6 +691,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
BgWatchData bwd = new BgWatchData(); BgWatchData bwd = new BgWatchData();
bwd.timestamp = prediction.getLong("timestamp"); bwd.timestamp = prediction.getLong("timestamp");
bwd.sgv = prediction.getDouble("sgv"); bwd.sgv = prediction.getDouble("sgv");
bwd.color = prediction.getInt("color");
predictionList.add(bwd); predictionList.add(bwd);
} }
} }

View file

@ -10,7 +10,9 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import info.nightscout.androidaps.data.BasalWatchData; import info.nightscout.androidaps.data.BasalWatchData;
@ -173,13 +175,12 @@ public class BgGraphBuilder {
} }
} }
addPredictionLines(lines);
lines.add(basalLine((float) minChart, factor, highlight)); lines.add(basalLine((float) minChart, factor, highlight));
lines.add(bolusLine((float) minChart)); lines.add(bolusLine((float) minChart));
lines.add(bolusInvalidLine((float) minChart)); lines.add(bolusInvalidLine((float) minChart));
lines.add(carbsLine((float) minChart)); lines.add(carbsLine((float) minChart));
lines.add(smbLine((float) minChart)); lines.add(smbLine((float) minChart));
lines.add(predictionLine());
return lines; return lines;
} }
@ -275,29 +276,30 @@ public class BgGraphBuilder {
} }
private Line predictionLine() { private void addPredictionLines(List<Line> lines) {
Map<Integer, List<PointValue>> values = new HashMap<>();
List<PointValue> pointValues = new ArrayList<PointValue>();
long endTime = getPredictionEndTime(); long endTime = getPredictionEndTime();
for (BgWatchData bwd: predictionsList) { for (BgWatchData bwd : predictionsList) {
if(bwd.timestamp <= endTime) { if (bwd.timestamp <= endTime) {
pointValues.add(new PointValue(fuzz(bwd.timestamp), (float) bwd.sgv)); double value = bwd.sgv < 300 ? bwd.sgv : 300;
if (!values.containsKey(bwd.color)) {
values.put(bwd.color, new ArrayList<>());
}
values.get(bwd.color).add(new PointValue(fuzz(bwd.timestamp), (float) value));
} }
} }
Line line = new Line(pointValues); for (Map.Entry<Integer, List<PointValue>> entry : values.entrySet()) {
line.setColor(Color.MAGENTA); Line line = new Line(entry.getValue());
line.setHasLines(false); line.setColor(entry.getKey());
int size = pointSize/2; line.setHasLines(false);
size = (size>0)?size:1; int size = pointSize / 2;
line.setPointRadius(size); size = (size > 0) ? size : 1;
line.setHasPoints(true); line.setPointRadius(size);
return line; line.setHasPoints(true);
lines.add(line);
}
} }
public Line highValuesLine() { public Line highValuesLine() {
Line highValuesLine = new Line(highValues); Line highValuesLine = new Line(highValues);
highValuesLine.setColor(highColor); highValuesLine.setColor(highColor);

View file

@ -573,7 +573,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh
double high = dataMap.getDouble("high"); double high = dataMap.getDouble("high");
double low = dataMap.getDouble("low"); double low = dataMap.getDouble("low");
long timestamp = dataMap.getLong("timestamp"); long timestamp = dataMap.getLong("timestamp");
bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); int color = dataMap.getInt("color", 0);
bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
} else if (!sharedPrefs.getBoolean("animation", false)) { } else if (!sharedPrefs.getBoolean("animation", false)) {
// don't load history at once if animations are set (less resource consumption) // don't load history at once if animations are set (less resource consumption)
Log.d("addToWatchSet", "entries.size(): " + entries.size()); Log.d("addToWatchSet", "entries.size(): " + entries.size());
@ -583,7 +584,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh
double high = entry.getDouble("high"); double high = entry.getDouble("high");
double low = entry.getDouble("low"); double low = entry.getDouble("low");
long timestamp = entry.getLong("timestamp"); long timestamp = entry.getLong("timestamp");
bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); int color = entry.getInt("color", 0);
bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
} }
} else } else