diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5d19981032..fbb68289f4 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java
index a5ef1bef47..47d230bb02 100644
--- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java
+++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java
@@ -29,6 +29,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
+import info.nightscout.utils.Round;
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
@@ -227,6 +228,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
this.delta = delta;
this.avgdelta = avgdelta;
}
+
+ public GlucoseStatus round() {
+ this.glucose = Round.roundTo(this.glucose, 0.1);
+ this.delta = Round.roundTo(this.delta, 0.01);
+ this.avgdelta = Round.roundTo(this.avgdelta, 0.01);
+ return this;
+ }
}
@Nullable
@@ -284,6 +292,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
e.printStackTrace();
return null;
}
+ result.round();
return result;
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java
index de09782ddd..c25200ceb5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java
@@ -132,8 +132,8 @@ public class DetermineBasalAdapterJS implements Parcelable {
mV8rt.add(PARAM_iobData, mIobData);
// Glucose status
mGlucoseStatus = new V8Object(mV8rt);
- mGlucoseStatus.add("delta", 0);
mGlucoseStatus.add("glucose", 0);
+ mGlucoseStatus.add("delta", 0);
mGlucoseStatus.add("avgdelta", 0);
mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus);
// Meal data
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResult.java
index c023bad6b5..cd955d32ca 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResult.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResult.java
@@ -32,7 +32,7 @@ public class DetermineBasalResult extends APSResult {
}
if (result.contains("duration")) {
duration = result.getInteger("duration");
- changeRequested = changeRequested & true;
+ changeRequested = changeRequested;
} else {
duration = -1;
changeRequested = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/IobTotal.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/IobTotal.java
index 0b167b8a94..77e3786313 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/IobTotal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/IobTotal.java
@@ -6,6 +6,7 @@ import org.json.JSONObject;
import java.util.Date;
import info.nightscout.utils.DateUtil;
+import info.nightscout.utils.Round;
public class IobTotal {
public Double iob;
@@ -50,6 +51,16 @@ public class IobTotal {
return result;
}
+ public IobTotal round() {
+ this.iob = Round.roundTo(this.iob, 0.001);
+ this.activity = Round.roundTo(this.activity, 0.0001);
+ this.bolussnooze = Round.roundTo(this.bolussnooze, 0.0001);
+ this.basaliob = Round.roundTo(this.basaliob, 0.001);
+ this.netbasalinsulin = Round.roundTo(this.netbasalinsulin, 0.001);
+ this.hightempinsulin = Round.roundTo(this.hightempinsulin, 0.001);
+ return this;
+ }
+
public JSONObject json() {
JSONObject json = new JSONObject();
try {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
index bdae0f057c..3fb86d4ee7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
@@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.ScriptReader;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
+import info.nightscout.utils.Round;
public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, PluginBase, APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class);
@@ -262,6 +263,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
double maxBasal = Double.parseDouble(SP.getString("openapsma_max_basal", "1").replace(",", "."));
double minBg = NSProfile.toMgdl(Double.parseDouble(SP.getString("openapsma_min_bg", minBgDefault).replace(",", ".")), units);
double maxBg = NSProfile.toMgdl(Double.parseDouble(SP.getString("openapsma_max_bg", maxBgDefault).replace(",", ".")), units);
+ minBg = Round.roundTo(minBg, 1d);
+ maxBg = Round.roundTo(maxBg, 1d);
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
@@ -270,7 +273,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
- IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob);
+ IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
TreatmentsFragment.MealData mealData = treatments.getMealData();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialogFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialogFragment.java
index 6188808545..25df14a849 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialogFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialogFragment.java
@@ -244,7 +244,7 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
calculatedTotalInsulin = 0d;
totalInsulin.setText("");
} else {
- calculatedTotalInsulin = roundTo(calculatedTotalInsulin, 0.05d);
+ calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, 0.05d);
total.setText("");
totalInsulin.setText(numberFormat.format(calculatedTotalInsulin) + "U");
}
@@ -260,11 +260,4 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
wizardDialogDeliverButton.setVisibility(Button.GONE);
}
}
-
- private Double roundTo(Double x, Double step) {
- if (x != 0d) {
- return Math.round(x / step) * step;
- }
- return 0d;
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java
new file mode 100644
index 0000000000..de4392b094
--- /dev/null
+++ b/app/src/main/java/info/nightscout/utils/Round.java
@@ -0,0 +1,13 @@
+package info.nightscout.utils;
+
+/**
+ * Created by mike on 20.06.2016.
+ */
+public class Round {
+ public static Double roundTo(Double x, Double step) {
+ if (x != 0d) {
+ return Math.round(x / step) * step;
+ }
+ return 0d;
+ }
+}