Java Code Examples for com.eveningoutpost.dexdrip.Models.Calibration#latestValid()

The following examples show how to use com.eveningoutpost.dexdrip.Models.Calibration#latestValid() . 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: XDripOriginal.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    CalibrationData cd = loadDataFromCache(TAG);
    if (cd == null) {
        UserError.Log.d(TAG, "Regenerating Calibration data cache");
        final List<Calibration> calibrationl = Calibration.latestValid(1, until);
        if ((calibrationl != null) && (calibrationl.size() > 0)) {
            final Calibration calibration = calibrationl.get(0); // first and only
            if (calibration != null) {

                // produce the CalibrationData result
                cd = new CalibrationData(calibration.slope, calibration.intercept);

                // saveDataToCache(TAG, cd);
            }
        }
    }
    return cd; // null if invalid
}
 
Example 2
Source File: XDripOriginal.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    CalibrationData cd = loadDataFromCache(TAG);
    if (cd == null) {
        UserError.Log.d(TAG, "Regenerating Calibration data cache");
        final List<Calibration> calibrationl = Calibration.latestValid(1, until);
        if ((calibrationl != null) && (calibrationl.size() > 0)) {
            final Calibration calibration = calibrationl.get(0); // first and only
            if (calibration != null) {

                // produce the CalibrationData result
                cd = new CalibrationData(calibration.slope, calibration.intercept);

                // saveDataToCache(TAG, cd);
            }
        }
    }
    return cd; // null if invalid
}
 
Example 3
Source File: XDripOriginal.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    CalibrationData cd = loadDataFromCache(TAG);
    if (cd == null) {
        UserError.Log.d(TAG, "Regenerating Calibration data cache");
        final List<Calibration> calibrationl = Calibration.latestValid(1, until);
        if ((calibrationl != null) && (calibrationl.size() > 0)) {
            final Calibration calibration = calibrationl.get(0); // first and only
            if (calibration != null) {

                // produce the CalibrationData result
                cd = new CalibrationData(calibration.slope, calibration.intercept);

                // saveDataToCache(TAG, cd);
            }
        }
    }
    return cd; // null if invalid
}
 
Example 4
Source File: XDripOriginal.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    CalibrationData cd = loadDataFromCache(TAG);
    if (cd == null) {
        UserError.Log.d(TAG, "Regenerating Calibration data cache");
        final List<Calibration> calibrationl = Calibration.latestValid(1, until);
        if ((calibrationl != null) && (calibrationl.size() > 0)) {
            final Calibration calibration = calibrationl.get(0); // first and only
            if (calibration != null) {

                // produce the CalibrationData result
                cd = new CalibrationData(calibration.slope, calibration.intercept);

                // saveDataToCache(TAG, cd);
            }
        }
    }
    return cd; // null if invalid
}
 
Example 5
Source File: LastSevenUnweightedA.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    //CalibrationData cd = loadDataFromCache(TAG);
    CalibrationData cd = null;
    if (cd == null) {

        // first is most recent
        final List<Calibration> calibrations = Calibration.latestValid(7, until);
        if ((calibrations == null) || (calibrations.size() == 0)) return null;
        // have we got enough data to have a go
        if (calibrations.size() < 4) {
            // just use whatever xDrip original would have come up with at this point
            Log.d(TAG, "Falling back to xDrip-original values");
            cd = new CalibrationData(calibrations.get(0).slope, calibrations.get(0).intercept);
        } else {
            // TODO sanity checks
            final TrendLine bg_to_raw = new PolyTrendLine(1);

            final List<Double> raws = new ArrayList<>();
            final List<Double> bgs = new ArrayList<>();
            final boolean adjust_raw = !DexCollectionType.hasLibre();
            for (Calibration calibration : calibrations) {
                // sanity check?
                // weighting!
                final double raw = adjust_raw ? calibration.adjusted_raw_value : calibration.raw_value;
                Log.d(TAG, "Calibration: " + raw + " -> " + calibration.bg);
                raws.add(raw);
                bgs.add(calibration.bg);
            }

            bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws));
            Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience());
            final double intercept = bg_to_raw.predict(0);
            Log.d(TAG, "Intercept: " + intercept);
            final double one = bg_to_raw.predict(1);
            Log.d(TAG, "One: " + one);
            final double slope = one - intercept;
            Log.d(TAG, "Slope: " + slope);
            cd = new CalibrationData(slope, intercept);
        }
    }
    return cd; // null if invalid
}
 
Example 6
Source File: LastSevenUnweightedA.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    //CalibrationData cd = loadDataFromCache(TAG);
    CalibrationData cd = null;
    if (cd == null) {

        // first is most recent
        final List<Calibration> calibrations = Calibration.latestValid(7, until);
        if ((calibrations == null) || (calibrations.size() == 0)) return null;
        // have we got enough data to have a go
        if (calibrations.size() < 4) {
            // just use whatever xDrip original would have come up with at this point
            Log.d(TAG, "Falling back to xDrip-original values");
            cd = new CalibrationData(calibrations.get(0).slope, calibrations.get(0).intercept);
        } else {
            // TODO sanity checks
            final TrendLine bg_to_raw = new PolyTrendLine(1);

            final List<Double> raws = new ArrayList<>();
            final List<Double> bgs = new ArrayList<>();
            final boolean adjust_raw = !DexCollectionType.hasLibre();
            for (Calibration calibration : calibrations) {
                // sanity check?
                // weighting!
                final double raw = adjust_raw ? calibration.adjusted_raw_value : calibration.raw_value;
                Log.d(TAG, "Calibration: " + raw + " -> " + calibration.bg);
                raws.add(raw);
                bgs.add(calibration.bg);
            }

            bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws));
            Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience());
            final double intercept = bg_to_raw.predict(0);
            Log.d(TAG, "Intercept: " + intercept);
            final double one = bg_to_raw.predict(1);
            Log.d(TAG, "One: " + one);
            final double slope = one - intercept;
            Log.d(TAG, "Slope: " + slope);
            cd = new CalibrationData(slope, intercept);
        }
    }
    return cd; // null if invalid
}
 
Example 7
Source File: LastSevenUnweightedA.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    //CalibrationData cd = loadDataFromCache(TAG);
    CalibrationData cd = null;
    if (cd == null) {

        // first is most recent
        final List<Calibration> calibrations = Calibration.latestValid(7, until);
        if ((calibrations == null) || (calibrations.size() == 0)) return null;
        // have we got enough data to have a go
        if (calibrations.size() < 4) {
            // just use whatever xDrip original would have come up with at this point
            Log.d(TAG, "Falling back to xDrip-original values");
            cd = new CalibrationData(calibrations.get(0).slope, calibrations.get(0).intercept);
        } else {
            // TODO sanity checks
            final TrendLine bg_to_raw = new PolyTrendLine(1);

            final List<Double> raws = new ArrayList<>();
            final List<Double> bgs = new ArrayList<>();
            final boolean adjust_raw = !DexCollectionType.hasLibre();
            for (Calibration calibration : calibrations) {
                // sanity check?
                // weighting!
                final double raw = adjust_raw ? calibration.adjusted_raw_value : calibration.raw_value;
                Log.d(TAG, "Calibration: " + raw + " -> " + calibration.bg);
                raws.add(raw);
                bgs.add(calibration.bg);
            }

            bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws));
            Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience());
            final double intercept = bg_to_raw.predict(0);
            Log.d(TAG, "Intercept: " + intercept);
            final double one = bg_to_raw.predict(1);
            Log.d(TAG, "One: " + one);
            final double slope = one - intercept;
            Log.d(TAG, "Slope: " + slope);
            cd = new CalibrationData(slope, intercept);
        }
    }
    return cd; // null if invalid
}
 
Example 8
Source File: LastSevenUnweightedA.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CalibrationData getCalibrationData(long until) {

    // TODO cache must understand until
    //CalibrationData cd = loadDataFromCache(TAG);
    CalibrationData cd = null;
    if (cd == null) {

        // first is most recent
        final List<Calibration> calibrations = Calibration.latestValid(7, until);
        if ((calibrations == null) || (calibrations.size() == 0)) return null;
        // have we got enough data to have a go
        if (calibrations.size() < 4) {
            // just use whatever xDrip original would have come up with at this point
            Log.d(TAG, "Falling back to xDrip-original values");
            cd = new CalibrationData(calibrations.get(0).slope, calibrations.get(0).intercept);
        } else {
            // TODO sanity checks
            final TrendLine bg_to_raw = new PolyTrendLine(1);

            final List<Double> raws = new ArrayList<>();
            final List<Double> bgs = new ArrayList<>();
            final boolean adjust_raw = !DexCollectionType.hasLibre();
            for (Calibration calibration : calibrations) {
                // sanity check?
                // weighting!
                final double raw = adjust_raw ? calibration.adjusted_raw_value : calibration.raw_value;
                Log.d(TAG, "Calibration: " + raw + " -> " + calibration.bg);
                raws.add(raw);
                bgs.add(calibration.bg);
            }

            bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws));
            Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience());
            final double intercept = bg_to_raw.predict(0);
            Log.d(TAG, "Intercept: " + intercept);
            final double one = bg_to_raw.predict(1);
            Log.d(TAG, "One: " + one);
            final double slope = one - intercept;
            Log.d(TAG, "Slope: " + slope);
            cd = new CalibrationData(slope, intercept);
        }
    }
    return cd; // null if invalid
}