From 73e8a0c8763949957d20c502ae12f8402aa27ace Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 23 Jun 2018 11:36:23 +0200 Subject: [PATCH] Rename BgReading.filtered to BgReading.isFiltered and add to NS. Avoids collision with 'filtered' value in NS data. --- .../java/info/nightscout/androidaps/db/BgReading.java | 6 +++--- .../info/nightscout/androidaps/db/DatabaseHelper.java | 2 +- .../androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 6 +++--- .../androidaps/plugins/Source/SourceDexcomG5Plugin.java | 5 +---- .../androidaps/plugins/Source/SourceGlimpPlugin.java | 2 +- .../androidaps/plugins/Source/SourceMM640gPlugin.java | 2 +- .../androidaps/plugins/Source/SourceNSClientPlugin.java | 2 +- .../androidaps/plugins/Source/SourcePoctechPlugin.java | 2 +- .../androidaps/plugins/Source/SourceXdripPlugin.java | 6 +++--- app/src/main/java/info/nightscout/utils/NSUpload.java | 2 ++ .../androidaps/plugins/Source/SourceXdripPluginTest.java | 8 ++++---- 11 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index 322f46100d..3ecc969fc6 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -39,7 +39,7 @@ public class BgReading implements DataPointWithLabelInterface { @DatabaseField public double noise = -999; // xDrip sends -999 to indicate lack of a noise reading (due to missed readings or calibration) @DatabaseField - public boolean filtered; + public boolean isFiltered; @DatabaseField public String sourcePlugin; @@ -124,7 +124,7 @@ public class BgReading implements DataPointWithLabelInterface { ", value=" + value + ", direction=" + direction + ", raw=" + raw + - ", filtered=" + filtered + + ", filtered=" + isFiltered + ", sourcePlugin=" + sourcePlugin + '}'; } @@ -156,7 +156,7 @@ public class BgReading implements DataPointWithLabelInterface { _id = other._id; noise = other.noise; sourcePlugin = other.sourcePlugin; - filtered = other.filtered; + isFiltered = other.isFiltered; } // ------------------ DataPointWithLabelInterface ------------------ 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 8dba0a7919..868e44b65e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -120,7 +120,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { // soft migration without changing DB version createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, - "filtered", "integer"); + "isFiltered", "integer"); createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, "sourcePlugin", "text"); createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, 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 9281be6e6f..0f66501e58 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 @@ -192,8 +192,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { MainApp.getConstraintChecker().isSMBModeEnabled(smbAllowed); inputConstraints.copyReasons(smbAllowed); - Constraint bgFiltered = new Constraint<>(bgReading.filtered); - if (!bgReading.filtered) { + Constraint bgFiltered = new Constraint<>(bgReading.isFiltered); + if (!bgReading.isFiltered) { bgFiltered.set(false, MainApp.gs(R.string.smbalwaysdisabled), this); } inputConstraints.copyReasons(bgFiltered); @@ -207,7 +207,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { lastAutosensResult.ratio, //autosensDataRatio isTempTarget, smbAllowed.value(), - bgReading.filtered + bgReading.isFiltered ); } catch (JSONException e) { log.error(e.getMessage()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java index 80785ec7fe..8d442d4d70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java @@ -2,8 +2,6 @@ package info.nightscout.androidaps.plugins.Source; import android.os.Bundle; -import com.google.common.collect.Lists; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -11,7 +9,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import info.nightscout.androidaps.Config; @@ -70,7 +67,7 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac bgReading.direction = json.getString("m_trend"); bgReading.date = json.getLong("m_time") * 1000L; bgReading.raw = 0; - bgReading.filtered = true; + bgReading.isFiltered = true; bgReading.sourcePlugin = getName(); boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); if (isNew) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java index ee9ff1424f..b5fb2ca294 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java @@ -45,7 +45,7 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface { bgReading.direction = bundle.getString("myTrend"); bgReading.date = bundle.getLong("myTimestamp"); bgReading.raw = 0; - bgReading.filtered = false; + bgReading.isFiltered = false; bgReading.sourcePlugin = getName(); boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java index 84a3cd5427..196529f1d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java @@ -64,7 +64,7 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface bgReading.direction = json_object.getString("direction"); bgReading.date = json_object.getLong("date"); bgReading.raw = json_object.getDouble("sgv"); - bgReading.filtered = true; + bgReading.isFiltered = true; bgReading.sourcePlugin = getName(); boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java index 43fff2eae5..c40fbb4806 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -67,7 +67,7 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac JSONObject sgvJson = jsonArray.getJSONObject(i); BgReading bgReading = new BgReading(new NSSgv(sgvJson)); String sourceDescription = JsonHelper.safeGetString(sgvJson, "device"); - bgReading.filtered = sourceDescription != null + bgReading.isFiltered = sourceDescription != null && (sourceDescription.contains("G5 Native") || sourceDescription.contains("AndroidAPS-DexcomG5")); bgReading.sourcePlugin = getName(); boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java index a2953eb2cd..2ed3ca0cf7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java @@ -66,7 +66,7 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface bgReading.direction = json.getString("direction"); bgReading.date = json.getLong("date"); bgReading.raw = json.getDouble("raw"); - bgReading.filtered = false; + bgReading.isFiltered = false; bgReading.sourcePlugin = getName(); if (JsonHelper.safeGetString(json, "utils", Constants.MGDL).equals("mmol/L")) bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java index 9c90ae8249..c97a01e516 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -52,12 +52,12 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW); bgReading.noise = bundle.getDouble(Intents.EXTRA_NOISE, -999); String sourceDescription = bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, ""); - bgReading.filtered = sourceDescription.equals("G5 Native"); - if (MainApp.engineeringMode && !bgReading.filtered && bgReading.noise >= 0 && bgReading.noise <= 4) { + bgReading.isFiltered = sourceDescription.equals("G5 Native"); + if (MainApp.engineeringMode && !bgReading.isFiltered && bgReading.noise >= 0 && bgReading.noise <= 4) { // TODO syncing noice with NS is neither implemented nor tested // * NSUpload.uploadBg log.debug("Setting filtered=true, since noise is provided and passed check: " + bgReading.noise); - bgReading.filtered = true; + bgReading.isFiltered = true; } bgReading.sourcePlugin = getName(); diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 00d5e39821..a425cc5d52 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -469,6 +469,8 @@ public class NSUpload { data.put("sgv", reading.value); data.put("direction", reading.direction); data.put("type", "sgv"); + data.put("isFiltered", reading.isFiltered); + data.put("sourcePlugin", reading.sourcePlugin); } catch (JSONException e) { log.error("Unhandled exception", e); } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java index 17e0544904..a21a8c0a9b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java @@ -49,7 +49,7 @@ public class SourceXdripPluginTest { public void bgWithUnknownSourceIsMarkedUnfiltered() { Bundle bundle = createBroadcastBundle(); BgReading bgReadings = plugin.processNewData(bundle).get(0); - assertFalse(bgReadings.filtered); + assertFalse(bgReadings.isFiltered); } // TODO @@ -60,7 +60,7 @@ public class SourceXdripPluginTest { bundle.putString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, "G5 Native"); BgReading bgReadings = plugin.processNewData(bundle).get(0); - assertTrue(bgReadings.filtered); + assertTrue(bgReadings.isFiltered); } // TODO @@ -71,7 +71,7 @@ public class SourceXdripPluginTest { bundle.putString(Intents.EXTRA_NOISE, "1.0"); BgReading bgReadings = plugin.processNewData(bundle).get(0); - assertTrue(bgReadings.filtered); + assertTrue(bgReadings.isFiltered); } // TODO @@ -82,7 +82,7 @@ public class SourceXdripPluginTest { bundle.putString(Intents.EXTRA_NOISE, "80.0"); BgReading bgReadings = plugin.processNewData(bundle).get(0); - assertTrue(bgReadings.filtered); + assertTrue(bgReadings.isFiltered); } @NonNull