com.eveningoutpost.dexdrip.Models.Calibration Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.Models.Calibration. 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: 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 #2
Source File: BgGraphBuilder.java    From xDrip-plus 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: BgGraphBuilder.java    From xDrip-plus 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 #4
Source File: NightscoutUploader.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private void populateV1APICalibrationEntry(JSONArray array, Calibration record) throws Exception {

            //do not upload undefined slopes
            if(record.slope == 0d) return;

            JSONObject json = new JSONObject();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
            format.setTimeZone(TimeZone.getDefault());
            json.put("device", "xDrip-" + prefs.getString("dex_collection_method", "BluetoothWixel"));
            json.put("type", "cal");
            json.put("date", record.timestamp);
            json.put("dateString", format.format(record.timestamp));
            json.put("slope", getNightscoutSlope(record));
            json.put("intercept", getNightscoutIntercept(record));
            json.put("scale", getNightscoutScale(record));
            json.put("sysTime", format.format(record.timestamp));
            array.put(json);
        }
 
Example #5
Source File: NightscoutUploader.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public boolean uploadRest(List<BgReading> glucoseDataSets, List<BloodTest> meterRecords, List<Calibration> calRecords) {

        boolean apiStatus = false;

        if (enableRESTUpload) {
            long start = System.currentTimeMillis();
            Log.i(TAG, String.format("Starting upload of %s record using a REST API", glucoseDataSets.size()));
            apiStatus = doRESTUpload(prefs, glucoseDataSets, meterRecords, calRecords);
            Log.i(TAG, String.format("Finished upload of %s record using a REST API in %s ms result: %b", glucoseDataSets.size(), System.currentTimeMillis() - start, apiStatus));

            if (prefs.getBoolean("cloud_storage_api_download_enable", false)) {
                start = System.currentTimeMillis();
                final boolean substatus = doRESTtreatmentDownload(prefs);
                if (substatus) {
                    Home.staticRefreshBGCharts();
                }
                Log.i(TAG, String.format("Finished download using a REST API in %s ms result: %b", System.currentTimeMillis() - start, substatus));
            }
        }
        return apiStatus;
    }
 
Example #6
Source File: NightscoutUploader.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void populateV1APIMeterReadingEntry(JSONArray array, Calibration record) throws Exception {
    if (record == null) {
        Log.e(TAG, "Received null calibration record in populateV1ApiMeterReadingEntry !");
        return;
    }
    JSONObject json = new JSONObject();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
    format.setTimeZone(TimeZone.getDefault());
    json.put("device", "xDrip-" + prefs.getString("dex_collection_method", "BluetoothWixel"));
    json.put("type", "mbg");
    json.put("date", record.timestamp);
    json.put("dateString", format.format(record.timestamp));
    json.put("mbg", record.bg);
    json.put("sysTime", format.format(record.timestamp));
    array.put(json);
}
 
Example #7
Source File: GcmActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static String sensorAndCalibrationsToJson(Sensor sensor, int limit) {
    SensorCalibrations[] sensorCalibrations = new SensorCalibrations[1];
    sensorCalibrations[0] = new SensorCalibrations();
    sensorCalibrations[0].sensor = sensor;
    sensorCalibrations[0].calibrations = Calibration.getCalibrationsForSensor(sensor, limit);
    if (d) Log.d(TAG, "calibrations size " + sensorCalibrations[0].calibrations.size());
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();

    String output = gson.toJson(sensorCalibrations);
    if (d) Log.d(TAG, "sensorAndCalibrationsToJson created the string " + output);
    return output;
}
 
Example #8
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 #9
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 #10
Source File: NightscoutUploader.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public boolean uploadRest(List<BgReading> glucoseDataSets, List<BloodTest> meterRecords, List<Calibration> calRecords) {

        boolean apiStatus = false;

        if (enableRESTUpload) {
            long start = System.currentTimeMillis();
            Log.i(TAG, String.format("Starting upload of %s record using a REST API", glucoseDataSets.size()));
            apiStatus = doRESTUpload(prefs, glucoseDataSets, meterRecords, calRecords);
            Log.i(TAG, String.format("Finished upload of %s record using a REST API in %s ms result: %b", glucoseDataSets.size(), System.currentTimeMillis() - start, apiStatus));

            if (prefs.getBoolean("cloud_storage_api_download_enable", false)) {
                start = System.currentTimeMillis();
                final boolean substatus = doRESTtreatmentDownload(prefs);
                if (substatus) {
                    Home.staticRefreshBGCharts();
                }
                Log.i(TAG, String.format("Finished download using a REST API in %s ms result: %b", System.currentTimeMillis() - start, substatus));
            }
        }
        return apiStatus;
    }
 
Example #11
Source File: InfluxDBUploader.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private Point createCalibrationPoint(Calibration record) {
    Point.Builder builder = Point.measurement("calibration")
            .time(record.timestamp, TimeUnit.MILLISECONDS)
            .tag("device", "xDrip-" + prefs.getString("dex_collection_method", "BluetoothWixel"))
            .tag("type", "cal");

    if (record.check_in) {
        builder.addField("slope", record.first_slope)
                .addField("intercept", record.first_intercept)
                .addField("scale", record.first_scale);
    } else {
        builder.addField("slope", (1000 / record.slope))
                .addField("intercept", ((record.intercept * -1000) / record.slope))
                .addField("scale", 1);
    }

    return builder.build();
}
 
Example #12
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 #13
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 #14
Source File: InfluxDBUploader.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private Point createCalibrationPoint(Calibration record) {
    Point.Builder builder = Point.measurement("calibration")
            .time(record.timestamp, TimeUnit.MILLISECONDS)
            .tag("device", "xDrip-" + prefs.getString("dex_collection_method", "BluetoothWixel"))
            .tag("type", "cal");

    if (record.check_in) {
        builder.addField("slope", record.first_slope)
                .addField("intercept", record.first_intercept)
                .addField("scale", record.first_scale);
    } else {
        builder.addField("slope", (1000 / record.slope))
                .addField("intercept", ((record.intercept * -1000) / record.slope))
                .addField("scale", 1);
    }

    return builder.build();
}
 
Example #15
Source File: AddCalibration.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public void addListenerOnButton() {

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

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                if (Sensor.isActive()) {
                    EditText value = (EditText) findViewById(R.id.bg_value);
                    String string_value = value.getText().toString();
                    if (!TextUtils.isEmpty(string_value)){
                        double calValue = Double.parseDouble(string_value);


                        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AddCalibration.this);
                        String unit = prefs.getString("units", "mgdl");
                        double calValueMGDL = ("mgdl".equals(unit))?calValue:calValue*Constants.MMOLL_TO_MGDL;

                        if(calValueMGDL >=40 && calValueMGDL <=400){

                            Calibration calibration = Calibration.create(calValue, getApplicationContext());

                            Intent tableIntent = new Intent(v.getContext(), Home.class);
                            startActivity(tableIntent);
                            finish();
                        } else {
                            value.setError("Out of range!");
                        }
                    } else {
                        value.setError("Calibration Can Not be blank");
                    }
                } else {
                    Log.w("CALERROR", "Sensor is not active, cannot calibrate");
                }
            }
        });

    }
 
Example #16
Source File: CalibrationOverride.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void addListenerOnButton() {
        button = (Button) findViewById(R.id.save_calibration_button);

        button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (Sensor.isActive()) {
                EditText value = (EditText) findViewById(R.id.bg_value);
                String string_value = value.getText().toString();
                if (!TextUtils.isEmpty(string_value)){
                    double calValue = Double.parseDouble(string_value);

                    Calibration last_calibration = Calibration.last();
                    last_calibration.sensor_confidence = 0;
                    last_calibration.slope_confidence = 0;
                    last_calibration.save();
                    Calibration.create(calValue, getApplicationContext());

                     Intent tableIntent = new Intent(v.getContext(), Home.class);
                     startActivity(tableIntent);
                     finish();
                } else {
                    value.setError("Calibration Can Not be blank");
                }
            } else {
                Log.w("CANNOT CALIBRATE WITHOUT CURRENT SENSOR", "ERROR");
            }
        }
    });

}
 
Example #17
Source File: CalibrationSendQueue.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void addToQueue(Calibration calibration, Context context) {

        // TODO support for various insert/update/delete functions

        //  CalibrationSendQueue calibrationSendQueue = new CalibrationSendQueue();
        //  calibrationSendQueue.calibration = calibration;
        //  calibrationSendQueue.success = false;
        //  calibrationSendQueue.mongo_success = false;
        //  calibrationSendQueue.save();
        UploaderQueue.newEntry("create", calibration);
        Log.i(TAG, "calling SensorSendQueue.SendToFollower");
        SensorSendQueue.SendToFollower(Sensor.getByUuid(calibration.sensor_uuid));
    }
 
Example #18
Source File: CalibrationSendQueue.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void addToQueue(Calibration calibration, Context context) {
    CalibrationSendQueue calibrationSendQueue = new CalibrationSendQueue();
    calibrationSendQueue.calibration = calibration;
    calibrationSendQueue.success = false;
    calibrationSendQueue.mongo_success = false;
    calibrationSendQueue.save();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (prefs.getBoolean("cloud_storage_mongodb_enable", false) || prefs.getBoolean("cloud_storage_api_enable", false)) {
        MongoSendTask task = new MongoSendTask(context, calibrationSendQueue);
        task.execute();
    }
}
 
Example #19
Source File: CalibrationOverride.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public void addListenerOnButton() {
        button = (Button) findViewById(R.id.save_calibration_button);

        button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (Sensor.isActive()) {
                EditText value = (EditText) findViewById(R.id.bg_value);
                String string_value = value.getText().toString();
                if (!TextUtils.isEmpty(string_value)){
                    double calValue = Double.parseDouble(string_value);

                    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CalibrationOverride.this);
                    String unit = prefs.getString("units", "mgdl");
                    double calValueMGDL = ("mgdl".equals(unit))?calValue:calValue* Constants.MMOLL_TO_MGDL;

                    if(calValueMGDL >=40 && calValueMGDL <=400){
                        Calibration.clearLastCalibration(getApplicationContext());
                        Calibration.create(calValue, getApplicationContext());

                        Intent tableIntent = new Intent(v.getContext(), Home.class);
                        startActivity(tableIntent);
                        finish();
                    } else {
                        value.setError("Out of range!");
                    }

                } else {
                    value.setError("Calibration Can Not be blank");
                }
            } else {
                Log.w("Calibration", "ERROR, no active sensor");
            }
        }
    });

}
 
Example #20
Source File: CalibrationDataTable.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
CalibrationDataCursorAdapter(Context context, List<Calibration> calibrations) {
    this.context = context;
    if(calibrations == null)
        calibrations = new ArrayList<>();

    this.calibrations = calibrations;
}
 
Example #21
Source File: UploaderQueue.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static UploaderQueue newEntryForWatch(String action, Model obj) {
    UserError.Log.d(TAG, "new entry called for watch");
    final UploaderQueue result = new UploaderQueue();
    result.bitfield_wanted = DEFAULT_UPLOAD_CIRCUITS
            | (Pref.getBooleanDefaultFalse("wear_sync") ? WATCH_WEARAPI : 0);
    if (result.bitfield_wanted == 0) return null; // no queue required
    result.timestamp = JoH.tsl();
    result.reference_id = obj.getId();
    // TODO this probably could be neater
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BgReading ? ((BgReading) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Treatments ? ((Treatments) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Calibration ? ((Calibration) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BloodTest ? ((BloodTest) obj).uuid : null;

    if (result.reference_uuid == null) {
        Log.d(TAG, "reference_uuid was null so refusing to create new entry");
        return null;
    }

    if (result.reference_id < 0) {
        UserError.Log.wtf(TAG, "Watch ERROR ref id was: " + result.reference_id + " for uuid: " + result.reference_uuid + " refusing to create");
        return null;
    }

    result.action = action;

    result.bitfield_complete = 0;
    result.type = obj.getClass().getSimpleName();
    result.saveit();
    if (d) UserError.Log.d(TAG, result.toS());
    last_new_entry = JoH.tsl();
    return result;
}
 
Example #22
Source File: SystemStatus.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void futureDataCheck() {
    futureDataDeleteButton.setVisibility(View.GONE);
    final List<BgReading> futureReadings = BgReading.futureReadings();
    final List<Calibration> futureCalibrations = Calibration.futureCalibrations();
    if((futureReadings != null && futureReadings.size() > 0) || (futureCalibrations != null && futureCalibrations.size() > 0)) {
        notes.append("\n- Your device has future data on it, Please double check the time and timezone on this phone.");
        futureDataDeleteButton.setVisibility(View.VISIBLE);
    }
    futureDataDeleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(futureReadings != null && futureReadings.size() > 0) {
                for (BgReading bgReading : futureReadings) {
                    bgReading.calculated_value = 0;
                    bgReading.raw_data = 0;
                    bgReading.timestamp = 0;
                    bgReading.save();
                }
            }
            if(futureCalibrations != null && futureCalibrations.size() > 0) {
                for (Calibration calibration : futureCalibrations) {
                    calibration.slope_confidence = 0;
                    calibration.sensor_confidence = 0;
                    calibration.timestamp = 0;
                    calibration.save();
                }
            }
        }
    });
}
 
Example #23
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static DataMap getCalibrations(long startTime) {
    Calibration last = Calibration.last();
    if (last != null) {
        Log.d(TAG, "getCalibrations last.timestamp:" +  JoH.dateTimeText(last.timestamp));
    }
    List<Calibration> graph = Calibration.latestForGraph(60, startTime, Long.MAX_VALUE);
    //calibrations = Calibration.latestForGraph(numValues, start - (3 * Constants.DAY_IN_MS), end);
    if (!graph.isEmpty()) {
        Log.d(TAG, "getCalibrations graph size=" + graph.size());
        final ArrayList<DataMap> dataMaps = new ArrayList<>(graph.size());
        DataMap entries = null;
        //if (last.slope_confidence != 0) entries = dataMapForWatchface(last);
        for (Calibration data : graph) {
            if (data.slope_confidence != 0) {
                if (entries == null) {
                    entries = dataMapForWatchface(data);
                    dataMaps.add(dataMapForWatchface(data));
                }
                else
                    dataMaps.add(dataMapForWatchface(data));
            }
        }
        if (entries != null) {
            entries.putDataMapArrayList("entries", dataMaps);
            Log.d(TAG, "getCalibrations entries=" + entries);
        }
        return entries;
    }
    else return null;
}
 
Example #24
Source File: CalibrationSendQueue.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void addToQueue(Calibration calibration, Context context) {
    CalibrationSendQueue calibrationSendQueue = new CalibrationSendQueue();
    calibrationSendQueue.calibration = calibration;
    calibrationSendQueue.success = false;
    calibrationSendQueue.mongo_success = false;
    calibrationSendQueue.save();
}
 
Example #25
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static DataMap getCalibrations(long startTime) {
    Calibration last = Calibration.last();
    if (last != null) {
        Log.d(TAG, "getCalibrations last.timestamp:" +  JoH.dateTimeText(last.timestamp));
    }
    List<Calibration> graph = Calibration.latestForGraph(60, startTime, Long.MAX_VALUE);
    //calibrations = Calibration.latestForGraph(numValues, start - (3 * Constants.DAY_IN_MS), end);
    if (!graph.isEmpty()) {
        Log.d(TAG, "getCalibrations graph size=" + graph.size());
        final ArrayList<DataMap> dataMaps = new ArrayList<>(graph.size());
        DataMap entries = null;
        //if (last.slope_confidence != 0) entries = dataMapForWatchface(last);
        for (Calibration data : graph) {
            if (data.slope_confidence != 0) {
                if (entries == null) {
                    entries = dataMapForWatchface(data);
                    dataMaps.add(dataMapForWatchface(data));
                }
                else
                    dataMaps.add(dataMapForWatchface(data));
            }
        }
        if (entries != null) {
            entries.putDataMapArrayList("entries", dataMaps);
            Log.d(TAG, "getCalibrations entries=" + entries);
        }
        return entries;
    }
    else return null;
}
 
Example #26
Source File: SystemStatus.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void futureDataCheck() {
    futureDataDeleteButton.setVisibility(View.GONE);
    final List<BgReading> futureReadings = BgReading.futureReadings();
    final List<Calibration> futureCalibrations = Calibration.futureCalibrations();
    if((futureReadings != null && futureReadings.size() > 0) || (futureCalibrations != null && futureCalibrations.size() > 0)) {
        notes.append("\n- Your device has future data on it, Please double check the time and timezone on this phone.");
        futureDataDeleteButton.setVisibility(View.VISIBLE);
    }
    futureDataDeleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(futureReadings != null && futureReadings.size() > 0) {
                for (BgReading bgReading : futureReadings) {
                    bgReading.calculated_value = 0;
                    bgReading.raw_data = 0;
                    bgReading.timestamp = 0;
                    bgReading.save();
                }
            }
            if(futureCalibrations != null && futureCalibrations.size() > 0) {
                for (Calibration calibration : futureCalibrations) {
                    calibration.slope_confidence = 0;
                    calibration.sensor_confidence = 0;
                    calibration.timestamp = 0;
                    calibration.save();
                }
            }
        }
    });
}
 
Example #27
Source File: WatchUpdaterService.java    From xDrip 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 #28
Source File: SystemStatusFragment.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void futureDataCheck() {
    futureDataDeleteButton.setVisibility(View.GONE);
    final List<BgReading> futureReadings = BgReading.futureReadings();
    final List<Calibration> futureCalibrations = Calibration.futureCalibrations();
    if ((futureReadings != null && futureReadings.size() > 0) || (futureCalibrations != null && futureCalibrations.size() > 0)) {
        notes.append("\n- Your device has future data on it, Please double check the time and timezone on this phone.");
        futureDataDeleteButton.setVisibility(View.VISIBLE);
    }
    futureDataDeleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (futureReadings != null && futureReadings.size() > 0) {
                for (BgReading bgReading : futureReadings) {
                    bgReading.calculated_value = 0;
                    bgReading.raw_data = 0;
                    bgReading.timestamp = 0;
                    bgReading.save();
                }
            }
            if (futureCalibrations != null && futureCalibrations.size() > 0) {
                for (Calibration calibration : futureCalibrations) {
                    calibration.slope_confidence = 0;
                    calibration.sensor_confidence = 0;
                    calibration.timestamp = 0;
                    calibration.save();
                }
            }
        }
    });
}
 
Example #29
Source File: AddCalibration.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void addListenerOnButton() {

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

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                if (Sensor.isActive()) {
                    EditText value = (EditText) findViewById(R.id.bg_value);
                    String string_value = value.getText().toString();
                    if (!TextUtils.isEmpty(string_value)){
                        double calValue = Double.parseDouble(string_value);


                        Calibration calibration = Calibration.create(calValue, getApplicationContext());

                        Intent tableIntent = new Intent(v.getContext(), Home.class);
                        startActivity(tableIntent);
                        finish();
                    } else {
                        value.setError("Calibration Can Not be blank");
                    }
                } else {
                    Log.w("CALERROR", "ERROR");
                }
            }
        });

    }
 
Example #30
Source File: NightscoutUploader.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public static double getNightscoutIntercept(Calibration cal) {
    if(cal.check_in) {
        return cal.first_intercept;
    } else {
        return (cal.intercept * -1000) / (cal.slope);
    }
}