run rendering calculations on background

This commit is contained in:
Milos Kozak 2017-06-05 15:16:07 +02:00
parent 88b9caa357
commit e0a6db22a2
7 changed files with 787 additions and 667 deletions

View file

@ -212,9 +212,6 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
@Override
public void run() {
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
danaRv2Plugin.cancelTempBasal();
}
danaRv2Plugin.setHighTempBasalPercent(50);
}
});
@ -224,9 +221,6 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
@Override
public void run() {
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
danaRv2Plugin.cancelTempBasal();
}
danaRv2Plugin.setHighTempBasalPercent(400);
}
});

View file

@ -7,6 +7,7 @@ import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
@ -155,6 +156,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
TextView sage;
TextView pbage;
TextView updating;
CheckBox showPredictionView;
CheckBox showBasalsView;
CheckBox showIobView;
@ -246,6 +249,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
updating = (TextView) view.findViewById(R.id.overview_updating);
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
@ -361,15 +366,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
switch (buttonView.getId()) {
case R.id.overview_showprediction:
SP.putBoolean("showprediction", showPredictionView.isChecked());
scheduleUpdateGUI("onPredictionCheckedChanged");
updateGUI("onPredictionCheckedChanged");
break;
case R.id.overview_showbasals:
SP.putBoolean("showbasals", showBasalsView.isChecked());
scheduleUpdateGUI("onBasalsCheckedChanged");
updateGUI("onBasalsCheckedChanged");
break;
case R.id.overview_showiob:
SP.putBoolean("showiob", showIobView.isChecked());
scheduleUpdateGUI("onIobCheckedChanged");
updateGUI("onIobCheckedChanged");
break;
case R.id.overview_showcob:
showDeviationsView.setOnCheckedChangeListener(null);
@ -377,7 +382,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showDeviationsView.setOnCheckedChangeListener(this);
SP.putBoolean("showcob", showCobView.isChecked());
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
scheduleUpdateGUI("onCobCheckedChanged");
updateGUI("onCobCheckedChanged");
break;
case R.id.overview_showdeviations:
showCobView.setOnCheckedChangeListener(null);
@ -385,7 +390,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showCobView.setOnCheckedChangeListener(this);
SP.putBoolean("showcob", showCobView.isChecked());
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
scheduleUpdateGUI("onDeviationsCheckedChanged");
updateGUI("onDeviationsCheckedChanged");
break;
}
}
@ -397,7 +402,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activeloop.setFragmentEnabled(PluginBase.LOOP, false);
activeloop.setFragmentVisible(PluginBase.LOOP, false);
MainApp.getConfigBuilder().storeSettings();
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -413,12 +418,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activeloop.setFragmentEnabled(PluginBase.LOOP, true);
activeloop.setFragmentVisible(PluginBase.LOOP, true);
MainApp.getConfigBuilder().storeSettings();
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
NSUpload.uploadOpenAPSOffline(0);
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
activeloop.suspendTo(0L);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -432,7 +437,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
activeloop.suspendTo(new Date().getTime() + 60L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -446,7 +451,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
activeloop.suspendTo(new Date().getTime() + 2 * 60L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -474,7 +479,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
activeloop.suspendTo(new Date().getTime() + 10 * 60L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -488,7 +493,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
activeloop.suspendTo(new Date().getTime() + 30L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -502,7 +507,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
activeloop.suspendTo(new Date().getTime() + 1 * 60L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -516,7 +521,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
activeloop.suspendTo(new Date().getTime() + 2 * 60L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -530,7 +535,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
activeloop.suspendTo(new Date().getTime() + 3 * 60L * 60 * 1000);
scheduleUpdateGUI("suspendmenu");
updateGUI("suspendmenu");
sHandler.post(new Runnable() {
@Override
public void run() {
@ -879,39 +884,79 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (scheduledUpdate != null)
scheduledUpdate.cancel(false);
Runnable task = new UpdateRunnable();
final int msec = 400;
final int msec = 2000;
scheduledUpdate = worker.schedule(task, msec, TimeUnit.MILLISECONDS);
}
@SuppressLint("SetTextI18n")
public void updateGUI(String from) {
log.debug("updateGUI entered from: " + from);
if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
pumpStatusView.setText(R.string.noprofileset);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
return;
}
pumpStatusLayout.setVisibility(View.GONE);
loopStatusLayout.setVisibility(View.VISIBLE);
private class updateGUIAsyncClass extends AsyncTask<String, Void, String> {
updateNotifications();
CareportalFragment.updateAge(getActivity(), sage, iage, cage, pbage);
BgReading actualBG = DatabaseHelper.actualBg();
BgReading lastBG = DatabaseHelper.lastBg();
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = profile.getUnits();
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
PumpInterface pump = MainApp.getConfigBuilder();
// Skip if not initialized yet
if (bgGraph == null)
return;
long now = new Date().getTime();
Profile profile = MainApp.getConfigBuilder().getProfile();
if (getActivity() == null)
return;
IobTotal bolusIob;
IobTotal basalIob;
Double lowLine;
Double highLine;
int hoursToFetch;
long toTime;
long fromTime;
long endTime;
boolean showPrediction;
boolean showBasals;
boolean showIob;
boolean showCob;
boolean showDeviations;
LineGraphSeries<DataPoint> basalsLineSeries;
LineGraphSeries<DataPoint> absoluteBasalsLineSeries;
LineGraphSeries<DataPoint> baseBasalsSeries;
LineGraphSeries<DataPoint> tempBasalsSeries;
AreaGraphSeries<DoubleDataPoint> areaSeries;
LineGraphSeries<DataPoint> seriesNow, seriesNow2;
PointsWithLabelGraphSeries<DataPointWithLabelInterface> bgSeries = null;
PointsWithLabelGraphSeries<DataPointWithLabelInterface> treatmentSeries = null;
class DeviationDataPoint extends DataPoint {
public int color;
public DeviationDataPoint(double x, double y, int color) {
super(x, y);
this.color = color;
}
}
FixedLineGraphSeries<DataPoint> iobSeries;
FixedLineGraphSeries<DataPoint> cobSeries;
BarGraphSeries<DeviationDataPoint> devSeries;
DataPoint[] cobData;
DeviationDataPoint[] devData;
List<BgReading> bgReadingsArray;
Double maxBgValue = 0d;
Double maxIobValueFound = 0d;
Double maxCobValueFound = 0d;
Double maxDevValueFound = 0d;
Double maxBasalValueFound = 0d;
Integer numOfHorizLines;
@Override
protected void onPreExecute() {
log.debug("updateGUIAsyncClass onPreExecute");
updating.setVisibility(View.VISIBLE);
updateNotifications();
CareportalFragment.updateAge(getActivity(), sage, iage, cage, pbage);
// open loop mode
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if (Config.APS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable) {
apsModeView.setVisibility(View.VISIBLE);
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
@ -1075,8 +1120,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
String units = profile.getUnits();
Double lowLine = SP.getDouble("low_mark", 0d);
Double highLine = SP.getDouble("high_mark", 0d);
lowLine = SP.getDouble("low_mark", 0d);
highLine = SP.getDouble("high_mark", 0d);
if (lowLine < 1) {
lowLine = Profile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units);
}
@ -1122,17 +1167,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
int agoMin = (int) (agoMsec / 60d / 1000d);
timeAgoView.setText(String.format(MainApp.sResources.getString(R.string.minago), agoMin));
// iob
MainApp.getConfigBuilder().updateTotalIOBTreatments();
MainApp.getConfigBuilder().updateTotalIOBTempBasals();
IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
iobView.setText(iobtext);
// cob
if (cobView != null) { // view must not exists
String cobText = "";
@ -1142,7 +1176,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobView.setText(cobText);
}
boolean showPrediction = showPredictionView.isChecked() && finalLastRun != null && finalLastRun.constraintsProcessed.getClass().equals(DetermineBasalResultAMA.class);
if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS)) {
showPredictionView.setVisibility(View.VISIBLE);
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
@ -1161,10 +1194,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
calendar.set(Calendar.MINUTE, 0);
calendar.add(Calendar.HOUR, 1);
int hoursToFetch;
long toTime;
long fromTime;
long endTime;
showPrediction = showPredictionView.isChecked() && finalLastRun != null && finalLastRun.constraintsProcessed.getClass().equals(DetermineBasalResultAMA.class);
showBasals = showBasalsView.isChecked();
showIob = showIobView.isChecked();
showCob = showCobView.isChecked();
showDeviations = showDeviationsView.isChecked();
if (showPrediction) {
int predHours = (int) (Math.ceil(((DetermineBasalResultAMA) finalLastRun.constraintsProcessed).getLatestPredictionsTime() - new Date().getTime()) / (60 * 60 * 1000));
predHours = Math.min(2, predHours);
@ -1180,18 +1215,45 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
endTime = toTime;
}
LineGraphSeries<DataPoint> basalsLineSeries = null;
LineGraphSeries<DataPoint> absoluteBasalsLineSeries = null;
LineGraphSeries<DataPoint> baseBasalsSeries = null;
LineGraphSeries<DataPoint> tempBasalsSeries = null;
AreaGraphSeries<DoubleDataPoint> areaSeries;
LineGraphSeries<DataPoint> seriesNow, seriesNow2;
// **** HIGH and LOW targets graph ****
DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{
new DoubleDataPoint(fromTime, lowLine, highLine),
new DoubleDataPoint(endTime, lowLine, highLine)
};
bgGraph.addSeries(areaSeries = new AreaGraphSeries<>(areaDataPoints));
areaSeries.setColor(0);
areaSeries.setDrawBackground(true);
areaSeries.setBackgroundColor(Color.argb(40, 0, 255, 0));
// set manual x bounds to have nice steps
bgGraph.getViewport().setMaxX(endTime);
bgGraph.getViewport().setMinX(fromTime);
bgGraph.getViewport().setXAxisBoundsManual(true);
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
iobGraph.getViewport().setMaxX(endTime);
iobGraph.getViewport().setMinX(fromTime);
iobGraph.getViewport().setXAxisBoundsManual(true);
iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
}
@Override
protected String doInBackground(String... params) {
log.debug("updateGUIAsyncClass starting background calculations from: " + params[0]);
// IOB
MainApp.getConfigBuilder().updateTotalIOBTreatments();
MainApp.getConfigBuilder().updateTotalIOBTempBasals();
bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
// ****** GRAPH *******
// **** TEMP BASALS graph ****
Double maxBasalValueFound = 0d;
long now = new Date().getTime();
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
if (pump.getPumpDescription().isTempBasalCapable && showBasals) {
List<DataPoint> baseBasalArray = new ArrayList<>();
List<DataPoint> tempBasalArray = new ArrayList<>();
List<DataPoint> basalLineArray = new ArrayList<>();
@ -1284,39 +1346,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
// **** IOB COB DEV graph ****
class DeviationDataPoint extends DataPoint {
public int color;
public DeviationDataPoint(double x, double y, int color) {
super(x, y);
this.color = color;
}
}
FixedLineGraphSeries<DataPoint> iobSeries;
FixedLineGraphSeries<DataPoint> cobSeries;
BarGraphSeries<DeviationDataPoint> devSeries;
Double maxIobValueFound = 0d;
Double maxCobValueFound = 0d;
Double maxDevValueFound = 0d;
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked()) {
if (showIob || showCob || showDeviations) {
//Date start = new Date();
List<DataPoint> iobArray = new ArrayList<>();
List<DataPoint> cobArray = new ArrayList<>();
List<DeviationDataPoint> devArray = new ArrayList<>();
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
if (showIobView.isChecked()) {
if (showIob) {
IobTotal iob = IobCobCalculatorPlugin.calulateFromTreatmentsAndTemps(time);
iobArray.add(new DataPoint(time, iob.iob));
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob.iob));
}
if (showCobView.isChecked() || showDeviationsView.isChecked()) {
if (showCob || showDeviations) {
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
if (autosensData != null && showCobView.isChecked()) {
if (autosensData != null && showCob) {
cobArray.add(new DataPoint(time, autosensData.cob));
maxCobValueFound = Math.max(maxCobValueFound, autosensData.cob);
}
if (autosensData != null && showDeviationsView.isChecked()) {
if (autosensData != null && showDeviations) {
int color = Color.BLACK; // "="
if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY;
if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN;
@ -1336,7 +1384,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
iobSeries.setThickness(3);
if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) {
if (showIob && (showCob || showDeviations)) {
List<DataPoint> cobArrayRescaled = new ArrayList<>();
List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
for (int ci = 0; ci < cobArray.size(); ci++) {
@ -1349,7 +1397,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
devArray = devArrayRescaled;
}
// COB
DataPoint[] cobData = new DataPoint[cobArray.size()];
cobData = new DataPoint[cobArray.size()];
cobData = cobArray.toArray(cobData);
cobSeries = new FixedLineGraphSeries<>(cobData);
cobSeries.setDrawBackground(true);
@ -1358,7 +1406,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobSeries.setThickness(3);
// DEVIATIONS
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
devData = new DeviationDataPoint[devArray.size()];
devData = devArray.toArray(devData);
devSeries = new BarGraphSeries<>(devData);
devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
@ -1367,61 +1415,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return data.color;
}
});
//devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
//devSeries.setColor(MainApp.sResources.getColor(R.color.cob));
//devSeries.setThickness(3);
iobGraph.removeAllSeries();
if (showIobView.isChecked()) {
iobGraph.addSeries(iobSeries);
}
if (showCobView.isChecked() && cobData.length > 0) {
iobGraph.addSeries(cobSeries);
}
if (showDeviationsView.isChecked() && devData.length > 0) {
iobGraph.addSeries(devSeries);
}
iobGraph.setVisibility(View.VISIBLE);
} else {
iobGraph.setVisibility(View.GONE);
}
// remove old data from graph
bgGraph.getSecondScale().getSeries().clear();
bgGraph.removeAllSeries();
// **** HIGH and LOW targets graph ****
DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{
new DoubleDataPoint(fromTime, lowLine, highLine),
new DoubleDataPoint(endTime, lowLine, highLine)
};
bgGraph.addSeries(areaSeries = new AreaGraphSeries<>(areaDataPoints));
areaSeries.setColor(0);
areaSeries.setDrawBackground(true);
areaSeries.setBackgroundColor(Color.argb(40, 0, 255, 0));
// set manual x bounds to have nice steps
bgGraph.getViewport().setMaxX(endTime);
bgGraph.getViewport().setMinX(fromTime);
bgGraph.getViewport().setXAxisBoundsManual(true);
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
iobGraph.getViewport().setMaxX(endTime);
iobGraph.getViewport().setMinX(fromTime);
iobGraph.getViewport().setXAxisBoundsManual(true);
iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
// **** BG graph ****
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
if (bgReadingsArray.size() == 0)
return;
Iterator<BgReading> it = bgReadingsArray.iterator();
Double maxBgValue = 0d;
while (it.hasNext()) {
BgReading bg = it.next();
if (bg.value > maxBgValue) maxBgValue = bg.value;
@ -1440,13 +1440,86 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
if (highLine > maxBgValue) maxBgValue = highLine;
Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()];
bg = bgListArray.toArray(bg);
if (bg.length > 0)
bgSeries = new PointsWithLabelGraphSeries<>(bg);
if (bg.length > 0) {
bgGraph.addSeries(new PointsWithLabelGraphSeries<>(bg));
// **** treatments graph ****
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
for (int tx = 0; tx < treatments.size(); tx++) {
DataPointWithLabelInterface t = treatments.get(tx);
if (t.getX() < fromTime || t.getX() > endTime) continue;
t.setY(getNearestBg((long) t.getX(), bgReadingsArray));
filteredTreatments.add(t);
}
// ProfileSwitch
List<ProfileSwitch> profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList();
for (int tx = 0; tx < profileSwitches.size(); tx++) {
DataPointWithLabelInterface t = profileSwitches.get(tx);
if (t.getX() < fromTime || t.getX() > endTime) continue;
filteredTreatments.add(t);
}
DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()];
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
if (treatmentsArray.length > 0) {
treatmentSeries = new PointsWithLabelGraphSeries<>(treatmentsArray);
}
return params[0];
}
@Override
protected void onPostExecute(String result) {
log.debug("updateGUIAsyncClass onPostExecute");
// IOB
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
iobView.setText(iobtext);
// ****** GRAPH *******
// **** IOB COB DEV graph ****
if (showIob || showCob || showDeviations) {
iobGraph.removeAllSeries();
if (showIob) {
iobGraph.addSeries(iobSeries);
}
if (showCob && cobData.length > 0) {
iobGraph.addSeries(cobSeries);
}
if (showDeviations && devData.length > 0) {
iobGraph.addSeries(devSeries);
}
iobGraph.setVisibility(View.VISIBLE);
} else {
iobGraph.setVisibility(View.GONE);
}
// remove old data from graph
bgGraph.getSecondScale().getSeries().clear();
bgGraph.removeAllSeries();
// **** BG graph ****
if (bgSeries != null) {
bgGraph.addSeries(bgSeries);
}
// **** treatments graph ****
if (treatmentSeries != null) {
bgGraph.addSeries(treatmentSeries);
}
// **** NOW line ****
@ -1472,34 +1545,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
seriesNow.setCustomPaint(paint);
seriesNow2.setCustomPaint(paint);
// Treatments
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
for (int tx = 0; tx < treatments.size(); tx++) {
DataPointWithLabelInterface t = treatments.get(tx);
if (t.getX() < fromTime || t.getX() > endTime) continue;
t.setY(getNearestBg((long) t.getX(), bgReadingsArray));
filteredTreatments.add(t);
}
// ProfileSwitch
List<ProfileSwitch> profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList();
for (int tx = 0; tx < profileSwitches.size(); tx++) {
DataPointWithLabelInterface t = profileSwitches.get(tx);
if (t.getX() < fromTime || t.getX() > endTime) continue;
filteredTreatments.add(t);
}
DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()];
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
if (treatmentsArray.length > 0) {
bgGraph.addSeries(new PointsWithLabelGraphSeries<>(treatmentsArray));
}
// set manual y bounds to have nice steps
bgGraph.getViewport().setMaxY(maxBgValue);
bgGraph.getViewport().setMinY(0);
@ -1507,7 +1552,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines);
// set second scale
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
if (pump.getPumpDescription().isTempBasalCapable && showBasals) {
bgGraph.getSecondScale().addSeries(baseBasalsSeries);
bgGraph.getSecondScale().addSeries(tempBasalsSeries);
bgGraph.getSecondScale().addSeries(basalsLineSeries);
@ -1526,7 +1571,27 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
});
updating.setVisibility(View.GONE);
}
}
public void updateGUIAsync(String from) {
new updateGUIAsyncClass().execute(from);
}
@SuppressLint("SetTextI18n")
public void updateGUI(String from) {
log.debug("updateGUI entered from: " + from);
if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
pumpStatusView.setText(R.string.noprofileset);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
return;
}
pumpStatusLayout.setVisibility(View.GONE);
loopStatusLayout.setVisibility(View.VISIBLE);
updateGUIAsync(from);
}
public double getNearestBg(long date, List<BgReading> bgReadingsArray) {

View file

@ -294,10 +294,30 @@
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content"
android:layout_height="160dip" />
android:layout_height="160dip"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/overview_updating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/updating"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/updating"
android:textStyle="bold" />
</RelativeLayout>
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_iobgraph"

View file

@ -294,10 +294,30 @@
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content"
android:layout_height="160dip" />
android:layout_height="160dip"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/overview_updating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/updating"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/updating"
android:textStyle="bold" />
</RelativeLayout>
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_iobgraph"

View file

@ -503,11 +503,30 @@
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
android:layout_height="160dip"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/overview_updating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/updating"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/updating"
android:textStyle="bold" />
</RelativeLayout>
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_iobgraph"

View file

@ -11,6 +11,7 @@
<color name="tabBgColor">#f0003f59</color>
<color name="tabBgColorSelected">#FF33B5E5</color>
<color name="deviations">#FF0000</color>
<color name="updating">#50ffffff</color>
<color name="defaultbackground">#424242</color>

View file

@ -625,4 +625,5 @@
<string name="invalidprofile">Invalid profile !!!</string>
<string name="profileswitch">ProfileSwitch</string>
<string name="careportal_pbage_label">Pump battery age</string>
<string name="updating">Updating ...</string>
</resources>