use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class UserError method deletable.
public static List<UserError> deletable() {
List<UserError> userErrors = new Select().from(UserError.class).where("severity < ?", 3).where("timestamp < ?", (new Date().getTime() - 1000 * 60 * 60 * 24)).orderBy("timestamp desc").execute();
List<UserError> highErrors = new Select().from(UserError.class).where("severity = ?", 3).where("timestamp < ?", (new Date().getTime() - 1000 * 60 * 60 * 24 * 3)).orderBy("timestamp desc").execute();
List<UserError> events = new Select().from(UserError.class).where("severity > ?", 3).where("timestamp < ?", (new Date().getTime() - 1000 * 60 * 60 * 24 * 7)).orderBy("timestamp desc").execute();
userErrors.addAll(highErrors);
userErrors.addAll(events);
return userErrors;
}
use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class LibreBlock method getForTrend.
public static List<LibreBlock> getForTrend(long start_time, long end_time) {
List<LibreBlock> res1 = new Select().from(LibreBlock.class).where("timestamp >= ?", start_time).where("timestamp <= ?", end_time).orderBy("timestamp asc").execute();
// One can think that we could do this filtering as part of the SQL. practically speaking
// the wrong key was used for the query, and it takes 2-3 minutes.
List<LibreBlock> res = new ArrayList<LibreBlock>();
for (LibreBlock lb : res1) {
if (lb.byte_start == 0 && (lb.byte_end == Constants.LIBRE_1_2_FRAM_SIZE || lb.byte_end == 44)) {
res.add(lb);
}
}
return res;
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class BluetoothScan method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.d(TAG, "Item Clicked");
final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
if (device == null || device.getName() == null)
return;
Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show();
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", device.getAddress()).apply();
Blukon.clearPin();
if (btDevice == null) {
ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
newBtDevice.name = device.getName();
newBtDevice.address = device.getAddress();
newBtDevice.save();
} else {
btDevice.name = device.getName();
btDevice.address = device.getAddress();
btDevice.save();
}
startWatchUpdaterService(this, WatchUpdaterService.ACTION_SYNC_ACTIVEBTDEVICE, TAG);
}
// automatically set or unset the option for "Transmiter" device
boolean using_transmiter = false;
// Experimental support for rfduino from Tomasz Stachowicz
// automatically set or unset the option for "RFDuino" device
boolean using_rfduino = false;
try {
if (device.getName().toLowerCase().contains("limitter") && (adverts.containsKey(device.getAddress()) && ((new String(adverts.get(device.getAddress()), "UTF-8").contains("eLeR")) || (new String(adverts.get(device.getAddress()), "UTF-8").contains("data")))) || device.getName().toLowerCase().contains("limitterd")) {
String msg = "Auto-detected transmiter_pl device!";
Log.e(TAG, msg);
JoH.static_toast_long(msg);
using_transmiter = true;
}
prefs.edit().putBoolean("use_transmiter_pl_bluetooth", using_transmiter).apply();
// Experimental support for rfduino from Tomasz Stachowicz
if (device.getName().toLowerCase().contains("xbridge") && (adverts.containsKey(device.getAddress()) && (new String(adverts.get(device.getAddress()), "UTF-8").contains("rfduino")))) {
String msg = "Auto-detected rfduino device!";
Log.e(TAG, msg);
JoH.static_toast_long(msg);
using_rfduino = true;
}
prefs.edit().putBoolean("use_rfduino_bluetooth", using_rfduino).apply();
if (device.getName().toLowerCase().contains("dexcom")) {
if (!CollectionServiceStarter.isBTShare(getApplicationContext())) {
prefs.edit().putString("dex_collection_method", "DexcomShare").apply();
prefs.edit().putBoolean("calibration_notifications", false).apply();
}
if (prefs.getString("share_key", "SM00000000").compareTo("SM00000000") == 0 || prefs.getString("share_key", "SM00000000").length() < 10) {
requestSerialNumber(prefs);
} else
returnToHome();
} else if (device.getName().toLowerCase().contains("bridge")) {
if (!CollectionServiceStarter.isDexBridgeOrWifiandDexBridge())
prefs.edit().putString("dex_collection_method", "DexbridgeWixel").apply();
if (prefs.getString("dex_txid", "00000").compareTo("00000") == 0 || prefs.getString("dex_txid", "00000").length() < 5) {
requestTransmitterId(prefs);
} else
returnToHome();
} else if (device.getName().toLowerCase().contains("drip")) {
if (!(CollectionServiceStarter.isBTWixelOrLimiTTer(getApplicationContext()) || CollectionServiceStarter.isWifiandBTWixel(getApplicationContext())) || CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply();
}
returnToHome();
} else if (device.getName().toLowerCase().contains("limitter")) {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if (device.getName().toLowerCase().contains("bluereader")) {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if ((device.getName().toLowerCase().contains("miaomiao")) || (device.getName().toLowerCase().startsWith("watlaa"))) {
if (!(CollectionServiceStarter.isLimitter() || CollectionServiceStarter.isWifiandBTLibre())) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if (device.getName().toLowerCase().contains("sweetreader")) {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if (device.getName().matches("^BLU[0-9][0-9][0-9][0-9][0-9].*$")) {
Blukon.doPinDialog(this, new Runnable() {
@Override
public void run() {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
}
});
} else if (device.getName().matches("MT")) {
if (Medtrum.saveSerialFromLegacy(adverts.get(device.getAddress()))) {
JoH.static_toast_long("Set Medtrum serial number");
CollectionServiceStarter.restartCollectionServiceBackground();
returnToHome();
} else {
JoH.static_toast_long("Failed to find Medtrum serial number");
}
} else {
returnToHome();
}
} catch (UnsupportedEncodingException | NullPointerException e) {
Log.d(TAG, "Got exception in listitemclick: " + Arrays.toString(e.getStackTrace()));
}
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
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;
}
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
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();
}
Aggregations