Search in sources :

Example 1 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method syncStepSensorData.

private synchronized void syncStepSensorData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncStepSensorData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    Log.d(TAG, "syncStepSensorData add to Table");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        StepCounter pm = StepCounter.last();
        Log.d(TAG, "syncStepSensorData add Table entries count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncStepSensorData add Table entry=" + entry);
                String record = entry.getString("entry");
                if (record != null) {
                    Log.d(TAG, "syncStepSensorData add Table record=" + record);
                    StepCounter data = gson.fromJson(record, StepCounter.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        Log.d(TAG, "syncStepSensorData add Entry Wear=" + data.toString());
                        Log.d(TAG, "syncStepSensorData WATCH data.metric=" + data.metric + " timestamp=" + JoH.dateTimeText((long) data.timestamp));
                        if (!bBenchmark)
                            data.saveit();
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "STEP", -1);
    }
}
Also used : StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) DataMap(com.google.android.gms.wearable.DataMap)

Example 2 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method syncLogData.

private synchronized void syncLogData(DataMap dataMap, boolean bBenchmark) {
    // KS
    Log.d(TAG, "syncLogData");
    long watch_syncLogsRequested = dataMap.getLong("syncLogsRequested", -1);
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    int saved = 0;
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        Log.d(TAG, "syncLogData add Table entries count=" + entries.size() + " watch_syncLogsRequested=" + watch_syncLogsRequested);
        for (DataMap entry : entries) {
            if (entry != null) {
                String record = entry.getString("entry");
                if (record != null) {
                    UserError data = gson.fromJson(record, UserError.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        if (data.shortError != null && !data.shortError.isEmpty()) {
                            // add wear prefix
                            if (!data.shortError.startsWith("wear")) {
                                data.shortError = mPrefs.getString("wear_logs_prefix", "wear") + data.shortError;
                            }
                        }
                        UserError exists = UserError.getForTimestamp(data);
                        if (exists == null && !bBenchmark) {
                            data.save();
                            saved++;
                        } else {
                        // Log.d(TAG, "syncLogData Log entry already exists with shortError=" + data.shortError + " timestamp=" + JoH.dateTimeText((long)data.timestamp));
                        }
                    }
                }
            }
        }
        if (saved > 0) {
            Log.d(TAG, "syncLogData Saved timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " saved=" + saved);
        } else {
            Log.d(TAG, "syncLogData No records saved due to being duplicates! timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " count=" + entries.size());
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "LOG", watch_syncLogsRequested);
    }
}
Also used : UserError(com.eveningoutpost.dexdrip.Models.UserError) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) DataMap(com.google.android.gms.wearable.DataMap)

Example 3 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.

the class ListenerService method syncCalibrationData.

private synchronized void syncCalibrationData(DataMap dataMap, Context context) {
    // KS
    Log.d(TAG, "syncCalibrationData");
    boolean changed = false;
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        Log.d(TAG, "syncCalibrationData add Calibration Table entries count=" + entries.size());
        // ensure database has already been initialized
        Sensor.InitDb(context);
        Sensor sensor = Sensor.currentSensor();
        if (sensor != null) {
            for (DataMap entry : entries) {
                if (entry != null) {
                    String bgrecord = entry.getString("bgs");
                    if (bgrecord != null) {
                        Calibration bgData = gson.fromJson(bgrecord, Calibration.class);
                        Calibration exists = Calibration.findByUuid(bgData.uuid);
                        bgData.sensor = sensor;
                        if (exists != null) {
                            Log.d(TAG, "syncCalibrationData Calibration exists for uuid=" + bgData.uuid + " bg=" + bgData.bg + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
                            if (exists.slope != bgData.slope || exists.slope_confidence != bgData.slope_confidence || exists.timestamp != bgData.timestamp || exists.bg != bgData.bg) {
                                // slope* indicates if shown on graph
                                changed = true;
                            }
                            exists.adjusted_raw_value = bgData.adjusted_raw_value;
                            exists.bg = bgData.bg;
                            exists.check_in = bgData.check_in;
                            exists.distance_from_estimate = bgData.distance_from_estimate;
                            exists.estimate_bg_at_time_of_calibration = bgData.estimate_bg_at_time_of_calibration;
                            exists.estimate_raw_at_time_of_calibration = bgData.estimate_raw_at_time_of_calibration;
                            exists.first_decay = bgData.first_decay;
                            exists.first_intercept = bgData.first_intercept;
                            exists.first_scale = bgData.first_scale;
                            exists.first_slope = bgData.first_slope;
                            exists.intercept = bgData.intercept;
                            exists.possible_bad = bgData.possible_bad;
                            exists.raw_timestamp = bgData.raw_timestamp;
                            exists.raw_value = bgData.raw_value;
                            exists.second_decay = bgData.second_decay;
                            exists.second_intercept = bgData.second_intercept;
                            exists.second_scale = bgData.second_scale;
                            exists.second_slope = bgData.second_slope;
                            exists.sensor = sensor;
                            exists.sensor_age_at_time_of_estimation = bgData.sensor_age_at_time_of_estimation;
                            exists.sensor_confidence = bgData.sensor_confidence;
                            exists.sensor_uuid = bgData.sensor_uuid;
                            exists.slope = bgData.slope;
                            exists.slope_confidence = bgData.slope_confidence;
                            exists.timestamp = bgData.timestamp;
                            exists.save();
                        } else {
                            changed = true;
                            bgData.save();
                            // final boolean adjustPast = mPrefs.getBoolean("rewrite_history", true);
                            Log.d(TAG, "syncCalibrationData Calibration does not exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
                        // Calibration.adjustRecentBgReadings(adjustPast ? 30 : 2);
                        }
                        exists = Calibration.findByUuid(bgData.uuid);
                        if (exists != null)
                            Log.d(TAG, "syncCalibrationData Calibration GSON saved BG: " + exists.toS());
                        else
                            Log.d(TAG, "syncCalibrationData Calibration GSON NOT saved");
                    }
                }
            }
        } else {
            Log.d(TAG, "syncCalibrationData No Active Sensor!! Request WEARABLE_INITDB_PATH");
            sendData(WEARABLE_INITDB_PATH, null);
        }
        if (changed) {
            showTreatments(context, "cals");
        }
    }
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Calibration(com.eveningoutpost.dexdrip.Models.Calibration) DataMap(com.google.android.gms.wearable.DataMap) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 4 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.

the class ListenerService method syncTreatmentsData.

private synchronized void syncTreatmentsData(DataMap dataMap, Context context) {
    Log.d(TAG, "syncTreatmentsData");
    boolean changed = false;
    String action = dataMap.getString("action");
    if (action.equals("delete")) {
        Log.d(TAG, "syncTreatmentsData Delete Treatments");
        deleteTreatment(dataMap);
        showTreatments(context, "treats");
    } else {
        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
            Log.d(TAG, "syncTreatmentsData add Treatments Table entries count=" + entries.size());
            // ensure database has already been initialized
            Sensor.InitDb(context);
            for (DataMap entry : entries) {
                if (entry != null) {
                    String record = entry.getString("data");
                    if (record != null) {
                        Treatments data = gson.fromJson(record, Treatments.class);
                        Treatments exists = Treatments.byuuid(data.uuid);
                        if (exists != null) {
                            Log.d(TAG, "syncTreatmentsData save existing Treatments for action insert uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " carbs=" + data.carbs + " insulin=" + data.insulin + " exists.systime=" + JoH.dateTimeText(exists.systimestamp));
                            if (exists.timestamp != data.timestamp) {
                                // currently only tracking timestamp on watch
                                changed = true;
                            }
                            exists.enteredBy = data.enteredBy;
                            exists.eventType = data.eventType;
                            exists.insulin = data.insulin;
                            exists.carbs = data.carbs;
                            exists.created_at = data.created_at;
                            exists.notes = data.notes;
                            exists.timestamp = data.timestamp;
                            exists.systimestamp = exists.systimestamp > 0 ? exists.systimestamp : data.timestamp < last_send_previous_treatments ? data.timestamp : last_send_previous_treatments > 0 ? last_send_previous_treatments - 1 : JoH.tsl();
                            exists.save();
                        } else {
                            changed = true;
                            data.systimestamp = data.timestamp < last_send_previous_treatments ? data.timestamp : last_send_previous_treatments > 0 ? last_send_previous_treatments - 1 : JoH.tsl();
                            data.save();
                            Log.d(TAG, "syncTreatmentsData create new treatment for action insert uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " carbs=" + data.carbs + " insulin=" + data.insulin + " systime=" + JoH.dateTimeText(data.systimestamp));
                        }
                    }
                }
            }
            if (changed) {
                showTreatments(context, "treats");
            }
        }
    }
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Treatments(com.eveningoutpost.dexdrip.Models.Treatments) DataMap(com.google.android.gms.wearable.DataMap)

Example 5 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.

the class Sensor method toS.

public String toS() {
    // KS
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
    Log.d("SENSOR", "Sensor toS uuid=" + this.uuid + " started_at=" + this.started_at + " active=" + this.isActive() + " battery=" + this.latest_battery_level + " location=" + this.sensor_location + " stopped_at=" + this.stopped_at);
    return gson.toJson(this);
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)24 GsonBuilder (com.google.gson.GsonBuilder)24 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)24 DataMap (com.google.android.gms.wearable.DataMap)16 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)6 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)4 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)4 SharedPreferences (android.content.SharedPreferences)2 Select (com.activeandroid.query.Select)2 AlertType (com.eveningoutpost.dexdrip.Models.AlertType)2 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)2 StepCounter (com.eveningoutpost.dexdrip.Models.StepCounter)2 TransmitterData (com.eveningoutpost.dexdrip.Models.TransmitterData)2 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)2 UserError (com.eveningoutpost.dexdrip.Models.UserError)2