Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.Constants#MMOLL_TO_MGDL

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Constants#MMOLL_TO_MGDL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBSearchUtil.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static int noReadingsBelowRange(Context context) {
    Bounds bounds = new Bounds().invoke();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        low *= Constants.MMOLL_TO_MGDL;

    }
    int count = new Select()
            .from(BgReading.class)
            .where("timestamp >= " + bounds.start)
            .where("timestamp <= " + bounds.stop)
            .where("calculated_value > " + CUTOFF)
            .where("calculated_value < " + low)
            .where("snyced == 0")
            .count();
    Log.d("DrawStats", "Low count: " + count);

    return count;
}
 
Example 2
Source File: DBSearchUtil.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static int noReadingsInRange(Context context) {
    Bounds bounds = new Bounds().invoke();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double high = Double.parseDouble(settings.getString("highValue", "170"));
    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
        low *= Constants.MMOLL_TO_MGDL;

    }
    int count = new Select()
            .from(BgReading.class)
            .where("timestamp >= " + bounds.start)
            .where("timestamp <= " + bounds.stop)
            .where("calculated_value > " + CUTOFF)
            .where("calculated_value <= " + high)
            .where("calculated_value >= " + low)
            .where("snyced == 0")
            .count();
    Log.d("DrawStats", "In count: " + count);

    return count;
}
 
Example 3
Source File: GcmActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
static void pushCalibration2(double bgValue, String uuid, long offset) {
    Log.i(TAG, "pushCalibration2 called: " + JoH.qs(bgValue, 1) + " " + uuid + " " + offset);
    if (Home.get_master_or_follower()) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
        final String unit = prefs.getString("units", "mgdl");

        if (unit.compareTo("mgdl") != 0) {
            bgValue = bgValue * Constants.MMOLL_TO_MGDL;
        }

        if ((bgValue < 40) || (bgValue > 400)) {
            Log.wtf(TAG, "Invalid out of range calibration glucose mg/dl value of: " + bgValue);
            JoH.static_toast_long("Calibration out of range: " + bgValue + " mg/dl");
            return;
        }
        final String json = newCalibrationToJson(bgValue, uuid, offset);
        GcmActivity.sendMessage(myIdentity(), "cal2", json);
    }
}
 
Example 4
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static BloodTest createFromCal(double bg, double timeoffset, String source, String suggested_uuid) {
    UserError.Log.d(TAG, "createFromCal call create");
    final String unit = Pref.getString("units", "mgdl");

    if (unit.compareTo("mgdl") != 0) {
        bg = bg * Constants.MMOLL_TO_MGDL;
    }

    if ((bg < 40) || (bg > 400)) {
        Log.wtf(TAG, "Invalid out of range bloodtest glucose mg/dl value of: " + bg);
        JoH.static_toast_long("Bloodtest out of range: " + bg + " mg/dl");
        return null;
    }

    return create((long) (new Date().getTime() - timeoffset), bg, source, suggested_uuid);
}
 
Example 5
Source File: DBSearchUtil.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public static int noReadingsBelowRange(Context context) {
    Bounds bounds = new Bounds().invoke();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        low *= Constants.MMOLL_TO_MGDL;

    }
    int count = new Select()
            .from(BgReading.class)
            .where("timestamp >= " + bounds.start)
            .where("timestamp <= " + bounds.stop)
            .where("calculated_value > " + CUTOFF)
            .where("calculated_value < " + low)
            .where("snyced == 0")
            .count();
    Log.d("DrawStats", "Low count: " + count);

    return count;
}
 
Example 6
Source File: DBSearchUtil.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public static int noReadingsInRange(Context context) {
    Bounds bounds = new Bounds().invoke();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double high = Double.parseDouble(settings.getString("highValue", "170"));
    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
        low *= Constants.MMOLL_TO_MGDL;

    }
    int count = new Select()
            .from(BgReading.class)
            .where("timestamp >= " + bounds.start)
            .where("timestamp <= " + bounds.stop)
            .where("calculated_value > " + CUTOFF)
            .where("calculated_value <= " + high)
            .where("calculated_value >= " + low)
            .where("snyced == 0")
            .count();
    Log.d("DrawStats", "In count: " + count);

    return count;
}
 
Example 7
Source File: PercentileView.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void drawHighLow(Canvas canvas) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));
    double high = Double.parseDouble(settings.getString("highValue", "170"));
    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
        low *= Constants.MMOLL_TO_MGDL;

    }

    int highPosition = getYfromBG(high, canvas);
    int lowPosition = getYfromBG(low, canvas);
    Paint myPaint = new Paint();
    myPaint.setStyle(Paint.Style.STROKE);
    myPaint.setAntiAlias(false);
    myPaint.setColor(Color.RED);
    myPaint.setStrokeWidth(dp2px(3));
    canvas.drawLine(dpOffset, lowPosition, canvas.getWidth(), lowPosition, myPaint);
    myPaint.setColor(Color.YELLOW);
    canvas.drawLine(dpOffset, highPosition, canvas.getWidth(), highPosition, myPaint);
}
 
Example 8
Source File: PercentileView.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void drawHighLow(Canvas canvas) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));
    double high = Double.parseDouble(settings.getString("highValue", "170"));
    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
        low *= Constants.MMOLL_TO_MGDL;

    }

    int highPosition = getYfromBG(high, canvas);
    int lowPosition = getYfromBG(low, canvas);
    Paint myPaint = new Paint();
    myPaint.setStyle(Paint.Style.STROKE);
    myPaint.setAntiAlias(false);
    myPaint.setColor(Color.RED);
    myPaint.setStrokeWidth(dp2px(3));
    canvas.drawLine(dpOffset, lowPosition, canvas.getWidth(), lowPosition, myPaint);
    myPaint.setColor(Color.YELLOW);
    canvas.drawLine(dpOffset, highPosition, canvas.getWidth(), highPosition, myPaint);
}
 
Example 9
Source File: GcmActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static void pushCalibration2(double bgValue, String uuid, long offset) {
    Log.i(TAG, "pushCalibration2 called: " + JoH.qs(bgValue, 1) + " " + uuid + " " + offset);
    if (Home.get_master_or_follower()) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
        final String unit = prefs.getString("units", "mgdl");

        if (unit.compareTo("mgdl") != 0) {
            bgValue = bgValue * Constants.MMOLL_TO_MGDL;
        }

        if ((bgValue < 40) || (bgValue > 400)) {
            Log.wtf(TAG, "Invalid out of range calibration glucose mg/dl value of: " + bgValue);
            JoH.static_toast_long("Calibration out of range: " + bgValue + " mg/dl");
            return;
        }
        final String json = newCalibrationToJson(bgValue, uuid, offset);
        GcmActivity.sendMessage(myIdentity(), "cal2", json);
    }
}
 
Example 10
Source File: EditAlertActivity.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
double unitsConvertFromDisp(double threshold) {
    if(doMgdl ) {
        return threshold;
    } else {
        return threshold * Constants.MMOLL_TO_MGDL;
    }
}
 
Example 11
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private double inMgdl(double value, SharedPreferences sPrefs) {
    if (!doMgdl(sPrefs)) {
        return value * Constants.MMOLL_TO_MGDL;
    } else {
        return value;
    }

}
 
Example 12
Source File: BloodTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static BloodTest createFromCal(double bg, double timeoffset, String source, String suggested_uuid) {
    final String unit = Pref.getString("units", "mgdl");

    if (unit.compareTo("mgdl") != 0) {
        bg = bg * Constants.MMOLL_TO_MGDL;
    }

    if ((bg < 40) || (bg > 400)) {
        Log.wtf(TAG, "Invalid out of range bloodtest glucose mg/dl value of: " + bg);
        JoH.static_toast_long("Bloodtest out of range: " + bg + " mg/dl");
        return null;
    }

    return create((long) (new Date().getTime() - timeoffset), bg, source, suggested_uuid);
}
 
Example 13
Source File: EditAlertActivity.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
double unitsConvertFromDisp(double threshold) {
    if(doMgdl ) {
        return threshold;
    } else {
        return threshold * Constants.MMOLL_TO_MGDL;
    }
}
 
Example 14
Source File: EditAlertActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
double unitsConvertFromDisp(double threshold) {
    if(doMgdl ) {
        return threshold;
    } else {
        return threshold * Constants.MMOLL_TO_MGDL;
    }
}
 
Example 15
Source File: Calibration.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static Double getConvertedBg(double bg) {
    final String unit = Pref.getString("units", "mgdl");
    if (unit.compareTo("mgdl") != 0) {
        bg = bg * Constants.MMOLL_TO_MGDL;
    }
    if ((bg < 40) || (bg > 400)) {
        return null;
    }
    return bg;
}
 
Example 16
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private double inMgdl(double value, SharedPreferences sPrefs) {
    if (!doMgdl(sPrefs)) {
        return value * Constants.MMOLL_TO_MGDL;
    } else {
        return value;
    }

}
 
Example 17
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private double bgScale() {
    //this.doMgdl = (prefs.getString("units", "mgdl").equals("mgdl"));
    if (doMgdl)
        return Constants.MMOLL_TO_MGDL;
    else
        return 1;
}
 
Example 18
Source File: Calibration.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static Calibration create(double bg, Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String unit = prefs.getString("units", "mgdl");

    if(unit.compareTo("mgdl") != 0 ) {
        bg = bg * Constants.MMOLL_TO_MGDL;
    }

    CalibrationRequest.clearAll();
    Calibration calibration = new Calibration();
    Sensor sensor = Sensor.currentSensor();

    if (sensor != null) {
        BgReading bgReading = BgReading.last();
        if (bgReading != null) {
            calibration.sensor = sensor;
            calibration.bg = bg;
            calibration.check_in = false;
            calibration.timestamp = new Date().getTime();
            calibration.raw_value = bgReading.raw_data;
            calibration.adjusted_raw_value = bgReading.age_adjusted_raw_value;
            calibration.sensor_uuid = sensor.uuid;
            calibration.slope_confidence = Math.min(Math.max(((4 - Math.abs((bgReading.calculated_value_slope) * 60000))/4), 0), 1);

            double estimated_raw_bg = BgReading.estimated_raw_bg(new Date().getTime());
            calibration.raw_timestamp = bgReading.timestamp;
            if (Math.abs(estimated_raw_bg - bgReading.age_adjusted_raw_value) > 20) {
                calibration.estimate_raw_at_time_of_calibration = bgReading.age_adjusted_raw_value;
            } else {
                calibration.estimate_raw_at_time_of_calibration = estimated_raw_bg;
            }
            calibration.distance_from_estimate = Math.abs(calibration.bg - bgReading.calculated_value);
            calibration.sensor_confidence = Math.max(((-0.0018 * bg * bg) + (0.6657 * bg) + 36.7505) / 100, 0);
            calibration.sensor_age_at_time_of_estimation = calibration.timestamp - sensor.started_at;
            calibration.uuid = UUID.randomUUID().toString();
            calibration.save();

            bgReading.calibration = calibration;
            bgReading.calibration_flag = true;
            bgReading.save();
            BgSendQueue.addToQueue(bgReading, "update", context);

            calculate_w_l_s();
            adjustRecentBgReadings();
            CalibrationSendQueue.addToQueue(calibration, context);
            Notifications.notificationSetter(context);
            Calibration.requestCalibrationIfRangeTooNarrow();
        }
    } else {
        Log.w("CALIBRATION", "No sensor, cant save!");
    }
    return Calibration.last();
}
 
Example 19
Source File: StatsResult.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public StatsResult(SharedPreferences settings, long from, long to){
    this.from = from;
    this.to = to;

    mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double high = Double.parseDouble(settings.getString("highValue", "170"));
    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
        low *= Constants.MMOLL_TO_MGDL;
    }
    SQLiteDatabase db = Cache.openDatabase();

    Cursor cursor= db.rawQuery("select count(*) from bgreadings  where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value >= " + low + " AND calculated_value <= " + high + " AND snyced == 0", null);
    cursor.moveToFirst();
    in = cursor.getInt(0);
    cursor.close();

    cursor= db.rawQuery("select count(*) from bgreadings  where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + CUTOFF + " AND calculated_value < " + low + " AND snyced == 0", null);
    cursor.moveToFirst();
    below = cursor.getInt(0);
    cursor.close();

    cursor= db.rawQuery("select count(*) from bgreadings  where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + high + " AND snyced == 0", null);
    cursor.moveToFirst();
    above = cursor.getInt(0);
    cursor.close();

    if(getTotalReadings() > 0){
        cursor= db.rawQuery("select avg(calculated_value) from bgreadings  where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + CUTOFF + " AND snyced == 0", null);
        cursor.moveToFirst();
        avg = cursor.getDouble(0);
        cursor.close();
    } else {
        avg = 0;
    }

    possibleCaptures = (to - from) / (5*60*1000);
    //while already in the next 5 minutes, a package could already have arrived.
    if ((to - from) % (5*60*1000) != 0) possibleCaptures += 1;

}
 
Example 20
Source File: Calibration.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static Calibration create(double bg, long timeoffset, Context context, boolean note_only, long estimatedInterstitialLagSeconds) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final String unit = prefs.getString("units", "mgdl");
    final boolean adjustPast = prefs.getBoolean("rewrite_history", true);

    if (unit.compareTo("mgdl") != 0) {
        bg = bg * Constants.MMOLL_TO_MGDL;
    }

    if ((bg < 40) || (bg > 400)) {
        Log.wtf(TAG, "Invalid out of range calibration glucose mg/dl value of: " + bg);
        JoH.static_toast_long("Calibration out of range: " + bg + " mg/dl");
        return null;
    }

    if (!note_only) CalibrationRequest.clearAll();
    final Calibration calibration = new Calibration();
    Sensor sensor = Sensor.currentSensor();

    boolean is_follower = prefs.getString("dex_collection_method", "").equals("Follower");
    if ((sensor == null)
            && (is_follower)) {
        Sensor.create(Math.round(JoH.ts())); // no sensor? no problem, create virtual one for follower
        sensor = Sensor.currentSensor();
    }

    if (sensor != null) {
        BgReading bgReading = null;
        if (timeoffset == 0) {
            bgReading = BgReading.last(is_follower);
        } else {
            // get closest bg reading we can find with a cut off at 15 minutes max time
            bgReading = BgReading.getForPreciseTimestamp(new Date().getTime() - ((timeoffset - estimatedInterstitialLagSeconds) * 1000 ), (15 * 60 * 1000));
        }
        if (bgReading != null) {
            calibration.sensor = sensor;
            calibration.bg = bg;
            calibration.check_in = false;
            calibration.timestamp = new Date().getTime() - (timeoffset * 1000); //  potential historical bg readings
            calibration.raw_value = bgReading.raw_data;
            calibration.adjusted_raw_value = bgReading.age_adjusted_raw_value;
            calibration.sensor_uuid = sensor.uuid;
            calibration.slope_confidence = Math.min(Math.max(((4 - Math.abs((bgReading.calculated_value_slope) * 60000)) / 4), 0), 1);

            double estimated_raw_bg = BgReading.estimated_raw_bg(new Date().getTime());
            calibration.raw_timestamp = bgReading.timestamp;
            if (Math.abs(estimated_raw_bg - bgReading.age_adjusted_raw_value) > 20) {
                calibration.estimate_raw_at_time_of_calibration = bgReading.age_adjusted_raw_value;
            } else {
                calibration.estimate_raw_at_time_of_calibration = estimated_raw_bg;
            }
            calibration.distance_from_estimate = Math.abs(calibration.bg - bgReading.calculated_value);
            if (!note_only) {
                calibration.sensor_confidence = Math.max(((-0.0018 * bg * bg) + (0.6657 * bg) + 36.7505) / 100, 0);
            } else {
                calibration.sensor_confidence = 0; // exclude from calibrations but show on graph
                calibration.slope = 0;
                calibration.intercept = 0;
            }
            calibration.sensor_age_at_time_of_estimation = calibration.timestamp - sensor.started_at;
            calibration.uuid = UUID.randomUUID().toString();
            calibration.save();

            if (!note_only) {
                bgReading.calibration = calibration;
                bgReading.calibration_flag = true;
                bgReading.save();
            }

            if ((!is_follower) && (!note_only)) {
                BgSendQueue.handleNewBgReading(bgReading, "update", context);
                // TODO probably should add a more fine grained prefs option in future
                calculate_w_l_s(prefs.getBoolean("infrequent_calibration", false));
                adjustRecentBgReadings(adjustPast ? 30 : 2);
                CalibrationSendQueue.addToQueue(calibration, context);
                context.startService(new Intent(context, Notifications.class));
                Calibration.requestCalibrationIfRangeTooNarrow();
                //KS newFingerStickData();
            } else {
                Log.d(TAG, "Follower mode or note so not processing calibration deeply");
            }
        } else {
            // we couldn't get a reading close enough to the calibration timestamp
            if (!is_follower) {
                JoH.static_toast(context, "No close enough reading for Calib (15 min)", Toast.LENGTH_LONG);
            }
        }
    } else {
        Log.d("CALIBRATION", "No sensor, cant save!");
    }
    return Calibration.last();
}