Search in sources :

Example 1 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class SystemStatus method setSensorStatus.

private void setSensorStatus() {
    StringBuilder sensor_status = new StringBuilder();
    if (Sensor.isActive()) {
        Sensor sens = Sensor.currentSensor();
        Date date = new Date(sens.started_at);
        DateFormat df = new SimpleDateFormat();
        sensor_status.append(df.format(date));
        sensor_status.append(" (");
        sensor_status.append((System.currentTimeMillis() - sens.started_at) / (1000 * 60 * 60 * 24));
        sensor_status.append("d ");
        sensor_status.append(((System.currentTimeMillis() - sens.started_at) % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        sensor_status.append("h)");
    } else {
        sensor_status.append("not available");
    }
    sensor_status_view.setText(sensor_status.toString());
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 2 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class SystemStatusFragment method setSensorStatus.

private void setSensorStatus() {
    StringBuilder sensor_status = new StringBuilder();
    if (Sensor.isActive()) {
        Sensor sens = Sensor.currentSensor();
        Date date = new Date(sens.started_at);
        DateFormat df = new SimpleDateFormat();
        sensor_status.append(df.format(date));
        sensor_status.append(" (");
        sensor_status.append((System.currentTimeMillis() - sens.started_at) / (1000 * 60 * 60 * 24));
        sensor_status.append("d ");
        sensor_status.append(((System.currentTimeMillis() - sens.started_at) % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        sensor_status.append("h)");
    } else {
        sensor_status.append("not available");
    }
    sensor_status_view.setText(sensor_status.toString());
}
Also used : DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 3 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

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");
    }
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) StatsResult(com.eveningoutpost.dexdrip.stats.StatsResult) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 4 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method sendWearCalibrationData.

private static boolean sendWearCalibrationData(Integer count, long startTime, List<Calibration> list) {
    try {
        if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
            googleApiClient.connect();
        }
        // if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        if (googleApiClient != null) {
            Log.d(TAG, "sendWearCalibrationData");
            final Sensor sensor = Sensor.currentSensor();
            final Calibration last = list != null && list.size() > 0 ? list.get(0) : Calibration.last();
            List<Calibration> latest;
            BgReading lastBgReading = BgReading.last();
            // From BgReading:     lastBgReading.calibration.rawValueOverride()
            if (list != null)
                latest = list;
            else if (startTime != 0)
                latest = Calibration.latestForGraphSensor(count, startTime, Long.MAX_VALUE);
            else if (lastBgReading != null && lastBgReading.calibration != null && lastBgReading.calibration_flag == true) {
                Log.d(TAG, "sendWearCalibrationData lastBgReading.calibration_flag=" + lastBgReading.calibration_flag + " lastBgReading.timestamp: " + lastBgReading.timestamp + " lastBgReading.calibration.timestamp: " + lastBgReading.calibration.timestamp);
                latest = Calibration.allForSensor();
            } else {
                latest = Calibration.latest(count);
            }
            if ((sensor != null) && (last != null) && (latest != null && !latest.isEmpty())) {
                Log.d(TAG, "sendWearCalibrationData latest count = " + latest.size());
                final DataMap entries = dataMap(last);
                final ArrayList<DataMap> dataMaps = new ArrayList<>(latest.size());
                if (sensor.uuid != null) {
                    for (Calibration bg : latest) {
                        if ((bg != null) && (bg.sensor_uuid != null) && (bg.sensor_uuid.equals(sensor.uuid))) {
                            dataMaps.add(dataMap(bg));
                        }
                    }
                }
                // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putLong("time", new Date().getTime());
                entries.putDataMapArrayList("entries", dataMaps);
                new SendToDataLayerThread(WEARABLE_CALIBRATION_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
            } else
                Log.d(TAG, "sendWearCalibrationData latest count = 0");
        } else {
            Log.e(TAG, "sendWearCalibrationData No connection to wearable available for send treatment!");
            return false;
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendWearCalibrationData: " + e);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Calibration(com.eveningoutpost.dexdrip.Models.Calibration) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Date(java.util.Date) Sensor(com.eveningoutpost.dexdrip.Models.Sensor) DataMap(com.google.android.gms.wearable.DataMap)

Example 5 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method sendWearBgData.

private static boolean sendWearBgData(Integer count, long startTime, List<BgReading> list) {
    try {
        if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
            // googleApiConnect();
            googleApiClient.connect();
        }
        if (googleApiClient != null) {
            Log.d(TAG, "sendWearBgData");
            final BgReading last = BgReading.last();
            List<BgReading> latest;
            if (list != null)
                latest = list;
            else if (startTime != 0)
                latest = BgReading.latestForGraphSensor(count, startTime, Long.MAX_VALUE);
            else
                latest = BgReading.latest(count);
            if ((last != null) && (latest != null && !latest.isEmpty())) {
                final int battery = PowerStateReceiver.getBatteryLevel(xdrip.getAppContext());
                Log.d(TAG, "sendWearBgData latest count = " + latest.size() + " battery=" + battery);
                final DataMap entries = dataMap(last);
                final ArrayList<DataMap> dataMaps = new ArrayList<>(latest.size());
                final Sensor sensor = Sensor.currentSensor();
                if ((sensor != null) && (sensor.uuid != null)) {
                    for (BgReading bg : latest) {
                        if ((bg != null) && (bg.sensor_uuid != null) && (bg.sensor_uuid.equals(sensor.uuid) && (bg.calibration_uuid != null))) {
                            dataMaps.add(dataMap(bg));
                        }
                    }
                }
                // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putLong("time", new Date().getTime());
                entries.putInt("battery", battery);
                entries.putDataMapArrayList("entries", dataMaps);
                new SendToDataLayerThread(WEARABLE_BG_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
            } else
                Log.d(TAG, "sendWearBgData lastest count = 0");
        } else {
            Log.e(TAG, "sendWearBgData No connection to wearable available for send BG!");
            return false;
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendWearBgData: " + e);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Aggregations

Sensor (com.eveningoutpost.dexdrip.Models.Sensor)38 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)16 Date (java.util.Date)14 DataMap (com.google.android.gms.wearable.DataMap)12 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)8 TransmitterData (com.eveningoutpost.dexdrip.Models.TransmitterData)8 Gson (com.google.gson.Gson)6 GsonBuilder (com.google.gson.GsonBuilder)6 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)6 Paint (android.graphics.Paint)4 Point (android.graphics.Point)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Canvas (android.graphics.Canvas)2 ColorFilter (android.graphics.ColorFilter)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 DisplayMetrics (android.util.DisplayMetrics)2