Search in sources :

Example 36 with Select

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;
}
Also used : ArrayList(java.util.ArrayList) Select(com.activeandroid.query.Select) Cursor(android.database.Cursor)

Example 37 with Select

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();
}
Also used : DecimalFormat(java.text.DecimalFormat) Select(com.activeandroid.query.Select)

Example 38 with Select

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();
                }
            }
        }
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) SharedPreferences(android.content.SharedPreferences) Select(com.activeandroid.query.Select)

Example 39 with Select

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;
    }
}
Also used : Select(com.activeandroid.query.Select) Date(java.util.Date)

Example 40 with Select

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;
    }
}
Also used : Select(com.activeandroid.query.Select)

Aggregations

Select (com.activeandroid.query.Select)80 SharedPreferences (android.content.SharedPreferences)14 From (com.activeandroid.query.From)11 MockModel (com.activeandroid.test.MockModel)11 DecimalFormat (java.text.DecimalFormat)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cursor (android.database.Cursor)6 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)6 JSONException (org.json.JSONException)5 GsonBuilder (com.google.gson.GsonBuilder)4 PendingIntent (android.app.PendingIntent)2 BluetoothDevice (android.bluetooth.BluetoothDevice)2 Intent (android.content.Intent)2 Update (com.activeandroid.query.Update)2 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)2 MissedReadingService (com.eveningoutpost.dexdrip.Services.MissedReadingService)2 Gson (com.google.gson.Gson)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2