Java源码示例:com.eveningoutpost.dexdrip.AddCalibration
示例1
private void calibrationRequest() {
UserNotification userNotification = UserNotification.lastCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) {
userNotification.delete();
}
final long calibration_hours = Calibration.msSinceLastCalibration() / (1000 * 60 * 60);
UserNotification.create(calibration_hours + " hours since last Calibration (@" + JoH.hourMinuteString() + ")", "calibration_alert", new Date().getTime());
String title = "Calibration Needed";
String content = calibration_hours + " hours since last calibration";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, calibrationNotificationId);
}
}
示例2
private void extraCalibrationRequest() {
UserNotification userNotification = UserNotification.lastExtraCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) { userNotification.delete(); }
UserNotification.create("Extra Calibration Requested", "extra_calibration_alert", new Date().getTime());
String title = "Calibration Requested";
String content = "Increase performance by calibrating now" + " (@" + JoH.hourMinuteString() + ")";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, extraCalibrationNotificationId);
}
}
示例3
private void calibrationRequest() {
UserNotification userNotification = UserNotification.lastCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) {
userNotification.delete();
}
final long calibration_hours = Calibration.msSinceLastCalibration() / (1000 * 60 * 60);
UserNotification.create(calibration_hours + " hours since last Calibration (@" + JoH.hourMinuteString() + ")", "calibration_alert", new Date().getTime());
String title = "Calibration Needed";
String content = calibration_hours + " hours since last calibration";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, calibrationNotificationId);
}
}
示例4
private void extraCalibrationRequest() {
UserNotification userNotification = UserNotification.lastExtraCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) { userNotification.delete(); }
UserNotification.create("Extra Calibration Requested", "extra_calibration_alert", new Date().getTime());
String title = "Calibration Requested";
String content = "Increase performance by calibrating now" + " (@" + JoH.hourMinuteString() + ")";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, extraCalibrationNotificationId);
}
}
示例5
private void calibrationRequest() {
UserNotification userNotification = UserNotification.lastCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) { userNotification.delete(); }
UserNotification.create("12 hours since last Calibration", "calibration_alert", new Date().getTime());
String title = "Calibration Needed";
String content = dateFormat.format(new Date()) + ": 12 hours since last calibration";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, calibrationNotificationId);
}
}
示例6
private void extraCalibrationRequest() {
UserNotification userNotification = UserNotification.lastExtraCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) { userNotification.delete(); }
UserNotification.create("Extra Calibration Requested", "extra_calibration_alert", new Date().getTime());
String title = "Calibration Needed";
String content = dateFormat.format(new Date()) + ": A calibration entered now will GREATLY increase performance";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, extraCalibrationNotificationId);
}
}
示例7
public static void calibrationRequest() {
UserNotification userNotification = UserNotification.lastCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) { userNotification.delete(); }
UserNotification newUserNotification = UserNotification.create("12 hours since last Calibration", "calibration_alert");
String title = "Calibration Needed";
String content = "12 hours since last calibration";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, calibrationNotificationId);
}
}
示例8
public static void extraCalibrationRequest() {
UserNotification userNotification = UserNotification.lastExtraCalibrationAlert();
if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) {
if (userNotification != null) { userNotification.delete(); }
UserNotification newUserNotification = UserNotification.create("Extra Calibration Requested", "extra_calibration_alert");
String title = "Calibration Needed";
String content = "A calibration entered now will GREATLY increase performance";
Intent intent = new Intent(mContext, AddCalibration.class);
calibrationNotificationCreate(title, content, intent, extraCalibrationNotificationId);
}
}
示例9
synchronized static void opportunisticCalibration() {
if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
final BloodTest bt = lastValid();
if (bt == null) {
Log.d(TAG, "opportunistic: No blood tests");
return;
}
if (JoH.msSince(bt.timestamp) > (Constants.HOUR_IN_MS * 8)) {
Log.d(TAG, "opportunistic: Blood test older than 8 hours ago");
return;
}
if ((bt.uuid == null) || (bt.uuid.length() < 8)) {
Log.d(TAG, "opportunisitic: invalid uuid");
return;
}
if ((bt.uuid != null) && (bt.uuid.length() > 1) && PersistentStore.getString(LAST_BT_AUTO_CALIB_UUID).equals(bt.uuid)) {
Log.d(TAG, "opportunistic: Already processed uuid: " + bt.uuid);
return;
}
final Calibration calibration = Calibration.lastValid();
if (calibration == null) {
Log.d(TAG, "opportunistic: No calibrations");
// TODO do we try to initial calibrate using this?
return;
}
if (JoH.msSince(calibration.timestamp) < Constants.HOUR_IN_MS) {
Log.d(TAG, "opportunistic: Last calibration less than 1 hour ago");
return;
}
if (bt.timestamp <= calibration.timestamp) {
Log.d(TAG, "opportunistic: Blood test isn't more recent than last calibration");
return;
}
// get closest bgreading - must be within dexcom period and locked to sensor
final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD);
if (bgReading == null) {
Log.d(TAG, "opportunistic: No matching bg reading");
return;
}
if (bt.timestamp > highest_timestamp) {
Accuracy.create(bt, bgReading, "xDrip Original");
final CalibrationAbstract plugin = PluggableCalibration.getCalibrationPluginFromPreferences();
final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null;
if (plugin != null) {
BgReading pluginBgReading = plugin.getBgReadingFromBgReading(bgReading, cd);
Accuracy.create(bt, pluginBgReading, plugin.getAlgorithmName());
}
highest_timestamp = bt.timestamp;
}
if (!CalibrationRequest.isSlopeFlatEnough(bgReading)) {
Log.d(TAG, "opportunistic: Slope is not flat enough at: " + JoH.dateTimeText(bgReading.timestamp));
return;
}
// TODO store evaluation failure for this record in cache for future optimization
// TODO Check we have prior reading as well perhaps
JoH.clearCache();
UserError.Log.ueh(TAG, "Opportunistic calibration for Blood Test at " + JoH.dateTimeText(bt.timestamp) + " of " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " matching sensor slope at: " + JoH.dateTimeText(bgReading.timestamp) + " from source " + bt.source);
final long time_since = JoH.msSince(bt.timestamp);
Log.d(TAG, "opportunistic: attempting auto calibration");
PersistentStore.setString(LAST_BT_AUTO_CALIB_UUID, bt.uuid);
Home.startHomeWithExtra(xdrip.getAppContext(),
Home.BLUETOOTH_METER_CALIBRATION,
BgGraphBuilder.unitized_string_static(bt.mgdl),
Long.toString(time_since),
"auto");
}
}
示例10
public static String evaluateAccuracy(long period) {
// CACHE??
final List<BloodTest> bloodTests = latestForGraph(1000, JoH.tsl() - period, JoH.tsl() - AddCalibration.estimatedInterstitialLagSeconds);
final List<Double> difference = new ArrayList<>();
final List<Double> plugin_difference = new ArrayList<>();
if ((bloodTests == null) || (bloodTests.size() == 0)) return null;
final boolean show_plugin = true;
final CalibrationAbstract plugin = (show_plugin) ? PluggableCalibration.getCalibrationPluginFromPreferences() : null;
for (BloodTest bt : bloodTests) {
final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD);
if (bgReading != null) {
final Calibration calibration = bgReading.calibration;
if (calibration == null) {
Log.d(TAG, "Calibration for bgReading is null! @ " + JoH.dateTimeText(bgReading.timestamp));
continue;
}
final double diff = Math.abs(bgReading.calculated_value - bt.mgdl);
difference.add(diff);
if (d) {
Log.d(TAG, "Evaluate Accuracy: difference: " + JoH.qs(diff));
}
final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null;
if ((plugin != null) && (cd != null)) {
final double plugin_diff = Math.abs(bt.mgdl - plugin.getGlucoseFromBgReading(bgReading, cd));
plugin_difference.add(plugin_diff);
if (d)
Log.d(TAG, "Evaluate Plugin Accuracy: " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " @ " + JoH.dateTimeText(bt.timestamp) + " difference: " + JoH.qs(plugin_diff) + "/" + JoH.qs(plugin_diff * Constants.MGDL_TO_MMOLL, 2) + " calibration: " + JoH.qs(cd.slope, 2) + " " + JoH.qs(cd.intercept, 2));
}
}
}
if (difference.size() == 0) return null;
double avg = DoubleMath.mean(difference);
Log.d(TAG, "Average accuracy: " + accuracyAsString(avg) + " (" + JoH.qs(avg, 5) + ")");
if (plugin_difference.size() > 0) {
double plugin_avg = DoubleMath.mean(plugin_difference);
Log.d(TAG, "Plugin Average accuracy: " + accuracyAsString(plugin_avg) + " (" + JoH.qs(plugin_avg, 5) + ")");
return accuracyAsString(plugin_avg) + " / " + accuracyAsString(avg);
}
return accuracyAsString(avg);
}
示例11
synchronized static void opportunisticCalibration() {
if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
final BloodTest bt = lastValid();
if (bt == null) {
Log.d(TAG, "opportunistic: No blood tests");
return;
}
if (JoH.msSince(bt.timestamp) > (Constants.HOUR_IN_MS * 8)) {
Log.d(TAG, "opportunistic: Blood test older than 8 hours ago");
return;
}
if ((bt.uuid == null) || (bt.uuid.length() < 8)) {
Log.d(TAG, "opportunisitic: invalid uuid");
return;
}
if ((bt.uuid != null) && (bt.uuid.length() > 1) && PersistentStore.getString(LAST_BT_AUTO_CALIB_UUID).equals(bt.uuid)) {
Log.d(TAG, "opportunistic: Already processed uuid: " + bt.uuid);
return;
}
final Calibration calibration = Calibration.lastValid();
if (calibration == null) {
Log.d(TAG, "opportunistic: No calibrations");
// TODO do we try to initial calibrate using this?
return;
}
if (JoH.msSince(calibration.timestamp) < Constants.HOUR_IN_MS) {
Log.d(TAG, "opportunistic: Last calibration less than 1 hour ago");
return;
}
if (bt.timestamp <= calibration.timestamp) {
Log.d(TAG, "opportunistic: Blood test isn't more recent than last calibration");
return;
}
// get closest bgreading - must be within dexcom period and locked to sensor
final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD);
if (bgReading == null) {
Log.d(TAG, "opportunistic: No matching bg reading");
return;
}
if (bt.timestamp > highest_timestamp) {
Accuracy.create(bt, bgReading, "xDrip Original");
final CalibrationAbstract plugin = PluggableCalibration.getCalibrationPluginFromPreferences();
final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null;
if (plugin != null) {
BgReading pluginBgReading = plugin.getBgReadingFromBgReading(bgReading, cd);
Accuracy.create(bt, pluginBgReading, plugin.getAlgorithmName());
}
highest_timestamp = bt.timestamp;
}
if (!CalibrationRequest.isSlopeFlatEnough(bgReading)) {
Log.d(TAG, "opportunistic: Slope is not flat enough at: " + JoH.dateTimeText(bgReading.timestamp));
return;
}
// TODO store evaluation failure for this record in cache for future optimization
// TODO Check we have prior reading as well perhaps
JoH.clearCache();
UserError.Log.ueh(TAG, "Opportunistic calibration for Blood Test at " + JoH.dateTimeText(bt.timestamp) + " of " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " matching sensor slope at: " + JoH.dateTimeText(bgReading.timestamp) + " from source " + bt.source);
final long time_since = JoH.msSince(bt.timestamp);
Log.d(TAG, "opportunistic: attempting auto calibration");
PersistentStore.setString(LAST_BT_AUTO_CALIB_UUID, bt.uuid);
Home.startHomeWithExtra(xdrip.getAppContext(),
Home.BLUETOOTH_METER_CALIBRATION,
BgGraphBuilder.unitized_string_static(bt.mgdl),
Long.toString(time_since),
"auto");
}
}
示例12
public static String evaluateAccuracy(long period) {
// CACHE??
final List<BloodTest> bloodTests = latestForGraph(1000, JoH.tsl() - period, JoH.tsl() - AddCalibration.estimatedInterstitialLagSeconds);
final List<Double> difference = new ArrayList<>();
final List<Double> plugin_difference = new ArrayList<>();
if ((bloodTests == null) || (bloodTests.size() == 0)) return null;
final boolean show_plugin = true;
final CalibrationAbstract plugin = (show_plugin) ? PluggableCalibration.getCalibrationPluginFromPreferences() : null;
for (BloodTest bt : bloodTests) {
final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD);
if (bgReading != null) {
final Calibration calibration = bgReading.calibration;
if (calibration == null) {
Log.d(TAG, "Calibration for bgReading is null! @ " + JoH.dateTimeText(bgReading.timestamp));
continue;
}
final double diff = Math.abs(bgReading.calculated_value - bt.mgdl);
difference.add(diff);
if (d) {
Log.d(TAG, "Evaluate Accuracy: difference: " + JoH.qs(diff));
}
final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null;
if ((plugin != null) && (cd != null)) {
final double plugin_diff = Math.abs(bt.mgdl - plugin.getGlucoseFromBgReading(bgReading, cd));
plugin_difference.add(plugin_diff);
if (d)
Log.d(TAG, "Evaluate Plugin Accuracy: " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " @ " + JoH.dateTimeText(bt.timestamp) + " difference: " + JoH.qs(plugin_diff) + "/" + JoH.qs(plugin_diff * Constants.MGDL_TO_MMOLL, 2) + " calibration: " + JoH.qs(cd.slope, 2) + " " + JoH.qs(cd.intercept, 2));
}
}
}
if (difference.size() == 0) return null;
double avg = DoubleMath.mean(difference);
Log.d(TAG, "Average accuracy: " + accuracyAsString(avg) + " (" + JoH.qs(avg, 5) + ")");
if (plugin_difference.size() > 0) {
double plugin_avg = DoubleMath.mean(plugin_difference);
Log.d(TAG, "Plugin Average accuracy: " + accuracyAsString(plugin_avg) + " (" + JoH.qs(plugin_avg, 5) + ")");
return accuracyAsString(plugin_avg) + " / " + accuracyAsString(avg);
}
return accuracyAsString(avg);
}