use of com.eveningoutpost.dexdrip.stats.StatsResult in project xDrip by NightscoutFoundation.
the class BgSendQueue method extraStatusLine.
@NonNull
public static String extraStatusLine(SharedPreferences prefs) {
if ((prefs == null) && (xdrip.getAppContext() != null)) {
prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
}
if (prefs == null)
return "";
final StringBuilder extraline = new StringBuilder();
final Calibration lastCalibration = Calibration.lastValid();
if (prefs.getBoolean("status_line_calibration_long", false) && lastCalibration != null) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append("slope = ");
extraline.append(String.format("%.2f", lastCalibration.slope));
extraline.append(' ');
extraline.append("inter = ");
extraline.append(String.format("%.2f", lastCalibration.intercept));
}
if (prefs.getBoolean("status_line_calibration_short", false) && lastCalibration != null) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append("s:");
extraline.append(String.format("%.2f", lastCalibration.slope));
extraline.append(' ');
extraline.append("i:");
extraline.append(String.format("%.2f", lastCalibration.intercept));
}
if (prefs.getBoolean("status_line_avg", false) || prefs.getBoolean("status_line_a1c_dcct", false) || prefs.getBoolean("status_line_a1c_ifcc", false) || prefs.getBoolean("status_line_in", false) || prefs.getBoolean("status_line_high", false) || prefs.getBoolean("status_line_low", false) || prefs.getBoolean("status_line_stdev", false) || prefs.getBoolean("status_line_carbs", false) || prefs.getBoolean("status_line_insulin", false) || prefs.getBoolean("status_line_royce_ratio", false) || prefs.getBoolean("status_line_accuracy", false) || prefs.getBoolean("status_line_capture_percentage", false)) {
final StatsResult statsResult = new StatsResult(prefs, Pref.getBooleanDefaultFalse("extra_status_stats_24h"));
if (prefs.getBoolean("status_line_avg", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getAverageUnitised());
}
if (prefs.getBoolean("status_line_a1c_dcct", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getA1cDCCT());
}
if (prefs.getBoolean("status_line_a1c_ifcc", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getA1cIFCC());
}
if (prefs.getBoolean("status_line_in", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getInPercentage());
}
if (prefs.getBoolean("status_line_high", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getHighPercentage());
}
if (prefs.getBoolean("status_line_low", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getLowPercentage());
}
if (prefs.getBoolean("status_line_stdev", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getStdevUnitised());
}
if (prefs.getBoolean("status_line_carbs", false) && prefs.getBoolean("show_wear_treatments", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
// extraline.append("Carbs: " + statsResult.getTotal_carbs());
double carbs = statsResult.getTotal_carbs();
extraline.append(carbs == -1 ? "" : "Carbs:" + carbs);
Log.d("BgSendQueue", "extraStatusLine carbs=" + carbs);
} else
Log.d("BgSendQueue", "extraStatusLine getTotal_carbs=-1");
if (prefs.getBoolean("status_line_insulin", false) && prefs.getBoolean("show_wear_treatments", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
double insulin = statsResult.getTotal_insulin();
extraline.append(insulin == -1 ? "" : "U:" + JoH.qs(insulin, 2));
}
if (prefs.getBoolean("status_line_royce_ratio", false) && prefs.getBoolean("show_wear_treatments", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
double ratio = statsResult.getRatio();
extraline.append(ratio == -1 ? "" : "C/I:" + JoH.qs(ratio, 2));
}
if (prefs.getBoolean("status_line_capture_percentage", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
// KS TODO = BloodTest.evaluateAccuracy(WEEK_IN_MS);
final String accuracy = null;
extraline.append(statsResult.getCapturePercentage(false) + ((accuracy != null) ? " " + accuracy : ""));
}
/*TODO if (prefs.getBoolean("status_line_accuracy", false)) {
final long accuracy_period = DAY_IN_MS * 3;
if (extraline.length() != 0) extraline.append(' ');
final String accuracy_report = Accuracy.evaluateAccuracy(accuracy_period);
if ((accuracy_report != null) && (accuracy_report.length() > 0)) {
extraline.append(accuracy_report);
} else {
final String accuracy = BloodTest.evaluateAccuracy(accuracy_period);
extraline.append(((accuracy != null) ? " " + accuracy : ""));
}
}*/
}
/* //KS TODO
if (prefs.getBoolean("extra_status_calibration_plugin", false)) {
final CalibrationAbstract plugin = getCalibrationPluginFromPreferences(); // make sure do this only once
if (plugin != null) {
final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData();
if (extraline.length() > 0) extraline.append("\n"); // not tested on the widget yet
if (pcalibration != null) extraline.append("(" + plugin.getAlgorithmName() + ") s:" + JoH.qs(pcalibration.slope, 2) + " i:" + JoH.qs(pcalibration.intercept, 2));
BgReading bgReading = BgReading.last();
if (bgReading != null) {
final boolean doMgdl = prefs.getString("units", "mgdl").equals("mgdl");
extraline.append(" \u21D2 " + BgGraphBuilder.unitized_string(plugin.getGlucoseFromSensorValue(bgReading.age_adjusted_raw_value), doMgdl) + " " + BgGraphBuilder.unit(doMgdl));
}
}
// If we are using the plugin as the primary then show xdrip original as well
if (Pref.getBooleanDefaultFalse("display_glucose_from_plugin") || Pref.getBooleanDefaultFalse("use_pluggable_alg_as_primary")) {
final CalibrationAbstract plugin_xdrip = getCalibrationPlugin(PluggableCalibration.Type.xDripOriginal); // make sure do this only once
if (plugin_xdrip != null) {
final CalibrationAbstract.CalibrationData pcalibration = plugin_xdrip.getCalibrationData();
if (extraline.length() > 0)
extraline.append("\n"); // not tested on the widget yet
if (pcalibration != null)
extraline.append("(" + plugin_xdrip.getAlgorithmName() + ") s:" + JoH.qs(pcalibration.slope, 2) + " i:" + JoH.qs(pcalibration.intercept, 2));
BgReading bgReading = BgReading.last();
if (bgReading != null) {
final boolean doMgdl = prefs.getString("units", "mgdl").equals("mgdl");
extraline.append(" \u21D2 " + BgGraphBuilder.unitized_string(plugin_xdrip.getGlucoseFromSensorValue(bgReading.age_adjusted_raw_value), doMgdl) + " " + BgGraphBuilder.unit(doMgdl));
}
}
}
}
if (prefs.getBoolean("status_line_time", false)) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
if (extraline.length() != 0) extraline.append(' ');
extraline.append(sdf.format(new Date()));
}
*/
return extraline.toString();
}
use of com.eveningoutpost.dexdrip.stats.StatsResult in project xDrip-plus by jamorham.
the class BgSendQueue method extraStatusLine.
@NonNull
public static String extraStatusLine(SharedPreferences prefs) {
if ((prefs == null) && (xdrip.getAppContext() != null)) {
prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
}
if (prefs == null)
return "";
final StringBuilder extraline = new StringBuilder();
final Calibration lastCalibration = Calibration.lastValid();
if (prefs.getBoolean("status_line_calibration_long", false) && lastCalibration != null) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append("slope = ");
extraline.append(String.format("%.2f", lastCalibration.slope));
extraline.append(' ');
extraline.append("inter = ");
extraline.append(String.format("%.2f", lastCalibration.intercept));
}
if (prefs.getBoolean("status_line_calibration_short", false) && lastCalibration != null) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append("s:");
extraline.append(String.format("%.2f", lastCalibration.slope));
extraline.append(' ');
extraline.append("i:");
extraline.append(String.format("%.2f", lastCalibration.intercept));
}
if (prefs.getBoolean("status_line_avg", false) || prefs.getBoolean("status_line_a1c_dcct", false) || prefs.getBoolean("status_line_a1c_ifcc", false) || prefs.getBoolean("status_line_in", false) || prefs.getBoolean("status_line_high", false) || prefs.getBoolean("status_line_low", false) || prefs.getBoolean("status_line_stdev", false) || prefs.getBoolean("status_line_carbs", false) || prefs.getBoolean("status_line_insulin", false) || prefs.getBoolean("status_line_royce_ratio", false) || prefs.getBoolean("status_line_accuracy", false) || prefs.getBoolean("status_line_capture_percentage", false)) {
final StatsResult statsResult = new StatsResult(prefs, Pref.getBooleanDefaultFalse("extra_status_stats_24h"));
if (prefs.getBoolean("status_line_avg", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getAverageUnitised());
}
if (prefs.getBoolean("status_line_a1c_dcct", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getA1cDCCT());
}
if (prefs.getBoolean("status_line_a1c_ifcc", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getA1cIFCC());
}
if (prefs.getBoolean("status_line_in", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getInPercentage());
}
if (prefs.getBoolean("status_line_high", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getHighPercentage());
}
if (prefs.getBoolean("status_line_low", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getLowPercentage());
}
if (prefs.getBoolean("status_line_stdev", false)) {
if (extraline.length() != 0)
extraline.append(' ');
extraline.append(statsResult.getStdevUnitised());
}
if (prefs.getBoolean("status_line_carbs", false) && prefs.getBoolean("show_wear_treatments", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
// extraline.append("Carbs: " + statsResult.getTotal_carbs());
double carbs = statsResult.getTotal_carbs();
extraline.append(carbs == -1 ? "" : "Carbs:" + carbs);
Log.d("BgSendQueue", "extraStatusLine carbs=" + carbs);
} else
Log.d("BgSendQueue", "extraStatusLine getTotal_carbs=-1");
if (prefs.getBoolean("status_line_insulin", false) && prefs.getBoolean("show_wear_treatments", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
double insulin = statsResult.getTotal_insulin();
extraline.append(insulin == -1 ? "" : "U:" + JoH.qs(insulin, 2));
}
if (prefs.getBoolean("status_line_royce_ratio", false) && prefs.getBoolean("show_wear_treatments", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
double ratio = statsResult.getRatio();
extraline.append(ratio == -1 ? "" : "C/I:" + JoH.qs(ratio, 2));
}
if (prefs.getBoolean("status_line_capture_percentage", false)) {
if (extraline.length() != 0 && extraline.charAt(extraline.length() - 1) != ' ')
extraline.append(' ');
// KS TODO = BloodTest.evaluateAccuracy(WEEK_IN_MS);
final String accuracy = null;
extraline.append(statsResult.getCapturePercentage(false) + ((accuracy != null) ? " " + accuracy : ""));
}
/*TODO if (prefs.getBoolean("status_line_accuracy", false)) {
final long accuracy_period = DAY_IN_MS * 3;
if (extraline.length() != 0) extraline.append(' ');
final String accuracy_report = Accuracy.evaluateAccuracy(accuracy_period);
if ((accuracy_report != null) && (accuracy_report.length() > 0)) {
extraline.append(accuracy_report);
} else {
final String accuracy = BloodTest.evaluateAccuracy(accuracy_period);
extraline.append(((accuracy != null) ? " " + accuracy : ""));
}
}*/
}
/* //KS TODO
if (prefs.getBoolean("extra_status_calibration_plugin", false)) {
final CalibrationAbstract plugin = getCalibrationPluginFromPreferences(); // make sure do this only once
if (plugin != null) {
final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData();
if (extraline.length() > 0) extraline.append("\n"); // not tested on the widget yet
if (pcalibration != null) extraline.append("(" + plugin.getAlgorithmName() + ") s:" + JoH.qs(pcalibration.slope, 2) + " i:" + JoH.qs(pcalibration.intercept, 2));
BgReading bgReading = BgReading.last();
if (bgReading != null) {
final boolean doMgdl = prefs.getString("units", "mgdl").equals("mgdl");
extraline.append(" \u21D2 " + BgGraphBuilder.unitized_string(plugin.getGlucoseFromSensorValue(bgReading.age_adjusted_raw_value), doMgdl) + " " + BgGraphBuilder.unit(doMgdl));
}
}
// If we are using the plugin as the primary then show xdrip original as well
if (Pref.getBooleanDefaultFalse("display_glucose_from_plugin") || Pref.getBooleanDefaultFalse("use_pluggable_alg_as_primary")) {
final CalibrationAbstract plugin_xdrip = getCalibrationPlugin(PluggableCalibration.Type.xDripOriginal); // make sure do this only once
if (plugin_xdrip != null) {
final CalibrationAbstract.CalibrationData pcalibration = plugin_xdrip.getCalibrationData();
if (extraline.length() > 0)
extraline.append("\n"); // not tested on the widget yet
if (pcalibration != null)
extraline.append("(" + plugin_xdrip.getAlgorithmName() + ") s:" + JoH.qs(pcalibration.slope, 2) + " i:" + JoH.qs(pcalibration.intercept, 2));
BgReading bgReading = BgReading.last();
if (bgReading != null) {
final boolean doMgdl = prefs.getString("units", "mgdl").equals("mgdl");
extraline.append(" \u21D2 " + BgGraphBuilder.unitized_string(plugin_xdrip.getGlucoseFromSensorValue(bgReading.age_adjusted_raw_value), doMgdl) + " " + BgGraphBuilder.unit(doMgdl));
}
}
}
}
if (prefs.getBoolean("status_line_time", false)) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
if (extraline.length() != 0) extraline.append(' ');
extraline.append(sdf.format(new Date()));
}
*/
return extraline.toString();
}
use of com.eveningoutpost.dexdrip.stats.StatsResult in project xDrip-plus by jamorham.
the class Telemetry method sendCaptureReport.
/*
No personal information is sent.
Only the level of success in receiving sensor data and
the make/model/version/settings/type of phone and collector used.
This is to try to find any patterns relating to successful combinations, for example
G5 collection working better with Samsung devices or not.
*/
public static void sendCaptureReport() {
try {
if (JoH.ratelimit("capture-report", 50000)) {
Log.d(TAG, "SEND EVENT START");
if (Pref.getBooleanDefaultFalse("enable_crashlytics") && Pref.getBooleanDefaultFalse("enable_telemetry")) {
final Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
if (JoH.msSince(sensor.started_at) > 86400000) {
final StatsResult statsResult = new StatsResult(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()), true);
final int capture_percentage = statsResult.getCapturePercentage();
final int capture_set = (capture_percentage / 10) * 10;
if (capture_set > 60) {
final boolean use_transmiter_pl_bluetooth = Pref.getBooleanDefaultFalse("use_transmiter_pl_bluetooth");
final boolean use_rfduino_bluetooth = Pref.getBooleanDefaultFalse("use_rfduino_bluetooth");
final String subtype = (use_transmiter_pl_bluetooth ? "TR" : "") + (use_rfduino_bluetooth ? "RF" : "") + (Home.get_forced_wear() ? "W" : "") + (NFCReaderX.used_nfc_successfully ? "N" : "");
final String capture_id = DexCollectionType.getDexCollectionType().toString() + subtype + " Captured " + capture_set;
Log.d(TAG, "SEND CAPTURE EVENT PROCESS: " + capture_id);
String watch_model = "";
if (Home.get_forced_wear()) {
// anonymize watch model
final String wear_node = Pref.getStringDefaultBlank("node_wearG5");
if (wear_node.length() > 0) {
final String[] wear_array = wear_node.split(" ");
for (String ii : wear_array) {
if (!ii.contains("|"))
watch_model = watch_model + ii;
}
}
}
if (watch_model.length() > 0) {
Answers.getInstance().logCustom(new CustomEvent(capture_id).putCustomAttribute("Model", Build.MODEL + " " + Build.VERSION.RELEASE).putCustomAttribute("Manufacturer", Build.MANUFACTURER).putCustomAttribute("Version", Build.VERSION.RELEASE).putCustomAttribute("xDrip", getVersionDetails()).putCustomAttribute("Watch", watch_model).putCustomAttribute("Percentage", capture_percentage));
} else {
Answers.getInstance().logCustom(new CustomEvent(capture_id).putCustomAttribute("Model", Build.MODEL + " " + Build.VERSION.RELEASE).putCustomAttribute("Manufacturer", Build.MANUFACTURER).putCustomAttribute("Version", Build.VERSION.RELEASE).putCustomAttribute("xDrip", getVersionDetails()).putCustomAttribute("Percentage", capture_percentage));
}
}
} else {
Log.d(TAG, "Sensor not running for more than 24 hours yet");
}
} else {
Log.d(TAG, "No sensor active");
}
Log.d(TAG, "SEND EVENT DONE");
}
}
} catch (Exception e) {
Log.e(TAG, "Got exception sending Capture Report");
}
}
Aggregations