Search in sources :

Example 76 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

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

Example 77 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class BgReading method getForTimestampExists.

// used in wear
public static BgReading getForTimestampExists(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))).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;
}
Also used : Select(com.activeandroid.query.Select)

Example 78 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

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

Example 79 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

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

Example 80 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class Treatments method latestForGraph.

public static List<Treatments> latestForGraph(int number, double startTime, double endTime) {
    fixUpTable();
    DecimalFormat df = new DecimalFormat("#");
    // are there decimal points in the database??
    df.setMaximumFractionDigits(1);
    return new Select().from(Treatments.class).where("timestamp >= ? and timestamp <= ?", df.format(startTime), df.format(endTime)).orderBy("timestamp desc").limit(number).execute();
}
Also used : DecimalFormat(java.text.DecimalFormat) 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