wear adaptive prediction timeframe
This commit is contained in:
parent
8ee7309d86
commit
c6a3efb60e
5 changed files with 87 additions and 8 deletions
|
@ -356,6 +356,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
ArrayList<DataMap> basals = new ArrayList<>();
|
ArrayList<DataMap> basals = new ArrayList<>();
|
||||||
ArrayList<DataMap> temps = new ArrayList<>();
|
ArrayList<DataMap> temps = new ArrayList<>();
|
||||||
ArrayList<DataMap> boluses = new ArrayList<>();
|
ArrayList<DataMap> boluses = new ArrayList<>();
|
||||||
|
ArrayList<DataMap> predictions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -461,10 +463,24 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||||
|
if(finalLastRun != null && finalLastRun.request.hasPredictions && finalLastRun.constraintsProcessed != null){
|
||||||
|
List<BgReading> predArray = finalLastRun.constraintsProcessed.getPredictions();
|
||||||
|
|
||||||
|
if (!predArray.isEmpty()) {
|
||||||
|
for (BgReading bg : predArray) {
|
||||||
|
predictions.add(predictionMap(bg.date, bg.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DataMap dm = new DataMap();
|
DataMap dm = new DataMap();
|
||||||
dm.putDataMapArrayList("basals", basals);
|
dm.putDataMapArrayList("basals", basals);
|
||||||
dm.putDataMapArrayList("temps", temps);
|
dm.putDataMapArrayList("temps", temps);
|
||||||
dm.putDataMapArrayList("boluses", boluses);
|
dm.putDataMapArrayList("boluses", boluses);
|
||||||
|
dm.putDataMapArrayList("predictions", predictions);
|
||||||
|
|
||||||
new SendToDataLayerThread(BASAL_DATA_PATH, googleApiClient).execute(dm);
|
new SendToDataLayerThread(BASAL_DATA_PATH, googleApiClient).execute(dm);
|
||||||
}
|
}
|
||||||
|
@ -496,6 +512,13 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
return dm;
|
return dm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DataMap predictionMap(long timestamp, double sgv) {
|
||||||
|
DataMap dm = new DataMap();
|
||||||
|
dm.putLong("timestamp", timestamp);
|
||||||
|
dm.putDouble("sgv", sgv);
|
||||||
|
return dm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendNotification() {
|
private void sendNotification() {
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
|
|
|
@ -16,6 +16,10 @@ public class BgWatchData implements Comparable<BgWatchData>{
|
||||||
this.timestamp = aTimestamp;
|
this.timestamp = aTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BgWatchData(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object that){
|
public boolean equals(Object that){
|
||||||
if(! (that instanceof BgWatchData)){
|
if(! (that instanceof BgWatchData)){
|
||||||
|
|
|
@ -77,6 +77,8 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
||||||
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
||||||
public ArrayList<BolusWatchData> bolusWatchDataList = new ArrayList<>();
|
public ArrayList<BolusWatchData> bolusWatchDataList = new ArrayList<>();
|
||||||
|
public ArrayList<BgWatchData> predictionList = new ArrayList<>();
|
||||||
|
|
||||||
public PowerManager.WakeLock wakeLock;
|
public PowerManager.WakeLock wakeLock;
|
||||||
public View layoutView;
|
public View layoutView;
|
||||||
private final Point displaySize = new Point();
|
private final Point displaySize = new Point();
|
||||||
|
@ -413,6 +415,16 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
bolusWatchDataList.add(bwd);
|
bolusWatchDataList.add(bwd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ArrayList<DataMap> predictions = dataMap.getDataMapArrayList("predictions");
|
||||||
|
if (boluses != null) {
|
||||||
|
predictionList = new ArrayList<>();
|
||||||
|
for (DataMap prediction : predictions) {
|
||||||
|
BgWatchData bwd = new BgWatchData();
|
||||||
|
bwd.timestamp = prediction.getLong("timestamp");
|
||||||
|
bwd.sgv = prediction.getDouble("sgv");
|
||||||
|
predictionList.add(bwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAgeAndStatus() {
|
private void showAgeAndStatus() {
|
||||||
|
@ -655,9 +667,9 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things
|
if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things
|
||||||
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
|
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
|
||||||
if (lowResMode) {
|
if (lowResMode) {
|
||||||
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, bolusWatchDataList, pointSize, midColor, gridColour, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, predictionList, tempWatchDataList, basalWatchDataList, bolusWatchDataList, pointSize, midColor, gridColour, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
||||||
} else {
|
} else {
|
||||||
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, bolusWatchDataList, pointSize, highColor, lowColor, midColor, gridColour, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, predictionList, tempWatchDataList, basalWatchDataList, bolusWatchDataList, pointSize, highColor, lowColor, midColor, gridColour, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
chart.setLineChartData(bgGraphBuilder.lineData());
|
chart.setLineChartData(bgGraphBuilder.lineData());
|
||||||
|
|
|
@ -76,6 +76,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
||||||
public ArrayList<BgWatchData> bgDataList = new ArrayList<>();
|
public ArrayList<BgWatchData> bgDataList = new ArrayList<>();
|
||||||
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
||||||
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
||||||
|
public ArrayList<BgWatchData> predictionList = new ArrayList<>();
|
||||||
public PowerManager.WakeLock wakeLock;
|
public PowerManager.WakeLock wakeLock;
|
||||||
// related endTime manual layout
|
// related endTime manual layout
|
||||||
public View layoutView;
|
public View layoutView;
|
||||||
|
@ -629,9 +630,9 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
||||||
if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things
|
if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things
|
||||||
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
|
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
|
||||||
if (lowResMode) {
|
if (lowResMode) {
|
||||||
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, null, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, predictionList, tempWatchDataList, basalWatchDataList, null, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
||||||
} else {
|
} else {
|
||||||
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, null, pointSize, highColor, lowColor, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList,predictionList, tempWatchDataList, basalWatchDataList, null, pointSize, highColor, lowColor, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, timeframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
chart.setLineChartData(bgGraphBuilder.lineData());
|
chart.setLineChartData(bgGraphBuilder.lineData());
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.watchfaces;
|
package info.nightscout.androidaps.watchfaces;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.DashPathEffect;
|
import android.graphics.DashPathEffect;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
@ -28,6 +29,8 @@ import lecho.lib.hellocharts.model.Viewport;
|
||||||
* Created by emmablack on 11/15/14.
|
* Created by emmablack on 11/15/14.
|
||||||
*/
|
*/
|
||||||
public class BgGraphBuilder {
|
public class BgGraphBuilder {
|
||||||
|
public static final double MAX_PREDICTION__TIME_RATIO = (3d / 5);
|
||||||
|
private List<BgWatchData> predictionsList;
|
||||||
private ArrayList<BolusWatchData> bolusWatchDataList;
|
private ArrayList<BolusWatchData> bolusWatchDataList;
|
||||||
private ArrayList<BasalWatchData> basalWatchDataList;
|
private ArrayList<BasalWatchData> basalWatchDataList;
|
||||||
public List<TempWatchData> tempWatchDataList;
|
public List<TempWatchData> tempWatchDataList;
|
||||||
|
@ -58,10 +61,11 @@ public class BgGraphBuilder {
|
||||||
|
|
||||||
|
|
||||||
//used for low resolution screen.
|
//used for low resolution screen.
|
||||||
public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<TempWatchData> tempWatchDataList, ArrayList<BasalWatchData> basalWatchDataList, ArrayList<BolusWatchData> bolusWatchDataList, int aPointSize, int aMidColor, int gridColour, int basalBackgroundColor, int basalCenterColor, int bolusColor, int timespan) {
|
public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<BgWatchData> predictionsList, List<TempWatchData> tempWatchDataList, ArrayList<BasalWatchData> basalWatchDataList, ArrayList<BolusWatchData> bolusWatchDataList, int aPointSize, int aMidColor, int gridColour, int basalBackgroundColor, int basalCenterColor, int bolusColor, int timespan) {
|
||||||
end_time = System.currentTimeMillis() + (1000 * 60 * 6 * timespan); //Now plus 30 minutes padding (for 5 hours. Less if less.)
|
end_time = System.currentTimeMillis() + (1000 * 60 * 6 * timespan); //Now plus 30 minutes padding (for 5 hours. Less if less.)
|
||||||
start_time = System.currentTimeMillis() - (1000 * 60 * 60 * timespan); //timespan hours ago
|
start_time = System.currentTimeMillis() - (1000 * 60 * 60 * timespan); //timespan hours ago
|
||||||
this.bgDataList = aBgList;
|
this.bgDataList = aBgList;
|
||||||
|
this.predictionsList = predictionsList;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.highMark = aBgList.get(aBgList.size() - 1).high;
|
this.highMark = aBgList.get(aBgList.size() - 1).high;
|
||||||
this.lowMark = aBgList.get(aBgList.size() - 1).low;
|
this.lowMark = aBgList.get(aBgList.size() - 1).low;
|
||||||
|
@ -80,10 +84,11 @@ public class BgGraphBuilder {
|
||||||
this.bolusColor = bolusColor;
|
this.bolusColor = bolusColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<TempWatchData> tempWatchDataList, ArrayList<BasalWatchData> basalWatchDataList, ArrayList<BolusWatchData> bolusWatchDataList, int aPointSize, int aHighColor, int aLowColor, int aMidColor, int gridColour, int basalBackgroundColor, int basalCenterColor, int bolusColor, int timespan) {
|
public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<BgWatchData> predictionsList, List<TempWatchData> tempWatchDataList, ArrayList<BasalWatchData> basalWatchDataList, ArrayList<BolusWatchData> bolusWatchDataList, int aPointSize, int aHighColor, int aLowColor, int aMidColor, int gridColour, int basalBackgroundColor, int basalCenterColor, int bolusColor, int timespan) {
|
||||||
end_time = System.currentTimeMillis() + (1000 * 60 * 6 * timespan); //Now plus 30 minutes padding (for 5 hours. Less if less.)
|
end_time = System.currentTimeMillis() + (1000 * 60 * 6 * timespan); //Now plus 30 minutes padding (for 5 hours. Less if less.)
|
||||||
start_time = System.currentTimeMillis() - (1000 * 60 * 60 * timespan); //timespan hours ago
|
start_time = System.currentTimeMillis() - (1000 * 60 * 60 * timespan); //timespan hours ago
|
||||||
this.bgDataList = aBgList;
|
this.bgDataList = aBgList;
|
||||||
|
this.predictionsList = predictionsList;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.highMark = aBgList.get(aBgList.size() - 1).high;
|
this.highMark = aBgList.get(aBgList.size() - 1).high;
|
||||||
this.lowMark = aBgList.get(aBgList.size() - 1).low;
|
this.lowMark = aBgList.get(aBgList.size() - 1).low;
|
||||||
|
@ -109,6 +114,7 @@ public class BgGraphBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Line> defaultLines() {
|
public List<Line> defaultLines() {
|
||||||
|
|
||||||
addBgReadingValues();
|
addBgReadingValues();
|
||||||
List<Line> lines = new ArrayList<Line>();
|
List<Line> lines = new ArrayList<Line>();
|
||||||
lines.add(highLine());
|
lines.add(highLine());
|
||||||
|
@ -163,6 +169,7 @@ public class BgGraphBuilder {
|
||||||
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(smbLine((float) minChart));
|
lines.add(smbLine((float) minChart));
|
||||||
|
lines.add(predictionLine());
|
||||||
|
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
|
@ -224,6 +231,24 @@ public class BgGraphBuilder {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Line predictionLine() {
|
||||||
|
|
||||||
|
List<PointValue> pointValues = new ArrayList<PointValue>();
|
||||||
|
|
||||||
|
long endTime = getPredictionEndTime();
|
||||||
|
for (BgWatchData bwd: predictionsList) {
|
||||||
|
if(bwd.timestamp <= endTime) {
|
||||||
|
pointValues.add(new PointValue(fuzz(bwd.timestamp), (float) bwd.sgv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Line line = new Line(pointValues);
|
||||||
|
line.setColor(Color.MAGENTA);
|
||||||
|
line.setHasLines(false);
|
||||||
|
line.setPointRadius(pointSize);
|
||||||
|
line.setHasPoints(true);
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -365,9 +390,12 @@ public class BgGraphBuilder {
|
||||||
timeFormat.setTimeZone(TimeZone.getDefault());
|
timeFormat.setTimeZone(TimeZone.getDefault());
|
||||||
long start_hour = today.getTime().getTime();
|
long start_hour = today.getTime().getTime();
|
||||||
long timeNow = System.currentTimeMillis();
|
long timeNow = System.currentTimeMillis();
|
||||||
|
|
||||||
|
long endTime = getPredictionEndTime();
|
||||||
|
|
||||||
for (int l = 0; l <= 24; l++) {
|
for (int l = 0; l <= 24; l++) {
|
||||||
if ((start_hour + (60000 * 60 * (l))) < timeNow) {
|
if ((start_hour + (60000 * 60 * (l))) < endTime) {
|
||||||
if ((start_hour + (60000 * 60 * (l + 1))) >= timeNow) {
|
if ((start_hour + (60000 * 60 * (l + 1))) >= endTime) {
|
||||||
endHour = start_hour + (60000 * 60 * (l));
|
endHour = start_hour + (60000 * 60 * (l));
|
||||||
l = 25;
|
l = 25;
|
||||||
}
|
}
|
||||||
|
@ -397,6 +425,17 @@ public class BgGraphBuilder {
|
||||||
return xAxis;
|
return xAxis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getPredictionEndTime() {
|
||||||
|
long maxPredictionDate = System.currentTimeMillis();
|
||||||
|
for (BgWatchData prediction :
|
||||||
|
predictionsList) {
|
||||||
|
if (maxPredictionDate < prediction.timestamp) {
|
||||||
|
maxPredictionDate = prediction.timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (long) Math.min(maxPredictionDate, System.currentTimeMillis() + MAX_PREDICTION__TIME_RATIO *timespan*1000*60*60);
|
||||||
|
}
|
||||||
|
|
||||||
public float fuzz(long value) {
|
public float fuzz(long value) {
|
||||||
return (float) Math.round(value / fuzzyTimeDenom);
|
return (float) Math.round(value / fuzzyTimeDenom);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue