Java Code Examples for com.eveningoutpost.dexdrip.Models.BgReading#bgReadingInsertFromG5()

The following examples show how to use com.eveningoutpost.dexdrip.Models.BgReading#bgReadingInsertFromG5() . 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: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void processBacksies(List<BackFillStream.Backsie> backsies) {
    boolean changed = false;
    for (BackFillStream.Backsie backsie : backsies) {
        final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime());

        final long since = JoH.msSince(time);
        if ((since > HOUR_IN_MS * 6) || (since < 0)) {
            UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)");
        } else {
            if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) {
                final BgReading bgr = BgReading.bgReadingInsertFromG5(backsie.getGlucose(), time, "Backfill");
                lastGlucoseBgReading = bgr;
                UserError.Log.d(TAG, "Adding backfilled reading: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
                changed = true;
            }
            UserError.Log.d(TAG, "Backsie: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
        }
    }
    if (changed) {
        updateStreamedTillTimeForBackfill();
    }
}
 
Example 2
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void processBacksies(List<BackFillStream.Backsie> backsies) {
    boolean changed = false;
    for (BackFillStream.Backsie backsie : backsies) {
        final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime());

        final long since = JoH.msSince(time);
        if ((since > HOUR_IN_MS * 6) || (since < 0)) {
            UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)");
        } else {
            if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) {
                final BgReading bgr = BgReading.bgReadingInsertFromG5(backsie.getGlucose(), time, "Backfill");
                lastGlucoseBgReading = bgr;
                UserError.Log.d(TAG, "Adding backfilled reading: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
                changed = true;
            }
            UserError.Log.d(TAG, "Backsie: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
        }
    }
    if (changed) {
        updateStreamedTillTimeForBackfill();
    }
}
 
Example 3
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void processBacksies(List<BackFillStream.Backsie> backsies) {
    boolean changed = false;
    for (BackFillStream.Backsie backsie : backsies) {
        final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime());

        final long since = JoH.msSince(time);
        if ((since > HOUR_IN_MS * 6) || (since < 0)) {
            UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)");
        } else {
            if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) {
                final BgReading bgr = BgReading.bgReadingInsertFromG5(backsie.getGlucose(), time, "Backfill");
                lastGlucoseBgReading = bgr;
                UserError.Log.d(TAG, "Adding backfilled reading: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
                changed = true;
            }
            UserError.Log.d(TAG, "Backsie: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
        }
    }
    if (changed) {
        updateStreamedTillTimeForBackfill();
    }
}
 
Example 4
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void processBacksies(List<BackFillStream.Backsie> backsies) {
    boolean changed = false;
    for (BackFillStream.Backsie backsie : backsies) {
        final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime());

        final long since = JoH.msSince(time);
        if ((since > HOUR_IN_MS * 6) || (since < 0)) {
            UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)");
        } else {
            if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) {
                final BgReading bgr = BgReading.bgReadingInsertFromG5(backsie.getGlucose(), time, "Backfill");
                lastGlucoseBgReading = bgr;
                UserError.Log.d(TAG, "Adding backfilled reading: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
                changed = true;
            }
            UserError.Log.d(TAG, "Backsie: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
        }
    }
    if (changed) {
        updateStreamedTillTimeForBackfill();
    }
}
 
Example 5
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final BaseGlucoseRxMessage glucose) {
    if (glucose == null) return;
    lastGlucosePacket = tsl();
    DexTimeKeeper.updateAge(getTransmitterID(), glucose.timestamp);
    if (glucose.usable() || (glucose.insufficient() && Pref.getBoolean("ob1_g5_use_insufficiently_calibrated", true))) {
        UserError.Log.d(TAG, "Got usable glucose data from G5!!");
        final BgReading bgReading = BgReading.bgReadingInsertFromG5(glucose.glucose, tsl());
        if (bgReading != null) {
            try {
                bgReading.calculated_value_slope = glucose.getTrend() / Constants.MINUTE_IN_MS; // note this is different to the typical calculated slope, (normally delta)
                if (bgReading.calculated_value_slope == Double.NaN) {
                    bgReading.hide_slope = true;
                }
            } catch (Exception e) {
                // not a good number - does this exception ever actually fire?
            }
            if (!FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) {
                bgReading.noRawWillBeAvailable();
            }
            if (glucose.insufficient()) {
                bgReading.appendSourceInfo("Insufficient").save();
            }
        } else {
            UserError.Log.wtf(TAG, "New BgReading was null in processGlucoseRxMessage!");
        }
        lastGlucoseBgReading = bgReading;
        lastUsableGlucosePacket = lastGlucosePacket;
        parent.lastUsableGlucosePacketTime = lastUsableGlucosePacket;
        if (glucose.getPredictedGlucose() != null) {
            // not really supported on wear yet
            if (!android_wear) {
                Prediction.create(tsl(), glucose.getPredictedGlucose(), "EGlucoseRx").save();
            }
        }

        if (android_wear && wear_broadcast && bgReading != null) {
            // emit local broadcast
            BroadcastGlucose.sendLocalBroadcast(bgReading);
        }

        if (WholeHouse.isLive()) {
            Mimeograph.poll(false);
        }

    } else {
        // TODO this is duplicated in processCalibrationState()
        if (glucose.calibrationState().sensorFailed()) {
            if (JoH.pratelimit("G5 Sensor Failed", 3600 * 3)) {
                JoH.showNotification(devName() + " SENSOR FAILED", "Sensor reporting failed", null, Constants.G5_SENSOR_ERROR, true, true, false);
            }
        }
    }
}
 
Example 6
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final BaseGlucoseRxMessage glucose) {
    if (glucose == null) return;
    lastGlucosePacket = tsl();
    DexTimeKeeper.updateAge(getTransmitterID(), glucose.timestamp);
    if (glucose.usable() || (glucose.insufficient() && Pref.getBoolean("ob1_g5_use_insufficiently_calibrated", true))) {
        UserError.Log.d(TAG, "Got usable glucose data from G5!!");
        final BgReading bgReading = BgReading.bgReadingInsertFromG5(glucose.glucose, tsl());
        if (bgReading != null) {
            try {
                bgReading.calculated_value_slope = glucose.getTrend() / Constants.MINUTE_IN_MS; // note this is different to the typical calculated slope, (normally delta)
                if (bgReading.calculated_value_slope == Double.NaN) {
                    bgReading.hide_slope = true;
                }
            } catch (Exception e) {
                // not a good number - does this exception ever actually fire?
            }
            if (!FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) {
                bgReading.noRawWillBeAvailable();
            }
            if (glucose.insufficient()) {
                bgReading.appendSourceInfo("Insufficient").save();
            }
        } else {
            UserError.Log.wtf(TAG, "New BgReading was null in processGlucoseRxMessage!");
        }
        lastGlucoseBgReading = bgReading;
        lastUsableGlucosePacket = lastGlucosePacket;
        parent.lastUsableGlucosePacketTime = lastUsableGlucosePacket;
        if (glucose.getPredictedGlucose() != null) {
            // not really supported on wear yet
            if (!android_wear) {
                Prediction.create(tsl(), glucose.getPredictedGlucose(), "EGlucoseRx").save();
            }
        }

        if (android_wear && wear_broadcast && bgReading != null) {
            // emit local broadcast
            BroadcastGlucose.sendLocalBroadcast(bgReading);
        }

        if (WholeHouse.isLive()) {
            Mimeograph.poll(false);
        }

    } else {
        // TODO this is duplicated in processCalibrationState()
        if (glucose.calibrationState().sensorFailed()) {
            if (JoH.pratelimit("G5 Sensor Failed", 3600 * 3)) {
                JoH.showNotification(devName() + " SENSOR FAILED", "Sensor reporting failed", null, Constants.G5_SENSOR_ERROR, true, true, false);
            }
        }
    }
}
 
Example 7
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final BaseGlucoseRxMessage glucose) {
    if (glucose == null) return;
    lastGlucosePacket = tsl();
    DexTimeKeeper.updateAge(getTransmitterID(), glucose.timestamp);
    if (glucose.usable() || (glucose.insufficient() && Pref.getBoolean("ob1_g5_use_insufficiently_calibrated", true))) {
        UserError.Log.d(TAG, "Got usable glucose data from G5!!");
        final BgReading bgReading = BgReading.bgReadingInsertFromG5(glucose.glucose, tsl());
        if (bgReading != null) {
            try {
                bgReading.calculated_value_slope = glucose.getTrend() / Constants.MINUTE_IN_MS; // note this is different to the typical calculated slope, (normally delta)
                if (bgReading.calculated_value_slope == Double.NaN) {
                    bgReading.hide_slope = true;
                }
            } catch (Exception e) {
                // not a good number - does this exception ever actually fire?
            }
            if (!FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) {
                bgReading.noRawWillBeAvailable();
            }
            if (glucose.insufficient()) {
                bgReading.appendSourceInfo("Insufficient").save();
            }
        } else {
            UserError.Log.wtf(TAG, "New BgReading was null in processGlucoseRxMessage!");
        }
        lastGlucoseBgReading = bgReading;
        lastUsableGlucosePacket = lastGlucosePacket;
        parent.lastUsableGlucosePacketTime = lastUsableGlucosePacket;
        if (glucose.getPredictedGlucose() != null) {
            // not really supported on wear yet
            if (!android_wear) {
                Prediction.create(tsl(), glucose.getPredictedGlucose(), "EGlucoseRx").save();
            }
        }

        if (android_wear && wear_broadcast && bgReading != null) {
            // emit local broadcast
            BroadcastGlucose.sendLocalBroadcast(bgReading);
        }

        if (WholeHouse.isLive()) {
            Mimeograph.poll(false);
        }

    } else {
        // TODO this is duplicated in processCalibrationState()
        if (glucose.calibrationState().sensorFailed()) {
            if (JoH.pratelimit("G5 Sensor Failed", 3600 * 3)) {
                JoH.showNotification(devName() + " SENSOR FAILED", "Sensor reporting failed", null, Constants.G5_SENSOR_ERROR, true, true, false);
            }
        }
    }
}
 
Example 8
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final BaseGlucoseRxMessage glucose) {
    if (glucose == null) return;
    lastGlucosePacket = tsl();
    DexTimeKeeper.updateAge(getTransmitterID(), glucose.timestamp);
    if (glucose.usable() || (glucose.insufficient() && Pref.getBoolean("ob1_g5_use_insufficiently_calibrated", true))) {
        UserError.Log.d(TAG, "Got usable glucose data from G5!!");
        final BgReading bgReading = BgReading.bgReadingInsertFromG5(glucose.glucose, tsl());
        if (bgReading != null) {
            try {
                bgReading.calculated_value_slope = glucose.getTrend() / Constants.MINUTE_IN_MS; // note this is different to the typical calculated slope, (normally delta)
                if (bgReading.calculated_value_slope == Double.NaN) {
                    bgReading.hide_slope = true;
                }
            } catch (Exception e) {
                // not a good number - does this exception ever actually fire?
            }
            if (!FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) {
                bgReading.noRawWillBeAvailable();
            }
            if (glucose.insufficient()) {
                bgReading.appendSourceInfo("Insufficient").save();
            }
        } else {
            UserError.Log.wtf(TAG, "New BgReading was null in processGlucoseRxMessage!");
        }
        lastGlucoseBgReading = bgReading;
        lastUsableGlucosePacket = lastGlucosePacket;
        parent.lastUsableGlucosePacketTime = lastUsableGlucosePacket;
        if (glucose.getPredictedGlucose() != null) {
            // not really supported on wear yet
            if (!android_wear) {
                Prediction.create(tsl(), glucose.getPredictedGlucose(), "EGlucoseRx").save();
            }
        }

        if (android_wear && wear_broadcast && bgReading != null) {
            // emit local broadcast
            BroadcastGlucose.sendLocalBroadcast(bgReading);
        }

        if (WholeHouse.isLive()) {
            Mimeograph.poll(false);
        }

    } else {
        // TODO this is duplicated in processCalibrationState()
        if (glucose.calibrationState().sensorFailed()) {
            if (JoH.pratelimit("G5 Sensor Failed", 3600 * 3)) {
                JoH.showNotification(devName() + " SENSOR FAILED", "Sensor reporting failed", null, Constants.G5_SENSOR_ERROR, true, true, false);
            }
        }
    }
}