use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class BgReading method is_new.
public static boolean is_new(SensorRecord sensorRecord, long addativeOffset) {
double timestamp = sensorRecord.getSystemTime().getTime() + addativeOffset;
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
BgReading bgReading = new Select().from(BgReading.class).where("Sensor = ? ", sensor.getId()).where("timestamp <= ?", // 1 minute padding (should never be that far off, but why not)
(timestamp + (60 * 1000))).orderBy("timestamp desc").executeSingle();
if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < (3 * 60 * 1000)) {
// cool, so was it actually within 4 minutes of that bg reading?
Log.i(TAG, "isNew; Old Reading");
return false;
}
}
Log.i(TAG, "isNew: New Reading");
return true;
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class BgReading method getForTimestamp.
public static BgReading getForTimestamp(double timestamp) {
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
BgReading bgReading = new Select().from(BgReading.class).where("Sensor = ? ", sensor.getId()).where("timestamp <= ?", // 1 minute padding (should never be that far off, but why not)
(timestamp + (60 * 1000))).where("calculated_value = 0").where("raw_calculated = 0").orderBy("timestamp desc").executeSingle();
if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < (3 * 60 * 1000)) {
// cool, so was it actually within 4 minutes of that bg reading?
Log.i(TAG, "getForTimestamp: Found a BG timestamp match");
return bgReading;
}
}
Log.d(TAG, "getForTimestamp: No luck finding a BG timestamp match");
return null;
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class AlertType method toSettings.
// Convert all settings to a string and save it in the references. This is needed to allow it's backup.
public static boolean toSettings(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
List<AlertType> alerts = new Select().from(AlertType.class).execute();
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
String output = gson.toJson(alerts);
Log.e(TAG, "Created the string " + output);
prefs.edit().putString("saved_alerts", output).commit();
return true;
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class ShareTest method attemptConnection.
public void attemptConnection() {
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (device != null) {
details.append("\nConnection state: " + " Device is not null");
mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
}
Log.i(TAG, "Connection state: " + mConnectionState);
details.append("\nConnection state: " + mConnectionState);
if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
if (btDevice != null) {
details.append("\nBT Device: " + btDevice.name);
mDeviceName = btDevice.name;
mDeviceAddress = btDevice.address;
mBluetoothAdapter = mBluetoothManager.getAdapter();
boolean newConnection = true;
if (newConnection) {
is_connected = connect(mDeviceAddress);
details.append("\nConnecting...: ");
}
}
}
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class UploaderQueue method getLegacyCount.
private static int getLegacyCount(Class which, Boolean rest, Boolean mongo, Boolean and) {
try {
String where = "";
if (rest != null)
where += " success = " + (rest ? "1 " : "0 ");
if (and != null)
where += (and ? " and " : " or ");
if (mongo != null)
where += " mongo_success = " + (mongo ? "1 " : "0 ");
final String query = new Select("COUNT(*) as total").from(which).toSql();
final Cursor resultCursor = Cache.openDatabase().rawQuery(query + ((where.length() > 0) ? " where " + where : ""), null);
if (resultCursor.moveToNext()) {
final int total = resultCursor.getInt(0);
resultCursor.close();
return total;
} else {
return 0;
}
} catch (Exception e) {
Log.d(TAG, "Got exception getting count: " + e);
return -1;
}
}
Aggregations