public static Accuracy create(BloodTest bloodTest, BestGlucose.DisplayGlucose dg) { if (dg == null) return null; final BgReading from_dg = new BgReading(); from_dg.timestamp = dg.timestamp; from_dg.calculated_value = dg.mgdl; return create(bloodTest, from_dg, dg.plugin_name); }
public static Accuracy create(BloodTest bloodTest, BestGlucose.DisplayGlucose dg) { if (dg == null) return null; final BgReading from_dg = new BgReading(); from_dg.timestamp = dg.timestamp; from_dg.calculated_value = dg.mgdl; return create(bloodTest, from_dg, dg.plugin_name); }
static List<BgReading> createlatestTest(String input, Long now) { Random randomGenerator = new Random(); List<BgReading> out = new LinkedList<BgReading> (); char[] chars= input.toCharArray(); for(int i=0; i < chars.length; i++) { BgReading bg = new BgReading(); int rand = randomGenerator.nextInt(20000) - 10000; bg.timestamp = now - i * 5 * 60000 + rand; bg.raw_data = 150; if(chars[i] == 'g') { bg.filtered_data = 151; } else if (chars[i] == 'b') { bg.filtered_data = 110; } else { continue; } out.add(bg); } return out; } static void TestgetUnclearTime(String input, Long interstingTime, Long expectedResult) {
static List<BgReading> createlatestTest(String input, Long now) { Random randomGenerator = new Random(); List<BgReading> out = new LinkedList<BgReading> (); char[] chars= input.toCharArray(); for(int i=0; i < chars.length; i++) { BgReading bg = new BgReading(); int rand = randomGenerator.nextInt(20000) - 10000; bg.timestamp = now - i * 5 * 60000 + rand; bg.raw_data = 150; if(chars[i] == 'g') { bg.filtered_data = 151; } else if (chars[i] == 'b') { bg.filtered_data = 110; } else { continue; } out.add(bg); } return out; } static void TestgetUnclearTime(String input, Long interstingTime, Long expectedResult) {
static List<BgReading> createlatestTest(String input, Long now) { Random randomGenerator = new Random(); List<BgReading> out = new LinkedList<BgReading> (); char[] chars= input.toCharArray(); for(int i=0; i < chars.length; i++) { BgReading bg = new BgReading(); int rand = randomGenerator.nextInt(20000) - 10000; bg.timestamp = now - i * 5 * 60000 + rand; bg.raw_data = 150; if(chars[i] == 'g') { bg.filtered_data = 151; } else if (chars[i] == 'b') { bg.filtered_data = 110; } else { continue; } out.add(bg); } return out; } static void TestgetUnclearTime(String input, Long interstingTime, Long expectedResult) {
private void addMockBgReading(int raw_data, int minutes, Sensor sensor) { BgReading mockReading = new BgReading(); mockReading.raw_data = raw_data; mockReading.timestamp = System.currentTimeMillis() - (1000 * 60 * minutes); mockReading.sensor = sensor; mockReading.age_adjusted_raw_value = raw_data + 0.1; mockReading.save(); } }
private static BgReading getGoodMockBgReading(long ago) { final BgReading bg = new BgReading(); bg.raw_data = 123; bg.timestamp = JoH.tsl() - ago; // current timestamp bg.noise = "MOCK DATA - DO NOT USE"; return bg; }
private void addMockBgReading(int raw_data, int minutes, Sensor sensor) { BgReading mockReading = new BgReading(); mockReading.raw_data = raw_data; mockReading.calculated_value = raw_data; mockReading.timestamp = System.currentTimeMillis() - (1000 * 60 * minutes); mockReading.sensor = sensor; mockReading.age_adjusted_raw_value = raw_data + 0.1; mockReading.save(); } }
private static BgReading getGoodMockBgReading(long ago) { final BgReading bg = new BgReading(); bg.raw_data = 123; bg.timestamp = JoH.tsl() - ago; // current timestamp bg.noise = "MOCK DATA - DO NOT USE"; return bg; }
private void addMockBgReading(int raw_data, int minutes, Sensor sensor) { BgReading mockReading = new BgReading(); mockReading.raw_data = raw_data; mockReading.timestamp = System.currentTimeMillis() - (1000 * 60 * minutes); mockReading.sensor = sensor; mockReading.age_adjusted_raw_value = raw_data + 0.1; mockReading.save(); } }
private void addMockBgReading(int raw_data, int minutes, Sensor sensor) { BgReading mockReading = new BgReading(); mockReading.raw_data = raw_data; mockReading.calculated_value = raw_data; mockReading.timestamp = System.currentTimeMillis() - (1000 * 60 * minutes); mockReading.sensor = sensor; mockReading.age_adjusted_raw_value = raw_data + 0.1; mockReading.save(); } }
public static void create(SensorRecord sensorRecord, long addativeOffset, Context context) { Log.i(TAG, "create: gonna make some sensor records: " + sensorRecord.getUnfiltered()); if (BgReading.is_new(sensorRecord, addativeOffset)) { BgReading bgReading = new BgReading(); Sensor sensor = Sensor.currentSensor(); Calibration calibration = Calibration.getForTimestamp(sensorRecord.getSystemTime().getTime() + addativeOffset); if (sensor != null && calibration != null) { bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.calibration = calibration; bgReading.calibration_uuid = calibration.uuid; bgReading.raw_data = (sensorRecord.getUnfiltered() / 1000); bgReading.filtered_data = (sensorRecord.getFiltered() / 1000); bgReading.timestamp = sensorRecord.getSystemTime().getTime() + addativeOffset; if (bgReading.timestamp > new Date().getTime()) { return; } bgReading.uuid = UUID.randomUUID().toString(); bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at; bgReading.calculateAgeAdjustedRawValue(); bgReading.save(); } } }
public static void create(SensorRecord sensorRecord, long addativeOffset, Context context) { Log.i(TAG, "create: gonna make some sensor records: " + sensorRecord.getUnfiltered()); if (BgReading.is_new(sensorRecord, addativeOffset)) { BgReading bgReading = new BgReading(); Sensor sensor = Sensor.currentSensor(); Calibration calibration = Calibration.getForTimestamp(sensorRecord.getSystemTime().getTime() + addativeOffset); if (sensor != null && calibration != null) { bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.calibration = calibration; bgReading.calibration_uuid = calibration.uuid; bgReading.raw_data = (sensorRecord.getUnfiltered() / 1000); bgReading.filtered_data = (sensorRecord.getFiltered() / 1000); bgReading.timestamp = sensorRecord.getSystemTime().getTime() + addativeOffset; if (bgReading.timestamp > new Date().getTime()) { return; } bgReading.uuid = UUID.randomUUID().toString(); bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at; bgReading.calculateAgeAdjustedRawValue(); bgReading.save(); } } }
public static void create(SensorRecord sensorRecord, long addativeOffset, Context context) { Log.i(TAG, "create: gonna make some sensor records: " + sensorRecord.getUnfiltered()); if (BgReading.is_new(sensorRecord, addativeOffset)) { BgReading bgReading = new BgReading(); Sensor sensor = Sensor.currentSensor(); Calibration calibration = Calibration.getForTimestamp(sensorRecord.getSystemTime().getTime() + addativeOffset); if (sensor != null && calibration != null) { bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.calibration = calibration; bgReading.calibration_uuid = calibration.uuid; bgReading.raw_data = (sensorRecord.getUnfiltered() / 1000); bgReading.filtered_data = (sensorRecord.getFiltered() / 1000); bgReading.timestamp = sensorRecord.getSystemTime().getTime() + addativeOffset; if (bgReading.timestamp > new Date().getTime()) { return; } bgReading.uuid = UUID.randomUUID().toString(); bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at; bgReading.calculateAgeAdjustedRawValue(); bgReading.save(); } } }
final BgReading bgr = new BgReading(); bgr.sensor = sensor; bgr.sensor_uuid = sensor.uuid;
private static void processFromMessage(BgReadingMessage btm) { if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) { BgReading bg = byUUID(btm.uuid); if (bg != null) { // we already have this uuid and we don't have a circumstance to update the record, so quick return here return; } if (bg == null) { bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false); if (bg != null) { UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!"); return; } bg = new BgReading(); } bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP); bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE); bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE); bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG); bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED); bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA); bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE); bg.calibration_uuid = btm.calibration_uuid; bg.uuid = btm.uuid; bg.save(); } else { UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid"); } }
private static void processFromMessage(BgReadingMessage btm) { if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) { BgReading bg = byUUID(btm.uuid); if (bg != null) { // we already have this uuid and we don't have a circumstance to update the record, so quick return here return; } if (bg == null) { bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false); if (bg != null) { UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!"); return; } bg = new BgReading(); } bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP); bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE); bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE); bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG); bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED); bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA); bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE); bg.calibration_uuid = btm.calibration_uuid; bg.uuid = btm.uuid; bg.save(); } else { UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid"); } }
private static void processFromMessage(BgReadingMessage btm) { if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) { BgReading bg = byUUID(btm.uuid); if (bg != null) { // we already have this uuid and we don't have a circumstance to update the record, so quick return here return; } if (bg == null) { bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false); if (bg != null) { UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!"); return; } bg = new BgReading(); } bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP); bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE); bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE); bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG); bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED); bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA); bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE); bg.calibration_uuid = btm.calibration_uuid; bg.uuid = btm.uuid; bg.save(); } else { UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid"); } }
@Test public void interpolateCalculatedValueTest() { final long startTime = 1531124821000L; final long endTime = startTime + (Constants.MINUTE_IN_MS * 10); final BgReading first = new BgReading(); final BgReading second = new BgReading(); first.timestamp = startTime; first.calculated_value = 100; second.timestamp = endTime; second.calculated_value = 200; assertWithMessage("time at first matches first").that(interpolateCalculatedValue(first,second, startTime)).isEqualTo(100.0); assertWithMessage("time at second matches second").that(interpolateCalculatedValue(first,second, endTime)).isEqualTo(200.0); assertWithMessage("time point 1 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 150))).isEqualTo(125.0); assertWithMessage("time point 2 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 300))).isEqualTo(150.0); assertWithMessage("time point 3 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 400))).isWithin(0.1).of(166.6); } }
@Test public void interpolateCalculatedValueTest() { final long startTime = 1531124821000L; final long endTime = startTime + (Constants.MINUTE_IN_MS * 10); final BgReading first = new BgReading(); final BgReading second = new BgReading(); first.timestamp = startTime; first.calculated_value = 100; second.timestamp = endTime; second.calculated_value = 200; assertWithMessage("time at first matches first").that(interpolateCalculatedValue(first,second, startTime)).isEqualTo(100.0); assertWithMessage("time at second matches second").that(interpolateCalculatedValue(first,second, endTime)).isEqualTo(200.0); assertWithMessage("time point 1 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 150))).isEqualTo(125.0); assertWithMessage("time point 2 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 300))).isEqualTo(150.0); assertWithMessage("time point 3 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 400))).isWithin(0.1).of(166.6); } }