Search in sources :

Example 1 with UserError

use of com.eveningoutpost.dexdrip.Models.UserError 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 2 with UserError

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

the class ListenerService method getWearLogData.

private synchronized DataMap getWearLogData(int count, long last_send_time, int min_count, long syncLogsRequested) {
    forceGoogleApiConnect();
    Log.d(TAG, "getWearLogData last_send_time:" + JoH.dateTimeText(last_send_time) + " max count=" + count + " min_count=" + min_count + " syncLogsRequested=" + syncLogsRequested);
    UserError last_log = UserError.last();
    if (last_log != null) {
        Log.d(TAG, "getWearLogData last_log.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
    }
    if (last_log != null && last_send_time <= last_log.timestamp) {
        // startTime
        long last_send_success = last_send_time;
        Log.d(TAG, "getWearLogData last_send_time < last_bg.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
        List<UserError> logs = UserError.latestAsc(count, last_send_time);
        if (!logs.isEmpty() && logs.size() > min_count) {
            // Log.d(TAG, "getWearLogData count = " + logs.size());
            DataMap entries = dataMap(last_log);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(logs.size());
            for (UserError log : logs) {
                dataMaps.add(dataMap(log));
                last_send_success = (long) log.timestamp;
            // Log.d(TAG, "getWearLogData set last_send_sucess:" + JoH.dateTimeText(last_send_sucess) + " Log:" + log.toString());
            }
            // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putLong("time", new Date().getTime());
            entries.putLong("syncLogsRequested", syncLogsRequested);
            entries.putDataMapArrayList("entries", dataMaps);
            Log.i(TAG, "getWearLogData SYNCED logs up to " + JoH.dateTimeText(last_send_success) + " count = " + logs.size() + " syncLogsRequested=" + syncLogsRequested);
            return entries;
        } else
            Log.i(TAG, "getWearLogData SYNCED logs up to " + JoH.dateTimeText(last_send_success) + " count = 0" + " syncLogsRequested=" + syncLogsRequested);
    }
    return null;
}
Also used : UserError(com.eveningoutpost.dexdrip.Models.UserError) ArrayList(java.util.ArrayList) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 3 with UserError

use of com.eveningoutpost.dexdrip.Models.UserError in project xDrip-plus by jamorham.

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 4 with UserError

use of com.eveningoutpost.dexdrip.Models.UserError in project xDrip-plus by jamorham.

the class ErrorListAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.item_user_error, null);
    }
    LinearLayout row = (LinearLayout) view.findViewById(R.id.errorRow);
    TextView shortText = (TextView) view.findViewById(R.id.errorShort);
    TextView longText = (TextView) view.findViewById(R.id.errorLong);
    TextView timestamp = (TextView) view.findViewById(R.id.errorTimestamp);
    UserError error = list.get(position);
    row.setBackgroundColor(backgroundFor(error.severity));
    shortText.setText(error.shortError);
    longText.setText(error.message);
    timestamp.setText(dateformatter(error.timestamp));
    return view;
}
Also used : UserError(com.eveningoutpost.dexdrip.Models.UserError) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 5 with UserError

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

the class ListenerService method isSafeToDeleteDB.

private boolean isSafeToDeleteDB() {
    // TODO remove once confirm not needed
    TransmitterData last_bg = TransmitterData.last();
    if (last_bg != null && last_send_previous <= last_bg.timestamp) {
        Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous < last_bg.timestamp:" + JoH.dateTimeText(last_send_previous) + "<=" + JoH.dateTimeText(last_bg.timestamp));
        requestData();
        return false;
    }
    if (mPrefs.getBoolean("sync_wear_logs", false)) {
        UserError last_log = UserError.last();
        if (last_log != null && last_send_previous_log <= last_log.timestamp) {
            Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous_log < last_log.timestamp:" + JoH.dateTimeText(last_send_previous_log) + "<=" + JoH.dateTimeText((long) last_log.timestamp));
            return false;
        }
    }
    return true;
}
Also used : TransmitterData(com.eveningoutpost.dexdrip.Models.TransmitterData) UserError(com.eveningoutpost.dexdrip.Models.UserError)

Aggregations

UserError (com.eveningoutpost.dexdrip.Models.UserError)10 DataMap (com.google.android.gms.wearable.DataMap)4 Intent (android.content.Intent)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 TransmitterData (com.eveningoutpost.dexdrip.Models.TransmitterData)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2