use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class UploaderQueue method getClasses.
private static List<String> getClasses() {
fixUpTable();
final ArrayList<String> results = new ArrayList<>();
final String query = new Select("distinct otype as otypes").from(UploaderQueue.class).toSql();
final Cursor resultCursor = Cache.openDatabase().rawQuery(query, null);
while (resultCursor.moveToNext()) {
results.add(resultCursor.getString(0));
}
resultCursor.close();
return results;
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class BgReading method readingNearTimeStamp.
public static BgReading readingNearTimeStamp(double startTime) {
final double margin = (4 * 60 * 1000);
final DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(1);
return new Select().from(BgReading.class).where("timestamp >= " + df.format(startTime - margin)).where("timestamp <= " + df.format(startTime + margin)).where("calculated_value != 0").where("raw_data != 0").executeSingle();
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class ListenerService method syncActiveBtDeviceData.
private void syncActiveBtDeviceData(DataMap dataMap, Context context) {
// KS
Log.d(TAG, "syncActiveBtDeviceData");
if (dataMap != null) {
String name = dataMap.getString("name", "");
String address = dataMap.getString("address", "");
Boolean connected = dataMap.getBoolean("connected", false);
Log.d(TAG, "syncActiveBtDeviceData add ActiveBluetoothDevice for name=" + name + " address=" + address + " connected=" + connected);
// ensure database has already been initialized
Sensor.InitDb(context);
if (name != null && !name.isEmpty() && address != null && !address.isEmpty()) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
synchronized (ActiveBluetoothDevice.table_lock) {
ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
prefs.edit().putString("last_connected_device_address", address).apply();
if (btDevice == null) {
ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
newBtDevice.name = name;
newBtDevice.address = address;
newBtDevice.connected = connected;
newBtDevice.save();
} else {
btDevice.name = name;
btDevice.address = address;
btDevice.connected = connected;
btDevice.save();
}
}
}
}
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class SlopeParameters method min_recent.
public static double min_recent() {
Sensor sensor = Sensor.currentSensor();
Calibration calibration = new Select().from(Calibration.class).where("Sensor = ? ", sensor.getId()).where("slope_confidence != 0").where("sensor_confidence != 0").where("timestamp > ?", (new Date().getTime() - (60000 * 60 * 24 * 4))).orderBy("bg asc").executeSingle();
if (calibration != null) {
return calibration.bg;
} else {
return 100;
}
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class SlopeParameters method is_new.
public static boolean is_new(CalSubrecord calSubrecord, long addativeOffset) {
Sensor sensor = Sensor.currentSensor();
Calibration calibration = new Select().from(Calibration.class).where("Sensor = ? ", sensor.getId()).where("timestamp <= ?", calSubrecord.getDateEntered().getTime() + addativeOffset + (1000 * 60 * 2)).orderBy("timestamp desc").executeSingle();
if (calibration != null && Math.abs(calibration.timestamp - (calSubrecord.getDateEntered().getTime() + addativeOffset)) < (4 * 60 * 1000)) {
Log.d("CAL CHECK IN ", "Already have that calibration!");
return false;
} else {
Log.d("CAL CHECK IN ", "Looks like a new calibration!");
return true;
}
}
Aggregations