From 8af4ac0dafd24059c9393b3df17c0928e895e5c7 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 18 Nov 2016 04:20:11 +0100 Subject: [PATCH] wear bigchart fully functional --- .../androidaps/plugins/Wear/WearPlugin.java | 1 - .../wearintegration/WatchUpdaterService.java | 83 ++++++++++++++----- .../nightscout/androidaps/BgGraphBuilder.java | 1 - 3 files changed, 63 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 2936c4da63..6566995fb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -83,7 +83,6 @@ public class WearPlugin implements PluginBase { if(basals){ ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BASALS)); - } if(status){ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index ee4701a20a..8b276fcc08 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -254,30 +254,79 @@ public class WatchUpdaterService extends WearableListenerService implements ArrayList basals = new ArrayList<>(); + ArrayList temps = 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))); + long runningTime = startTimeWindow; + + double beginBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime))); + double endBasalValue = beginBasalValue; + + TempBasal tb1 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); + TempBasal tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); + double tb_before = beginBasalValue; + double tb_amount = beginBasalValue; + long tb_start = runningTime; + + if(tb1 != null){ + tb_before = beginBasalValue; + tb_amount = tb1.tempBasalConvertedToAbsolute(new Date(runningTime)); + tb_start = runningTime; + } - for(;endBasalSegmentTime push it + temps.add(tempDatamap(tb_start, tb_before, runningTime, endBasalValue, tb_amount)); + tb1 = null; + + } else if (tb1 == null && tb2 != null) { + //temp begins + tb1 = tb2; + tb_start = runningTime; + tb_before = endBasalValue; + tb_amount = tb1.tempBasalConvertedToAbsolute(new Date(runningTime)); + + } else if (tb1 != null && tb2 != null) { + double currentAmount = tb2.tempBasalConvertedToAbsolute(new Date(runningTime)); + if(currentAmount != tb_amount){ + temps.add(tempDatamap(tb_start, tb_before, runningTime, currentAmount, tb_amount)); + tb_start = runningTime; + tb_before = tb_amount; + tb_amount = currentAmount; + tb1 = tb2; + } } } - if(beginBasalSegmentTime != endBasalSegmentTime){ + if(beginBasalSegmentTime != runningTime){ //push the remaining segment - basals.add(basalMap(beginBasalSegmentTime, endBasalSegmentTime, beginValue)); + basals.add(basalMap(beginBasalSegmentTime, runningTime, beginBasalValue)); + } + if(tb1 != null){ + temps.add(tempDatamap(tb_start, tb_before, runningTime, tb_amount, tb_amount)); } @@ -286,19 +335,13 @@ public class WatchUpdaterService extends WearableListenerService implements //TODO: Adrian: replace fake data - long from = startTimeWindow; + /* long from = startTimeWindow; long to = (now + from)/2; double amount = 0.5; - //basals.add(basalMap(from, to, amount)); - - //from = to; - //to = now; - //amount = 0.8; - //basals.add(basalMap(from, to, amount)); - ArrayList temps = new ArrayList<>(); + from = (long)(startTimeWindow + (1/8d)*(now - startTimeWindow)); double fromBasal = 0.5; to = (long)(startTimeWindow + (2/8d)*(now - startTimeWindow)); @@ -314,7 +357,7 @@ public class WatchUpdaterService extends WearableListenerService implements amount = 0; temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); - +*/ DataMap dm = new DataMap(); diff --git a/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java b/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java index 9f5448c2c3..7577c97256 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java +++ b/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java @@ -199,7 +199,6 @@ public class BgGraphBuilder { lineValues.add(new PointValue(fuzz(begin), offset + (float) (factor * twd.amount))); lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float) (factor * twd.amount))); lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float) (factor * twd.endBasal))); - lineValues.add(new PointValue(fuzz(begin), offset + (float) (factor * twd.startBasal))); Line valueLine = new Line(lineValues); valueLine.setHasPoints(false); valueLine.setColor(Color.BLUE);