public static List<Accuracy> latestForGraph(int number, long startTime, long endTime) { try { return new Select() .from(Accuracy.class) .where("timestamp >= " + Math.max(startTime, 0)) .where("timestamp <= " + endTime) .orderBy("timestamp desc, _id asc") .limit(number) .execute(); } catch (android.database.sqlite.SQLiteException e) { patched = fixUpTable(schema, patched); return new ArrayList<>(); } }
public static List<Accuracy> latestForGraph(int number, long startTime, long endTime) { try { return new Select() .from(Accuracy.class) .where("timestamp >= " + Math.max(startTime, 0)) .where("timestamp <= " + endTime) .orderBy("timestamp desc, _id asc") .limit(number) .execute(); } catch (android.database.sqlite.SQLiteException e) { patched = fixUpTable(schema, patched); return new ArrayList<>(); } }
static Accuracy getForPreciseTimestamp(double timestamp, double precision, String plugin) { patched = fixUpTable(schema, patched); final Accuracy accuracy = new Select() .from(Accuracy.class) .where("timestamp <= ?", (timestamp + precision)) .where("timestamp >= ?", (timestamp - precision)) .where("plugin = ?", plugin) .orderBy("abs(timestamp - " + timestamp + ") asc") .executeSingle(); if (accuracy != null && Math.abs(accuracy.timestamp - timestamp) < precision) { return accuracy; } return null; }
static Accuracy getForPreciseTimestamp(double timestamp, double precision, String plugin) { patched = fixUpTable(schema, patched); final Accuracy accuracy = new Select() .from(Accuracy.class) .where("timestamp <= ?", (timestamp + precision)) .where("timestamp >= ?", (timestamp - precision)) .where("plugin = ?", plugin) .orderBy("abs(timestamp - " + timestamp + ") asc") .executeSingle(); if (accuracy != null && Math.abs(accuracy.timestamp - timestamp) < precision) { return accuracy; } return null; }
public static Accuracy create(BloodTest bloodTest, BgReading bgReading, String plugin) { if ((bloodTest == null) || (bgReading == null)) return null; patched = fixUpTable(schema, patched); if (getForPreciseTimestamp(bgReading.timestamp, Constants.MINUTE_IN_MS, plugin) != null) { UserError.Log.d(TAG, "Duplicate accuracy timestamp for: " + JoH.dateTimeText(bgReading.timestamp)); return null; } final Accuracy ac = new Accuracy(); ac.timestamp = bgReading.timestamp; ac.bg = bloodTest.mgdl; ac.bgtimestamp = bloodTest.timestamp; ac.bgsource = bloodTest.source; ac.plugin = plugin; ac.calculated = bgReading.calculated_value; //ac.lag = bgReading.timestamp-bloodTest.timestamp; ac.difference = bgReading.calculated_value - bloodTest.mgdl; ac.save(); return ac; }
public static Accuracy create(BloodTest bloodTest, BgReading bgReading, String plugin) { if ((bloodTest == null) || (bgReading == null)) return null; patched = fixUpTable(schema, patched); if (getForPreciseTimestamp(bgReading.timestamp, Constants.MINUTE_IN_MS, plugin) != null) { UserError.Log.d(TAG, "Duplicate accuracy timestamp for: " + JoH.dateTimeText(bgReading.timestamp)); return null; } final Accuracy ac = new Accuracy(); ac.timestamp = bgReading.timestamp; ac.bg = bloodTest.mgdl; ac.bgtimestamp = bloodTest.timestamp; ac.bgsource = bloodTest.source; ac.plugin = plugin; ac.calculated = bgReading.calculated_value; //ac.lag = bgReading.timestamp-bloodTest.timestamp; ac.difference = bgReading.calculated_value - bloodTest.mgdl; ac.save(); return ac; }