Search in sources :

Example 1 with StepCounter

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

the class BgGraphBuilder method stepsLines.

// line illustrating result from step counter
private List<Line> stepsLines() {
    final List<Line> stepsLines = new ArrayList<>();
    if ((prefs.getBoolean("use_pebble_health", true) && prefs.getBoolean("show_pebble_movement_line", true))) {
        final List<StepCounter> pmlist = StepCounter.deltaListFromMovementList(StepCounter.latestForGraph(2000, loaded_start, loaded_end));
        PointValue last_point = null;
        final boolean d = false;
        if (d)
            Log.d(TAG, "Delta: pmlist size: " + pmlist.size());
        final float yscale = doMgdl ? (float) Constants.MMOLL_TO_MGDL : 1f;
        // TODO Configurable
        final float ypos = 6 * yscale;
        // final long last_timestamp = pmlist.get(pmlist.size() - 1).timestamp;
        final float MAX_SIZE = 50;
        int flipper = 0;
        int accumulator = 0;
        for (StepCounter pm : pmlist) {
            if (last_point == null) {
                last_point = new PointValue((float) pm.timestamp / FUZZER, ypos);
            } else {
                final PointValue this_point = new PointValue((float) pm.timestamp / FUZZER, ypos);
                final float time_delta = this_point.getX() - last_point.getX();
                if (time_delta > 1) {
                    final List<PointValue> new_points = new ArrayList<>();
                    new_points.add(last_point);
                    new_points.add(this_point);
                    // update pointer
                    last_point = this_point;
                    final Line this_line = new Line(new_points);
                    flipper ^= 1;
                    this_line.setColor((flipper == 0) ? getCol(X.color_step_counter1) : getCol(X.color_step_counter2));
                    float stroke_size = Math.min(MAX_SIZE, (float) Math.log1p(((double) (pm.metric + accumulator)) / time_delta) * 4);
                    if (d)
                        Log.d(TAG, "Delta stroke: " + stroke_size);
                    this_line.setStrokeWidth((int) stroke_size);
                    if (d)
                        Log.d(TAG, "Delta-Line: " + JoH.dateTimeText(pm.timestamp) + " time delta: " + time_delta + "  total: " + (pm.metric + accumulator) + " lsize: " + stroke_size + " / " + (int) stroke_size);
                    accumulator = 0;
                    if (this_line.getStrokeWidth() > 0) {
                        stepsLines.add(this_line);
                        this_line.setHasPoints(false);
                        this_line.setHasLines(true);
                    } else {
                        if (d)
                            Log.d(TAG, "Delta skip: " + JoH.dateTimeText(pm.timestamp));
                    }
                    if (d)
                        Log.d(TAG, "Delta-List: " + JoH.dateTimeText(pm.timestamp) + " time delta: " + time_delta + "  val: " + pm.metric);
                } else {
                    accumulator += pm.metric;
                    if (d)
                        Log.d(TAG, "Delta: added: " + JoH.dateTimeText(pm.timestamp) + " metric: " + pm.metric + " to accumulator: " + accumulator);
                }
            }
        }
        if (d)
            Log.d(TAG, "Delta returning stepsLines: " + stepsLines.size() + " final accumulator remaining: " + accumulator);
    }
    return stepsLines;
}
Also used : TrendLine(com.eveningoutpost.dexdrip.Models.Forecast.TrendLine) PolyTrendLine(com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine) Line(lecho.lib.hellocharts.model.Line) StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter) PointValue(lecho.lib.hellocharts.model.PointValue) ArrayList(java.util.ArrayList)

Example 2 with StepCounter

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

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

the class Home method updateHealthInfo.

private void updateHealthInfo(String caller) {
    final StepCounter pm = StepCounter.last();
    final boolean use_pebble_health = Pref.getBoolean("use_pebble_health", true);
    if ((use_pebble_health) && (pm != null)) {
        stepsButton.setText(Integer.toString(pm.metric));
        stepsButton.setVisibility(View.VISIBLE);
        // TODO this can be done with PrefsView binding
        stepsButton.setAlpha(Pref.getBoolean("show_pebble_movement_line", true) ? 1.0f : 0.3f);
    } else {
        stepsButton.setVisibility(View.INVISIBLE);
    }
    final HeartRate hr = HeartRate.last();
    if ((use_pebble_health) && (hr != null)) {
        bpmButton.setText(Integer.toString(hr.bpm));
        bpmButton.setVisibility(View.VISIBLE);
        // TODO this can be done with PrefsView binding
        bpmButton.setAlpha(Pref.getBoolean("show_pebble_movement_line", true) ? 1.0f : 0.3f);
    } else {
        bpmButton.setVisibility(View.INVISIBLE);
    }
}
Also used : StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter) HeartRate(com.eveningoutpost.dexdrip.Models.HeartRate)

Example 4 with StepCounter

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

the class WebServiceSteps method request.

// process the request and produce a response object
public WebResponse request(String query) {
    query = stripFirstComponent(query);
    List<String> components = getUrlComponents(query);
    if (components.size() > 0) {
        UserError.Log.d(TAG, "Processing " + query);
        switch(components.get(0)) {
            case "set":
                if (components.size() == 2) {
                    // sets pebble movement data for steps NOW, must be current step counter reading only
                    try {
                        int data = Integer.parseInt(components.get(1));
                        final StepCounter pm = StepCounter.createEfficientRecord(JoH.tsl(), data);
                        return webOk("Updated step counter: " + data);
                    } catch (NumberFormatException e) {
                        return webError("Couldn't parse Set value: " + components.get(1));
                    }
                } else {
                    return webError("Incorrect parameters for Set", 400);
                }
            // break;
            default:
                return webError("Unknown steps command: " + components.get(0));
        }
    } else {
        return webError("No steps command specified", 404);
    }
}
Also used : StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter)

Example 5 with StepCounter

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

the class NightscoutUploader method postStepsCount.

private void postStepsCount(NightscoutService nightscoutService, String apiSecret) throws Exception {
    Log.d(TAG, "Processing steps for RESTAPI");
    final String STORE_COUNTER = "nightscout-rest-steps-synced-time";
    if (apiSecret != null) {
        final long syncedTillTime = Math.max(PersistentStore.getLong(STORE_COUNTER), JoH.tsl() - Constants.DAY_IN_MS * 7);
        final List<StepCounter> readings = StepCounter.latestForGraph((MAX_ACTIVITY_RECORDS / Math.min(1, Math.max(activityErrorCount, MAX_ACTIVITY_RECORDS / 10))), syncedTillTime);
        final JSONArray data = new JSONArray();
        // final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
        // format.setTimeZone(TimeZone.getDefault());
        long highest_timestamp = 0;
        if (readings.size() > 0) {
            for (StepCounter reading : readings) {
                final JSONObject json = new JSONObject();
                json.put("type", "steps-total");
                json.put("timeStamp", reading.timestamp);
                // json.put("dateString", format.format(reading.timestamp));
                json.put("created_at", DateUtil.toISOString(reading.timestamp));
                json.put("steps", reading.metric);
                data.put(json);
                highest_timestamp = Math.max(highest_timestamp, reading.timestamp);
            }
            // send to nightscout - update counter
            final RequestBody body = RequestBody.create(MediaType.parse("application/json"), data.toString());
            Response<ResponseBody> r;
            r = nightscoutService.uploadActivity(apiSecret, body).execute();
            if (!r.isSuccess()) {
                activityErrorCount++;
                UserError.Log.e(TAG, "Unable to upload steps data to Nightscout - check nightscout version");
                throw new UploaderException(r.message(), r.code());
            } else {
                PersistentStore.setLong(STORE_COUNTER, highest_timestamp);
                UserError.Log.e(TAG, "Updating steps synced record count (success) " + JoH.dateTimeText(highest_timestamp) + " Processed: " + readings.size() + " records");
                checkGzipSupport(r);
            }
        }
    } else {
        UserError.Log.e(TAG, "Api secret is null");
    }
}
Also used : StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) RequestBody(com.squareup.okhttp.RequestBody) ResponseBody(com.squareup.okhttp.ResponseBody)

Aggregations

StepCounter (com.eveningoutpost.dexdrip.Models.StepCounter)12 HeartRate (com.eveningoutpost.dexdrip.Models.HeartRate)4 Context (android.content.Context)2 PolyTrendLine (com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine)2 TrendLine (com.eveningoutpost.dexdrip.Models.Forecast.TrendLine)2 PebbleKit (com.getpebble.android.kit.PebbleKit)2 PebbleDictionary (com.getpebble.android.kit.util.PebbleDictionary)2 DataMap (com.google.android.gms.wearable.DataMap)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 RequestBody (com.squareup.okhttp.RequestBody)2 ResponseBody (com.squareup.okhttp.ResponseBody)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 Line (lecho.lib.hellocharts.model.Line)2 PointValue (lecho.lib.hellocharts.model.PointValue)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2