Java Code Examples for com.eveningoutpost.dexdrip.Models.Calibration#allForSensorLimited()

The following examples show how to use com.eveningoutpost.dexdrip.Models.Calibration#allForSensorLimited() . 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: Notifications.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private boolean notificationSetter(Context context) {
    ReadPerfs(context);
    final long end = System.currentTimeMillis() + (60000 * 5);
    final long start = end - (60000 * 60 * 3) - (60000 * 10);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context, start, end);
    //BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
    if (bg_ongoing && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)) {
        bgOngoingNotification(bgGraphBuilder);
    }
    if (prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()) {
        Log.d("NOTIFICATIONS", "Notifications are currently disabled!!");
        return false;
    }
    
    boolean unclearReading = BgReading.getAndRaiseUnclearReading(context);
    
    if (unclearReading) {
        AlertPlayer.getPlayer().stopAlert(context, false, true);
    } else {
        FileBasedNotifications(context);
        BgReading.checkForDropAllert(context);
        BgReading.checkForRisingAllert(context);
    }
    // TODO: Add this alerts as well to depend on unclear sensor reading.
    PersistentHigh.checkForPersistentHigh();
    //KS evaluateLowPredictionAlarm();
    //KS reportNoiseChanges();


    Sensor sensor = Sensor.currentSensor();
    // TODO need to check performance of rest of this method when in follower mode
    final List<BgReading> bgReadings = BgReading.latest(3);
    final List<Calibration> calibrations = Calibration.allForSensorLimited(3);
    if (bgReadings == null || bgReadings.size() < 3) {
        return unclearReading;
    }
    if (calibrations == null || calibrations.size() < 2) {
        return unclearReading;
    }
    BgReading bgReading = bgReadings.get(0);

    if (calibration_notifications) {
        // TODO this should only clear double calibration once after calibrations are achieved
        if (bgReadings.size() >= 3) {
            if (calibrations.size() == 0 && (new Date().getTime() - bgReadings.get(2).timestamp <= (60000 * 30)) && sensor != null) {
                if ((sensor.started_at + (60000 * 60 * 2)) < new Date().getTime()) {
                    doubleCalibrationRequest();
                } else {
                    // TODO should be aware of state
                    clearDoubleCalibrationRequest();
                }
            } else {
                clearDoubleCalibrationRequest();
            }
        } else {
            clearDoubleCalibrationRequest();
        }
        // bgreadings criteria possibly needs a review
        if (CalibrationRequest.shouldRequestCalibration(bgReading) && (new Date().getTime() - bgReadings.get(2).timestamp <= (60000 * 24))) {
            if ((!PowerStateReceiver.is_power_connected()) || (Pref.getBooleanDefaultFalse("calibration_alerts_while_charging"))) {
                if (JoH.pratelimit("calibration-request-notification", CALIBRATION_REQUEST_MAX_FREQUENCY)) {
                    extraCalibrationRequest();
                }
            }
        } else {
            // TODO should be aware of state
            clearExtraCalibrationRequest();
        }
        if (calibrations.size() >= 1 && (Math.abs((new Date().getTime() - calibrations.get(0).timestamp)) / (1000 * 60 * 60) > 12)
                && (CalibrationRequest.isSlopeFlatEnough(BgReading.last(true)))) {
            Log.d("NOTIFICATIONS", "Calibration difference in hours: " + ((new Date().getTime() - calibrations.get(0).timestamp)) / (1000 * 60 * 60));
            if ((!PowerStateReceiver.is_power_connected()) || (Pref.getBooleanDefaultFalse("calibration_alerts_while_charging"))) {
                // TODO check slope
                if (JoH.pratelimit("calibration-request-notification", CALIBRATION_REQUEST_MIN_FREQUENCY) || Pref.getBooleanDefaultFalse("calibration_alerts_repeat")) {
                    calibrationRequest();
                }
            }
        } else {
            // TODO should be aware of state
            clearCalibrationRequest();
        }

    } else {
        clearAllCalibrationNotifications();
    }
    return unclearReading;
}
 
Example 2
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private boolean notificationSetter(Context context) {
    ReadPerfs(context);
    final long end = System.currentTimeMillis() + (60000 * 5);
    final long start = end - (60000 * 60 * 3) - (60000 * 10);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context, start, end);
    //BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
    if (bg_ongoing && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)) {
        bgOngoingNotification(bgGraphBuilder);
    }
    if (prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()) {
        Log.d("NOTIFICATIONS", "Notifications are currently disabled!!");
        return false;
    }
    
    boolean unclearReading = BgReading.getAndRaiseUnclearReading(context);
    
    if (unclearReading) {
        AlertPlayer.getPlayer().stopAlert(context, false, true);
    } else {
        FileBasedNotifications(context);
        BgReading.checkForDropAllert(context);
        BgReading.checkForRisingAllert(context);
    }
    // TODO: Add this alerts as well to depend on unclear sensor reading.
    PersistentHigh.checkForPersistentHigh();
    //KS evaluateLowPredictionAlarm();
    //KS reportNoiseChanges();


    Sensor sensor = Sensor.currentSensor();
    // TODO need to check performance of rest of this method when in follower mode
    final List<BgReading> bgReadings = BgReading.latest(3);
    final List<Calibration> calibrations = Calibration.allForSensorLimited(3);
    if (bgReadings == null || bgReadings.size() < 3) {
        return unclearReading;
    }
    if (calibrations == null || calibrations.size() < 2) {
        return unclearReading;
    }
    BgReading bgReading = bgReadings.get(0);

    if (calibration_notifications) {
        // TODO this should only clear double calibration once after calibrations are achieved
        if (bgReadings.size() >= 3) {
            if (calibrations.size() == 0 && (new Date().getTime() - bgReadings.get(2).timestamp <= (60000 * 30)) && sensor != null) {
                if ((sensor.started_at + (60000 * 60 * 2)) < new Date().getTime()) {
                    doubleCalibrationRequest();
                } else {
                    // TODO should be aware of state
                    clearDoubleCalibrationRequest();
                }
            } else {
                clearDoubleCalibrationRequest();
            }
        } else {
            clearDoubleCalibrationRequest();
        }
        // bgreadings criteria possibly needs a review
        if (CalibrationRequest.shouldRequestCalibration(bgReading) && (new Date().getTime() - bgReadings.get(2).timestamp <= (60000 * 24))) {
            if ((!PowerStateReceiver.is_power_connected()) || (Pref.getBooleanDefaultFalse("calibration_alerts_while_charging"))) {
                if (JoH.pratelimit("calibration-request-notification", CALIBRATION_REQUEST_MAX_FREQUENCY)) {
                    extraCalibrationRequest();
                }
            }
        } else {
            // TODO should be aware of state
            clearExtraCalibrationRequest();
        }
        if (calibrations.size() >= 1 && (Math.abs((new Date().getTime() - calibrations.get(0).timestamp)) / (1000 * 60 * 60) > 12)
                && (CalibrationRequest.isSlopeFlatEnough(BgReading.last(true)))) {
            Log.d("NOTIFICATIONS", "Calibration difference in hours: " + ((new Date().getTime() - calibrations.get(0).timestamp)) / (1000 * 60 * 60));
            if ((!PowerStateReceiver.is_power_connected()) || (Pref.getBooleanDefaultFalse("calibration_alerts_while_charging"))) {
                // TODO check slope
                if (JoH.pratelimit("calibration-request-notification", CALIBRATION_REQUEST_MIN_FREQUENCY) || Pref.getBooleanDefaultFalse("calibration_alerts_repeat")) {
                    calibrationRequest();
                }
            }
        } else {
            // TODO should be aware of state
            clearCalibrationRequest();
        }

    } else {
        clearAllCalibrationNotifications();
    }
    return unclearReading;
}