com.eveningoutpost.dexdrip.Models.BgReading Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.Models.BgReading. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XbridgePlus.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void process15minData(byte[] buffer, int src_offset, int min_offset, int count) {
    long timestamp = JoH.tsl();
    for (int i = src_offset; i < (src_offset + (count * 2)); i = i + 2) {
        double val = LIBRE_MULTIPLIER * (unsignedBytesToInt(buffer[i], buffer[i + 1]) & 0xFFF);
        UserError.Log.d(TAG, "Received 15 min value: " + JoH.qs(val, 4) + " for minute: " + min_offset);

        final long this_timestamp = timestamp - (min_offset * Constants.MINUTE_IN_MS);
        // TODO we may want to use getForPreciseTimestamp instead..
        if (BgReading.readingNearTimeStamp(this_timestamp) == null) {
            UserError.Log.d(TAG, "Creating a new reading at: " + JoH.dateTimeText(this_timestamp));
            BgReading.create(val, val, xdrip.getAppContext(), this_timestamp, min_offset != 0);
        } else {
            UserError.Log.d(TAG, "Already a reading for minute offset: " + min_offset);
        }

        min_offset++;
    }
}
 
Example #2
Source File: BgGraphBuilder.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public BgGraphBuilder(Context context, long start, long end, int numValues){
    end_time = end;
    start_time = start;
    bgReadings = BgReading.latestForGraph( numValues, start, end);
    calibrations = Calibration.latestForGraph( numValues, start, end);
    this.context = context;
    this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
    this.highMark = Double.parseDouble(prefs.getString("highValue", "170"));
    this.lowMark = Double.parseDouble(prefs.getString("lowValue", "70"));
    this.doMgdl = (prefs.getString("units", "mgdl").equals("mgdl"));
    defaultMinY = unitized(40);
    defaultMaxY = unitized(250);
    pointSize = isXLargeTablet(context) ? 5 : 3;
    axisTextSize = isXLargeTablet(context) ? 20 : Axis.DEFAULT_TEXT_SIZE_SP;
    previewAxisTextSize = isXLargeTablet(context) ? 12 : 5;
    hoursPreviewStep = isXLargeTablet(context) ? 2 : 1;
}
 
Example #3
Source File: GcmActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void requestBGsync() {
    if (token != null) {
        if ((JoH.tsl() - last_sync_request) > (60 * 1000 * (5 + bg_sync_backoff))) {
            last_sync_request = JoH.tsl();
            final BgReading bgReading = BgReading.last();
            if (JoH.pratelimit("gcm-bfr", 299)) {
                GcmActivity.sendMessage("bfr", bgReading != null ? "" + bgReading.timestamp : "");
            }
            bg_sync_backoff++;
        } else {
            Log.d(TAG, "Already requested BGsync recently, backoff: " + bg_sync_backoff);
            if (JoH.ratelimit("check-queue", 20)) {
                queueCheckOld(xdrip.getAppContext());
            }
        }
    } else {
        Log.d(TAG, "No token for BGSync");
    }
}
 
Example #4
Source File: NewDataObserver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void newBgReading(BgReading bgReading, boolean is_follower) {

        sendToPebble();
        sendToWear();
        sendToAmazfit();
        sendToLeFun();
        sendToMiBand();
        sendToBlueJay();
        sendToRemoteBlueJay();
        Notifications.start();
        uploadToShare(bgReading, is_follower);
        textToSpeech(bgReading, null);
        LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value);
        LockScreenWallPaper.setIfEnabled();
        TidepoolEntry.newData();

    }
 
Example #5
Source File: NightscoutUploader.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public static double getNightscoutRaw(BgReading bgReading, Calibration cal) {
    double slope = 0, intercept = 0, scale = 0, filtered = 0, unfiltered = 0, nightscoutRaw = 0;
    if (cal != null){
        // slope/intercept/scale like uploaded to NightScout (NightScoutUploader.java)
        slope = getNightscoutSlope(cal);
        intercept = getNightscoutIntercept(cal);
        scale = getNightscoutScale(cal);
        unfiltered= bgReading.usedRaw()*1000;
        filtered = bgReading.ageAdjustedFiltered()*1000;
    }
    //nightscoutRaw logic from https://github.com/nightscout/cgm-remote-monitor/blob/master/lib/plugins/rawbg.js#L59
    if (slope != 0 && intercept != 0 && scale != 0) {
        if (filtered == 0 || bgReading.calculated_value < 40) {
            nightscoutRaw = scale * (unfiltered - intercept) / slope;
        } else {
            double ratio = scale * (filtered - intercept) / slope / bgReading.calculated_value;
            nightscoutRaw = scale * (unfiltered - intercept) / slope / ratio;
        }
    }
    return nightscoutRaw;
}
 
Example #6
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void resendData(long since) {
    Log.d(TAG, "resendData ENTER");
    forceGoogleApiConnect();
    final long startTime = since == 0 ? new Date().getTime() - (60000 * 60 * 24) : since;
    Log.d(TAG, "resendData googleApiClient connected ENTER, sending since: " + JoH.dateTimeText(startTime));
    final BgReading last_bg = BgReading.last();
    if (last_bg != null) {
        List<BgReading> graph_bgs = BgReading.latestForGraph(60, startTime);
        BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getApplicationContext());
        if (!graph_bgs.isEmpty()) {
            final int battery = PowerStateReceiver.getBatteryLevel(getApplicationContext());
            DataMap entries = dataMap(last_bg, mPrefs, bgGraphBuilder, battery);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
            for (BgReading bg : graph_bgs) {
                dataMaps.add(dataMap(bg, mPrefs, bgGraphBuilder, battery));
            }
            entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putDataMapArrayList("entries", dataMaps);
            if (mPrefs.getBoolean("extra_status_line", false)) {
                entries.putString("extra_status_line", StatusLine.extraStatusLine());
            }

            new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
        }
    }
}
 
Example #7
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
        Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
        return;
    }


    //sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
    sensor.latest_battery_level = transmitterData.sensor_battery_level; // allow level to go up and down
    sensor.save();

    last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
 
Example #8
Source File: NSEmulatorReceiver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static BgReading bgReadingInsertFromData(long timestamp, double sgv, double slope, boolean do_notification) {
    Log.d(TAG, "bgReadingInsertFromData called timestamp = " + timestamp + " bg = " + sgv + " time =" + JoH.dateTimeText(timestamp));
    final JSONObject faux_bgr = new JSONObject();
    try {
        faux_bgr.put("timestamp", timestamp);
        faux_bgr.put("calculated_value", sgv);
        faux_bgr.put("filtered_calculated_value", sgv);
        faux_bgr.put("calculated_value_slope", slope);
        // sanity checking???
        // fake up some extra data
        faux_bgr.put("raw_data", sgv);
        faux_bgr.put("age_adjusted_raw_value", sgv);
        faux_bgr.put("filtered_data", sgv);

        faux_bgr.put("uuid", UUID.randomUUID().toString());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        UserError.Log.e(TAG, "bgReadingInsertFromData Got JSON exception: " + e);
        return null;
    }

    Log.d(TAG, "Received NSEmulator SGV: " + faux_bgr);
    return bgReadingInsertFromJson(faux_bgr.toString(), do_notification, true); // notify and force sensor
}
 
Example #9
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public void setRetryTimer() {
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        BgReading bgReading = BgReading.last();
        long retry_in;
        if (bgReading != null) {
            retry_in = Math.min(Math.max((1000 * 30), (1000 * 60 * 5) - (new Date().getTime() - bgReading.timestamp) + (1000 * 5)), (1000 * 60 * 5));
        } else {
            retry_in = (1000 * 20);
        }
        Log.d(TAG, "Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    }
}
 
Example #10
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public BgGraphBuilder(Context context, long start, long end, int numValues){
    end_time = end;
    start_time = start;
    bgReadings = BgReading.latestForGraph( numValues, start, end);
    calibrations = Calibration.latestForGraph( numValues, start, end);
    this.context = context;
    this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
    this.highMark = Double.parseDouble(prefs.getString("highValue", "170"));
    this.lowMark = Double.parseDouble(prefs.getString("lowValue", "70"));
    this.doMgdl = (prefs.getString("units", "mgdl").equals("mgdl"));
    defaultMinY = unitized(40);
    defaultMaxY = unitized(250);
    pointSize = isXLargeTablet(context) ? 5 : 3;
    axisTextSize = isXLargeTablet(context) ? 20 : Axis.DEFAULT_TEXT_SIZE_SP;
    previewAxisTextSize = isXLargeTablet(context) ? 12 : 5;
    hoursPreviewStep = isXLargeTablet(context) ? 2 : 1;
}
 
Example #11
Source File: NewDataObserver.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void newBgReading(BgReading bgReading, boolean is_follower) {

        sendToPebble();
        sendToWear();
        sendToAmazfit();
        sendToLeFun();
        sendToMiBand();
        sendToBlueJay();
        sendToRemoteBlueJay();
        Notifications.start();
        uploadToShare(bgReading, is_follower);
        textToSpeech(bgReading, null);
        LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value);
        LockScreenWallPaper.setIfEnabled();
        TidepoolEntry.newData();

    }
 
Example #12
Source File: DBSearchUtil.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static int noReadingsBelowRange(Context context) {
    Bounds bounds = new Bounds().invoke();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        low *= Constants.MMOLL_TO_MGDL;

    }
    int count = new Select()
            .from(BgReading.class)
            .where("timestamp >= " + bounds.start)
            .where("timestamp <= " + bounds.stop)
            .where("calculated_value > " + CUTOFF)
            .where("calculated_value < " + low)
            .where("snyced == 0")
            .count();
    Log.d("DrawStats", "Low count: " + count);

    return count;
}
 
Example #13
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
        Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
        return;
    }


    //sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
    sensor.latest_battery_level = transmitterData.sensor_battery_level; // allow level to go up and down
    sensor.save();

    last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
 
Example #14
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static synchronized double getCurrentLowOccursAt() {
    try {
        final long last_bg_reading_timestamp = BgReading.last().timestamp;
        // TODO remove any duplication by using refreshNoiseIfOlderThan()
        if (low_occurs_at_processed_till_timestamp < last_bg_reading_timestamp) {
            Log.d(TAG, "Recalculating lowOccursAt: " + JoH.dateTimeText((long) low_occurs_at_processed_till_timestamp) + " vs " + JoH.dateTimeText(last_bg_reading_timestamp));
            // new only the last hour worth of data for this
            (new BgGraphBuilder(xdrip.getAppContext(), System.currentTimeMillis() - 60 * 60 * 1000, System.currentTimeMillis() + 5 * 60 * 1000, 24, true)).addBgReadingValues(false);
        } else {
            Log.d(TAG, "Cached current low timestamp ok: " +  JoH.dateTimeText((long) low_occurs_at_processed_till_timestamp) + " vs " + JoH.dateTimeText(last_bg_reading_timestamp));
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception in getCurrentLowOccursAt() " + e);
    }
    return low_occurs_at;
}
 
Example #15
Source File: WixelReader.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void setSerialDataToTransmitterRawData(int raw_data, int filtered_data, int sensor_battery_leve, Long CaptureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_leve, CaptureTime);
        if (transmitterData != null) {
            final Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                BgReading bgReading = BgReading.create(transmitterData.raw_data, filtered_data, null, CaptureTime);

                //sensor.latest_battery_level = (sensor.latest_battery_level!=0)?Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level):transmitterData.sensor_battery_level;
                sensor.latest_battery_level = transmitterData.sensor_battery_level; // don't lock it only going downwards
                sensor.save();
            } else {
                Log.d(TAG, "No Active Sensor, Data only stored in Transmitter Data");
            }
        }
    }
 
Example #16
Source File: NSEmulatorReceiverTest.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void bgReadingInsertFromDataTest() throws JSONException {

    // test data courtesy of philipgo - thanks
    final JSONObject json_object = new JSONObject();
    json_object.put("date", 1526717691000.0);
    json_object.put("sgv", 148);
    json_object.put("direction", "SingleUp");

    final BgReading result = NSEmulatorReceiver.bgReadingInsertFromData(json_object.getLong("date"),
            json_object.getDouble("sgv"),
            BgReading.slopefromName(json_object.getString("direction")),
            true);

    assertWithMessage("result not null").that(result).isNotNull();
    assertWithMessage("direction matches").that(result.slopeName()).isEqualTo("SingleUp");
    assertWithMessage("timestamp matches").that(result.timestamp).isEqualTo(1526717691000L);
    assertWithMessage("sgv matches 1").that(result.calculated_value).isEqualTo(148d);
    assertWithMessage("sgv matches 2").that(result.filtered_calculated_value).isEqualTo(148d);
    assertWithMessage("sgv matches 3").that(result.raw_data).isEqualTo(148d);
    assertWithMessage("sgv matches 4").that(result.filtered_data).isEqualTo(148d);

    //System.out.println(result.toJSON(true));
    //System.out.println(result.slopeName());

}
 
Example #17
Source File: FakeNumbers.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addListenerOnButton() {

        button = (Button)findViewById(R.id.log);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                EditText value = (EditText) findViewById(R.id.bg_value);
                int intValue = Integer.parseInt(value.getText().toString());

                BgReading bgReading = BgReading.create(intValue * 1000, getApplicationContext(), new Date().getTime());
                Intent intent = new Intent(getApplicationContext(), Home.class);
                startActivity(intent);
                finish();
            }

        });
    }
 
Example #18
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void addBgReadingValues() {
    final boolean show_filtered = prefs.getBoolean("show_filtered_curve", false);

    for (BgReading bgReading : bgReadings) {
        if (bgReading.raw_calculated != 0 && prefs.getBoolean("interpret_raw", false)) {
            rawInterpretedValues.add(new PointValueExtended((float) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.raw_calculated),(float) unitized(bgReading.filtered_calculated_value)));
        } else if (bgReading.calculated_value >= 400) {
            highValues.add(new PointValueExtended((float) (bgReading.timestamp / FUZZER), (float) unitized(400),(float) unitized(bgReading.filtered_calculated_value)));
        } else if (unitized(bgReading.calculated_value) >= highMark) {
            highValues.add(new PointValueExtended((float) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value), (float) unitized(bgReading.filtered_calculated_value)));
        } else if (unitized(bgReading.calculated_value) >= lowMark) {
            inRangeValues.add(new PointValueExtended((float) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value), (float) unitized(bgReading.filtered_calculated_value)));
        } else if (bgReading.calculated_value >= 40) {
            lowValues.add(new PointValueExtended((float) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value),(float) unitized(bgReading.filtered_calculated_value)));
        } else if (bgReading.calculated_value > 13) {
            lowValues.add(new PointValueExtended((float) (bgReading.timestamp / FUZZER), (float) unitized(40), (float) unitized(bgReading.filtered_calculated_value)));
        }

        if ((show_filtered) && (bgReading.filtered_calculated_value > 0) && (bgReading.filtered_calculated_value != bgReading.calculated_value)) {
            filteredValues.add(new PointValueExtended((float) ((bgReading.timestamp - timeshift) / FUZZER), (float) unitized(bgReading.filtered_calculated_value)));
        }
    }
    for (Calibration calibration : calibrations) {
        calibrationValues.add(new PointValueExtended((float) (calibration.timestamp / FUZZER), (float) unitized(calibration.bg)));
    }
}
 
Example #19
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean sendWearUpload(List<BgReading> bgs, List<Calibration> cals, List<BloodTest> bts, List<Treatments> treatsAdd, List<String> treatsDel) {
    boolean statusCals = sendWearCalibrationData(0, 0, cals);
    boolean statusBgs = sendWearBgData(0, 0, bgs);
    boolean statusBts = sendWearBloodTestData(0, 0, bts);
    boolean statusTreats = sendWearTreatmentsData(0, 0, treatsAdd);
    boolean statusTreatsDel = sendWearTreatmentsDataDelete(treatsDel);
    return (statusCals && statusBts && statusTreats && statusTreatsDel && statusBgs);
}
 
Example #20
Source File: GcmActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
static void processBFPbundle(String bundle) {
    String[] bundlea = bundle.split("\\^");
    for (String bgr : bundlea) {
        BgReading.bgReadingInsertFromJson(bgr, false);
    }
    GcmActivity.requestSensorBatteryUpdate();
    Home.staticRefreshBGCharts();
}
 
Example #21
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized DataMap getWearBgReadingData(int count, long last_send_time, int min_count) {
    forceGoogleApiConnect();

    Log.d(TAG, "getWearBgReadingData last_send_time:" + JoH.dateTimeText(last_send_time));

    BgReading last_bg = BgReading.last();
    if (last_bg != null) {
        Log.d(TAG, "getWearBgReadingData last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
    }

    if (last_bg != null && last_send_time <= last_bg.timestamp) {//startTime
        long last_send_success = last_send_time;
        Log.d(TAG, "getWearBgData last_send_time < last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
        final List<BgReading> graph_bgs = BgReading.latestForGraphAsc(count, last_send_time);
        if (!graph_bgs.isEmpty() && graph_bgs.size() > min_count) {
            //Log.d(TAG, "getWearBgData count = " + graph_bgs.size());
            final DataMap entries = dataMap(last_bg);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
            for (BgReading bg : graph_bgs) {
                dataMaps.add(dataMap(bg));
                last_send_success = bg.timestamp;
                //Log.d(TAG, "getWearBgData bg getId:" + bg.getId() + " raw_data:" + bg.raw_data + " filtered_data:" + bg.filtered_data + " timestamp:" + bg.timestamp + " uuid:" + bg.uuid);
            }
            entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putDataMapArrayList("entries", dataMaps);
            Log.i(TAG, "getWearBgReadingData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = " + graph_bgs.size());
            return entries;
        } else
            Log.i(TAG, "getWearBgReading SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = 0");
    }
    return null;
}
 
Example #22
Source File: NewDataObserver.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void textToSpeech(BgReading bgReading, BestGlucose.DisplayGlucose dg) {
    //Text to speech
    if (Pref.getBooleanDefaultFalse("bg_to_speech") || VehicleMode.shouldSpeak()) {
        if (dg == null) dg = BestGlucose.getDisplayGlucose();
        if (dg != null) {
            BgToSpeech.speak(dg.mgdl, dg.timestamp, dg.delta_name);
        } else {
            BgToSpeech.speak(bgReading.calculated_value, bgReading.timestamp, bgReading.slopeName());
        }
    }
}
 
Example #23
Source File: LibreTrendGraph.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static ArrayList<Float> getLatestBgForXMinutes(int NumberOfMinutes) {

        Log.i(TAG, "getLatestBgForXMinutes number of minutes = " + NumberOfMinutes);
        
        List<LibreTrendPoint> LibreTrendPoints = LibreTrendUtil.getInstance().getData(JoH.tsl() - NumberOfMinutes * 60 * 1000, JoH.tsl());
        if(LibreTrendPoints == null || LibreTrendPoints.size() == 0) {
            Log.e(TAG, "Error getting data from getLatestBgForXMinutes");
            return null;
        }
        
        LibreTrendLatest libreTrendLatest = LibreTrendUtil.getInstance().getLibreTrendLatest();
        if(libreTrendLatest.glucoseLevelRaw == 0) {
            Log.e(TAG, "libreBlock exists but libreTrendLatest.glucoseLevelRaw is zero ");
            return null;
        }
        ArrayList<Float> ret = new ArrayList<Float>();
        
        double factor = libreTrendLatest.bg / libreTrendLatest.glucoseLevelRaw;
        if(factor == 0) {
            // We don't have the calculated value, but we do have the raw value. (No calibration exists)
            // I want to show raw data.
            Log.w(TAG, "Bg data was not calculated, working on raw data");
            List<BgReading> latestReading = BgReading.latestForGraph (1, libreTrendLatest.timestamp - 1000, libreTrendLatest.timestamp + 1000);
            if(latestReading == null || latestReading.size() == 0) {
                Log.e(TAG, "libreBlock exists but no matching bg record exists");
                return null;
            }
            
            factor = latestReading.get(0).raw_data / libreTrendLatest.glucoseLevelRaw;
        }
        
        int count = 0;
        for(int i = libreTrendLatest.id ; i >= 0 && count < NumberOfMinutes; i--) {
            count ++;
            ret.add(new Float(factor * LibreTrendPoints.get(i).rawSensorValue));
        }
            
        return ret;

    }
 
Example #24
Source File: BgReadingTable.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void bindView(View view, Context context, BgReading bgReading) {
    final BgReadingCursorAdapterViewHolder tag = (BgReadingCursorAdapterViewHolder) view.getTag();
    tag.raw_data_id.setText(Double.toString(bgReading.calculated_value));
    tag.raw_data_value.setText(Double.toString(bgReading.age_adjusted_raw_value));
    tag.raw_data_slope.setText(Double.toString(bgReading.raw_data));
    tag.raw_data_timestamp.setText(new Date(bgReading.timestamp).toString());
}
 
Example #25
Source File: ESensorGlucose.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
static boolean isBgReadingValid(final BgReading bgReading) {
    if(bgReading.calculated_value >= 39 && bgReading.calculated_value <= 500) {
        return true;
    }
    UserError.Log.e(TAG, "Ignoring invalid bg " + bgReading.toS());
    return false;
}
 
Example #26
Source File: NightscoutUploader.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public boolean uploadMongo(List<BgReading> glucoseDataSets, List<Calibration> meterRecords, List<Calibration> calRecords, List<TransmitterData> transmittersData, List<LibreBlock> libreBlock) {
    boolean mongoStatus = false;


    if (enableMongoUpload) {
        double start = new Date().getTime();
        mongoStatus = doMongoUpload(prefs, glucoseDataSets, meterRecords, calRecords, transmittersData, libreBlock);
        Log.i(TAG, String.format("Finished upload of %s record using a Mongo in %s ms result: %b", 
                glucoseDataSets.size() + meterRecords.size() + calRecords.size() + transmittersData.size() + libreBlock.size(), System.currentTimeMillis() - start, mongoStatus));
    }

    return mongoStatus;
}
 
Example #27
Source File: Ob1G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void estimateAnticipateFromLinkedData() {
    final BgReading bg = BgReading.last();
    if (bg != null && bg.timestamp > static_last_connected && JoH.msSince(bg.timestamp) < HOUR_IN_MS * 3) {
        final long ts = bg.timestamp - Constants.SECOND_IN_MS;
        UserError.Log.d(TAG, "Updating Sync Keeper with network learned timestamp: " + JoH.dateTimeText(ts));
        DexSyncKeeper.store(transmitterID, ts);
    }
}
 
Example #28
Source File: BgSendQueue.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void resendData(Context context, int battery) {//KS
    Log.d("BgSendQueue", "resendData enter battery=" + battery);
    long startTime = new Date().getTime() - (60000 * 60 * 24);
    Intent messageIntent = new Intent();
    messageIntent.setAction(Intent.ACTION_SEND);
    messageIntent.putExtra("message", "ACTION_G5BG");

    BgReading last_bg = BgReading.last();
    if (last_bg != null) {
        Log.d("BgSendQueue", "resendData last_bg.timestamp:" +  JoH.dateTimeText(last_bg.timestamp));
    }

    List<BgReading> graph_bgs = BgReading.latestForGraph(60, startTime);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context.getApplicationContext());
    if (!graph_bgs.isEmpty()) {
        Log.d("BgSendQueue", "resendData graph_bgs size=" + graph_bgs.size());
        final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        DataMap entries = dataMap(last_bg, sharedPrefs, bgGraphBuilder, context, battery);
        for (BgReading bg : graph_bgs) {
            dataMaps.add(dataMap(bg, sharedPrefs, bgGraphBuilder, context, battery));
        }
        entries.putDataMapArrayList("entries", dataMaps);
        if (sharedPrefs.getBoolean("extra_status_line", false)) {
            //messageIntent.putExtra("extra_status_line", extraStatusLine(sharedPrefs));
            entries.putString("extra_status_line", extraStatusLine(sharedPrefs));
        }
        Log.d("BgSendQueue", "resendData entries=" + entries);
        messageIntent.putExtra("data", entries.toBundle());

        DataMap stepsDataMap = getSensorSteps(sharedPrefs);
        if (stepsDataMap != null) {
            messageIntent.putExtra("steps", stepsDataMap.toBundle());
        }
        LocalBroadcastManager.getInstance(context).sendBroadcast(messageIntent);
    }
}
 
Example #29
Source File: ESensorGlucose.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
static List<ESensorGlucose> fromBgReadings(final List<BgReading> bgReadingList) {
    if (bgReadingList == null) return null;
    final List<ESensorGlucose> results = new LinkedList<>();
    for (BgReading bgReading : bgReadingList) {
        if(isBgReadingValid(bgReading)) {
            results.add(fromBgReading(bgReading));
        }
    }
    return results;
}
 
Example #30
Source File: Experience.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean gotData() {
    if (got_data) return true;
    if (BgReading.last(true) != null) {
        got_data = true;
        return true;
    } else {
        return false;
    }
}