From 768f61bc07f18070c446c885c614d3d263f66e1d Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 8 Mar 2018 14:59:18 +0100 Subject: [PATCH] unify target calculation --- .../java/info/nightscout/androidaps/data/Profile.java | 8 ++++++++ .../androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 2 +- .../androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java | 2 +- .../androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index f461c84b2e..cb17802777 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -442,6 +442,14 @@ public class Profile { return ret; } + public double getTarget(){ + return getTarget(secondsFromMidnight(System.currentTimeMillis())); + } + + private double getTarget(Integer time) { + return (getTargetLow(time) + getTargetHigh(time))/2; + } + public Double getTargetLow() { return getTargetLow(secondsFromMidnight(System.currentTimeMillis())); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index dbb448d8d5..9d537b5b2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -176,7 +176,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { double maxBasal = SP.getDouble("openapsma_max_basal", 1d); double minBg = Profile.toMgdl(profile.getTargetLow(), units); double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); - double targetBg = (minBg + maxBg) / 2; + double targetBg = Profile.toMgdl(profile.getTarget(), units); minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index fd20bc3274..9f071c75a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -179,7 +179,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1")); double minBg = Profile.toMgdl(profile.getTargetLow(), units); double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); - double targetBg = (minBg + maxBg) / 2; + double targetBg = Profile.toMgdl(profile.getTarget(), units); minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index 9a74c491dd..325951929a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -181,7 +181,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { double maxBasal = SP.getDouble("openapsma_max_basal", 1d); double minBg = Profile.toMgdl(profile.getTargetLow(), units); double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); - double targetBg = (minBg + maxBg) / 2; + double targetBg = Profile.toMgdl(profile.getTarget(), units); minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d);