Process xDrip noise data if provided (engineering mode only).

This commit is contained in:
Johannes Mockenhaupt 2018-06-23 11:21:05 +02:00
parent 34ee125666
commit b4db98fa1d
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 15 additions and 2 deletions

View file

@ -38,6 +38,7 @@ public interface Intents {
String EXTRA_TIMESTAMP = "com.eveningoutpost.dexdrip.Extras.Time";
String EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw";
String XDRIP_DATA_SOURCE_DESCRIPTION = "com.eveningoutpost.dexdrip.Extras.SourceDesc";
String EXTRA_NOISE = "com.eveningoutpost.dexdrip.Extras.Noise";
String ACTION_NEW_BG_ESTIMATE_NO_DATA = "com.eveningoutpost.dexdrip.BgEstimateNoData";

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.db;
import android.content.res.Resources;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
@ -39,6 +37,8 @@ public class BgReading implements DataPointWithLabelInterface {
@DatabaseField
public double raw;
@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;
@DatabaseField
public String sourcePlugin;
@ -154,6 +154,7 @@ public class BgReading implements DataPointWithLabelInterface {
raw = other.raw;
direction = other.direction;
_id = other._id;
noise = other.noise;
sourcePlugin = other.sourcePlugin;
filtered = other.filtered;
}

View file

@ -123,6 +123,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
"filtered", "integer");
createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS,
"sourcePlugin", "text");
createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS,
"noise", "real");
} catch (SQLException e) {
log.error("Can't create database", e);

View file

@ -4,6 +4,9 @@ import android.os.Bundle;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
@ -20,6 +23,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
* Created by mike on 05.08.2016.
*/
public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
private static final Logger log = LoggerFactory.getLogger(SourceXdripPlugin.class);
private static SourceXdripPlugin plugin = null;
@ -46,8 +50,13 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
bgReading.direction = bundle.getString(Intents.EXTRA_BG_SLOPE_NAME);
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
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) {
log.debug("Setting filtered=true, since noise is provided and passed check: " + bgReading.noise);
bgReading.filtered = true;
}
bgReading.sourcePlugin = getName();
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());