wear basal live

This commit is contained in:
AdrianLxM 2016-11-18 03:21:38 +01:00
parent 552fdaa9de
commit afa5faf834
4 changed files with 44 additions and 18 deletions

View file

@ -247,40 +247,69 @@ public class WatchUpdaterService extends WearableListenerService implements
private void sendBasals() { private void sendBasals() {
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); } if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
long startTime = System.currentTimeMillis() - (long)(60000 * 60 * 5.5);
long now = System.currentTimeMillis();
long startTimeWindow = now - (long)(60000 * 60 * 5.5);
ArrayList<DataMap> basals = new ArrayList<>(); ArrayList<DataMap> basals = new ArrayList<>();
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
long beginBasalSegmentTime = startTimeWindow;
long endBasalSegmentTime = startTimeWindow;
double beginValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime)));
double endValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(endBasalSegmentTime)));
for(;endBasalSegmentTime<now;endBasalSegmentTime+= 5*60*1000){
endValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(endBasalSegmentTime)));
if(endValue != beginValue){
//push the segment we recently left
basals.add(basalMap(beginBasalSegmentTime, endBasalSegmentTime, beginValue));
//begin new Basal segment
beginBasalSegmentTime = endBasalSegmentTime;
beginValue = endValue;
}
}
if(beginBasalSegmentTime != endBasalSegmentTime){
//push the remaining segment
basals.add(basalMap(beginBasalSegmentTime, endBasalSegmentTime, beginValue));
}
//TODO: Adrian: replace fake data //TODO: Adrian: replace fake data
long from = startTime; long from = startTimeWindow;
long now = System.currentTimeMillis();
long to = (now + from)/2; long to = (now + from)/2;
double amount = 0.5; double amount = 0.5;
double afterwards = 0.8; //basals.add(basalMap(from, to, amount));
basals.add(basalMap(from, to, amount, afterwards));
from = to; //from = to;
to = now; //to = now;
amount = 0.8; //amount = 0.8;
basals.add(basalMap(from, to, amount, amount)); //basals.add(basalMap(from, to, amount));
ArrayList<DataMap> temps = new ArrayList<>(); ArrayList<DataMap> temps = new ArrayList<>();
from = (long)(startTime + (1/8d)*(now - startTime)); from = (long)(startTimeWindow + (1/8d)*(now - startTimeWindow));
double fromBasal = 0.5; double fromBasal = 0.5;
to = (long)(startTime + (2/8d)*(now - startTime)); to = (long)(startTimeWindow + (2/8d)*(now - startTimeWindow));
double toBasal = 0.5; double toBasal = 0.5;
amount = 3; amount = 3;
temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); temps.add(tempDatamap(from, fromBasal, to, toBasal, amount));
from = (long)(startTime + (6/8d)*(now - startTime)); from = (long)(startTimeWindow + (6/8d)*(now - startTimeWindow));
fromBasal = 0.8; fromBasal = 0.8;
to = (long)(startTime + (7/8d)*(now - startTime)); to = (long)(startTimeWindow + (7/8d)*(now - startTimeWindow));
toBasal = 0.8; toBasal = 0.8;
amount = 0; amount = 0;
temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); temps.add(tempDatamap(from, fromBasal, to, toBasal, amount));
@ -305,12 +334,11 @@ public class WatchUpdaterService extends WearableListenerService implements
return dm; return dm;
} }
private DataMap basalMap(long startTime, long endTime, double amount, double afterwards) { private DataMap basalMap(long startTime, long endTime, double amount) {
DataMap dm = new DataMap(); DataMap dm = new DataMap();
dm.putLong("starttime", startTime); dm.putLong("starttime", startTime);
dm.putLong("endtime", endTime); dm.putLong("endtime", endTime);
dm.putDouble("amount", amount); dm.putDouble("amount", amount);
dm.putDouble("afterwards", afterwards);
return dm; return dm;
} }

View file

@ -311,7 +311,6 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
bwd.startTime = basal.getLong("starttime"); bwd.startTime = basal.getLong("starttime");
bwd.endTime = basal.getLong("endtime"); bwd.endTime = basal.getLong("endtime");
bwd.amount = basal.getDouble("amount"); bwd.amount = basal.getDouble("amount");
//bwd.afterwards;
basalWatchDataList.add(bwd); basalWatchDataList.add(bwd);
} }
} }

View file

@ -8,5 +8,4 @@ public class BasalWatchData {
public long startTime; public long startTime;
public long endTime; public long endTime;
public double amount; public double amount;
public double afterwards;
} }

View file

@ -124,7 +124,7 @@ public class BgGraphBuilder {
double factor = (maxChart-minChart)/maxTemp; double factor = (maxChart-minChart)/maxTemp;
// in case basal is the highest, don't paint it totally at the top. // in case basal is the highest, don't paint it totally at the top.
factor = Math.min(factor, ((maxChart-minChart)/maxTemp)*(2/3d)); factor = Math.min(factor, ((maxChart-minChart)/maxBasal)*(2/3d));
for (TempWatchData twd: tempWatchDataList) { for (TempWatchData twd: tempWatchDataList) {
if(twd.endTime > start_time) { if(twd.endTime > start_time) {
lines.add(tempValuesLine(twd, (float) minChart, factor)); lines.add(tempValuesLine(twd, (float) minChart, factor));