show predictions in nsclient mode
This commit is contained in:
parent
f7f4385d5d
commit
29032e658f
|
@ -10,7 +10,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -28,7 +27,7 @@ import info.nightscout.utils.DecimalFormatter;
|
||||||
public class APSResult {
|
public class APSResult {
|
||||||
private static Logger log = LoggerFactory.getLogger(APSResult.class);
|
private static Logger log = LoggerFactory.getLogger(APSResult.class);
|
||||||
|
|
||||||
public Date date;
|
public long date = 0;
|
||||||
public String reason;
|
public String reason;
|
||||||
public double rate;
|
public double rate;
|
||||||
public int duration;
|
public int duration;
|
||||||
|
@ -133,8 +132,8 @@ public class APSResult {
|
||||||
public List<BgReading> getPredictions() {
|
public List<BgReading> getPredictions() {
|
||||||
List<BgReading> array = new ArrayList<>();
|
List<BgReading> array = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
long startTime = date.getTime();
|
long startTime = date;
|
||||||
if (json.has("predBGs")) {
|
if (json != null && json.has("predBGs")) {
|
||||||
JSONObject predBGs = json.getJSONObject("predBGs");
|
JSONObject predBGs = json.getJSONObject("predBGs");
|
||||||
if (predBGs.has("IOB")) {
|
if (predBGs.has("IOB")) {
|
||||||
JSONArray iob = predBGs.getJSONArray("IOB");
|
JSONArray iob = predBGs.getJSONArray("IOB");
|
||||||
|
@ -196,8 +195,8 @@ public class APSResult {
|
||||||
public long getLatestPredictionsTime() {
|
public long getLatestPredictionsTime() {
|
||||||
long latest = 0;
|
long latest = 0;
|
||||||
try {
|
try {
|
||||||
long startTime = date != null ? date.getTime() : 0;
|
long startTime = date;
|
||||||
if (json.has("predBGs")) {
|
if (json != null && json.has("predBGs")) {
|
||||||
JSONObject predBGs = json.getJSONObject("predBGs");
|
JSONObject predBGs = json.getJSONObject("predBGs");
|
||||||
if (predBGs.has("IOB")) {
|
if (predBGs.has("IOB")) {
|
||||||
JSONArray iob = predBGs.getJSONArray("IOB");
|
JSONArray iob = predBGs.getJSONArray("IOB");
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -374,7 +375,7 @@ public class NSDeviceStatus {
|
||||||
public String getUploaderStatus() {
|
public String getUploaderStatus() {
|
||||||
Iterator iter = uploaders.entrySet().iterator();
|
Iterator iter = uploaders.entrySet().iterator();
|
||||||
int minBattery = 100;
|
int minBattery = 100;
|
||||||
while(iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Map.Entry pair = (Map.Entry) iter.next();
|
Map.Entry pair = (Map.Entry) iter.next();
|
||||||
Uploader uploader = (Uploader) pair.getValue();
|
Uploader uploader = (Uploader) pair.getValue();
|
||||||
if (minBattery > uploader.battery)
|
if (minBattery > uploader.battery)
|
||||||
|
@ -388,7 +389,7 @@ public class NSDeviceStatus {
|
||||||
StringBuilder string = new StringBuilder();
|
StringBuilder string = new StringBuilder();
|
||||||
|
|
||||||
Iterator iter = uploaders.entrySet().iterator();
|
Iterator iter = uploaders.entrySet().iterator();
|
||||||
while(iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Map.Entry pair = (Map.Entry) iter.next();
|
Map.Entry pair = (Map.Entry) iter.next();
|
||||||
Uploader uploader = (Uploader) pair.getValue();
|
Uploader uploader = (Uploader) pair.getValue();
|
||||||
String device = (String) pair.getKey();
|
String device = (String) pair.getKey();
|
||||||
|
@ -398,4 +399,11 @@ public class NSDeviceStatus {
|
||||||
return Html.fromHtml(string.toString());
|
return Html.fromHtml(string.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static APSResult getAPSResult() {
|
||||||
|
APSResult result = new APSResult();
|
||||||
|
result.json = deviceStatusOpenAPSData.suggested;
|
||||||
|
result.date = deviceStatusOpenAPSData.clockSuggested;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,18 @@ import org.mozilla.javascript.NativeObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
||||||
public class DetermineBasalResultAMA extends APSResult {
|
public class DetermineBasalResultAMA extends APSResult {
|
||||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalResultAMA.class);
|
private static Logger log = LoggerFactory.getLogger(DetermineBasalResultAMA.class);
|
||||||
|
|
||||||
public double eventualBG;
|
private double eventualBG;
|
||||||
public double snoozeBG;
|
private double snoozeBG;
|
||||||
|
|
||||||
public DetermineBasalResultAMA(NativeObject result, JSONObject j) {
|
DetermineBasalResultAMA(NativeObject result, JSONObject j) {
|
||||||
this();
|
this();
|
||||||
date = new Date();
|
date = DateUtil.now();
|
||||||
json = j;
|
json = j;
|
||||||
if (result.containsKey("error")) {
|
if (result.containsKey("error")) {
|
||||||
reason = result.get("error").toString();
|
reason = result.get("error").toString();
|
||||||
|
|
|
@ -5,22 +5,20 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
||||||
public class DetermineBasalResultSMB extends APSResult {
|
public class DetermineBasalResultSMB extends APSResult {
|
||||||
private static final Logger log = LoggerFactory.getLogger(DetermineBasalResultSMB.class);
|
private static final Logger log = LoggerFactory.getLogger(DetermineBasalResultSMB.class);
|
||||||
|
|
||||||
public double eventualBG;
|
private double eventualBG;
|
||||||
public double snoozeBG;
|
private double snoozeBG;
|
||||||
public double insulinReq;
|
//public double insulinReq;
|
||||||
public double carbsReq;
|
//public double carbsReq;
|
||||||
|
|
||||||
public DetermineBasalResultSMB(JSONObject result) {
|
DetermineBasalResultSMB(JSONObject result) {
|
||||||
this();
|
this();
|
||||||
date = new Date();
|
date = DateUtil.now();
|
||||||
json = result;
|
json = result;
|
||||||
try {
|
try {
|
||||||
if (result.has("error")) {
|
if (result.has("error")) {
|
||||||
|
@ -31,8 +29,8 @@ public class DetermineBasalResultSMB extends APSResult {
|
||||||
reason = result.getString("reason");
|
reason = result.getString("reason");
|
||||||
if (result.has("eventualBG")) eventualBG = result.getDouble("eventualBG");
|
if (result.has("eventualBG")) eventualBG = result.getDouble("eventualBG");
|
||||||
if (result.has("snoozeBG")) snoozeBG = result.getDouble("snoozeBG");
|
if (result.has("snoozeBG")) snoozeBG = result.getDouble("snoozeBG");
|
||||||
if (result.has("insulinReq")) insulinReq = result.getDouble("insulinReq");
|
//if (result.has("insulinReq")) insulinReq = result.getDouble("insulinReq");
|
||||||
if (result.has("carbsReq")) carbsReq = result.getDouble("carbsReq");
|
//if (result.has("carbsReq")) carbsReq = result.getDouble("carbsReq");
|
||||||
|
|
||||||
if (result.has("rate") && result.has("duration")) {
|
if (result.has("rate") && result.has("duration")) {
|
||||||
tempBasalRequested = true;
|
tempBasalRequested = true;
|
||||||
|
@ -64,7 +62,7 @@ public class DetermineBasalResultSMB extends APSResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetermineBasalResultSMB() {
|
private DetermineBasalResultSMB() {
|
||||||
hasPredictions = true;
|
hasPredictions = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress;
|
||||||
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||||
|
@ -343,7 +344,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||||
final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
|
boolean predictionsAvailable;
|
||||||
|
if (Config.APS)
|
||||||
|
predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
|
||||||
|
else if (Config.NSCLIENT)
|
||||||
|
predictionsAvailable = true;
|
||||||
|
else
|
||||||
|
predictionsAvailable = false;
|
||||||
|
|
||||||
MenuItem item;
|
MenuItem item;
|
||||||
CharSequence title;
|
CharSequence title;
|
||||||
|
@ -1355,7 +1362,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
cobView.setText(cobText);
|
cobView.setText(cobText);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
|
boolean predictionsAvailable;
|
||||||
|
if (Config.APS)
|
||||||
|
predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
|
||||||
|
else if (Config.NSCLIENT)
|
||||||
|
predictionsAvailable = true;
|
||||||
|
else
|
||||||
|
predictionsAvailable = false;
|
||||||
|
final boolean finalPredictionsAvailable = predictionsAvailable;
|
||||||
|
|
||||||
// pump status from ns
|
// pump status from ns
|
||||||
if (pumpDeviceStatusView != null) {
|
if (pumpDeviceStatusView != null) {
|
||||||
pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus());
|
pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus());
|
||||||
|
@ -1398,8 +1413,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final long toTime;
|
final long toTime;
|
||||||
final long fromTime;
|
final long fromTime;
|
||||||
final long endTime;
|
final long endTime;
|
||||||
if (predictionsAvailable && SP.getBoolean("showprediction", false)) {
|
|
||||||
int predHours = (int) (Math.ceil(finalLastRun.constraintsProcessed.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000));
|
APSResult apsResult;
|
||||||
|
if (Config.APS)
|
||||||
|
apsResult = finalLastRun.constraintsProcessed;
|
||||||
|
else
|
||||||
|
apsResult = NSDeviceStatus.getAPSResult();
|
||||||
|
|
||||||
|
if (finalPredictionsAvailable && SP.getBoolean("showprediction", false)) {
|
||||||
|
int predHours = (int) (Math.ceil(apsResult.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000));
|
||||||
predHours = Math.min(2, predHours);
|
predHours = Math.min(2, predHours);
|
||||||
predHours = Math.max(0, predHours);
|
predHours = Math.max(0, predHours);
|
||||||
hoursToFetch = rangeToDisplay - predHours;
|
hoursToFetch = rangeToDisplay - predHours;
|
||||||
|
@ -1425,9 +1447,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
||||||
|
|
||||||
// **** BG ****
|
// **** BG ****
|
||||||
if (predictionsAvailable && SP.getBoolean("showprediction", false))
|
if (finalPredictionsAvailable && SP.getBoolean("showprediction", false))
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine,
|
graphData.addBgReadings(fromTime, toTime, lowLine, highLine,
|
||||||
finalLastRun.constraintsProcessed.getPredictions());
|
apsResult.getPredictions());
|
||||||
else
|
else
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null);
|
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue