Search in sources :

Example 51 with Calibration

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

the class CalibrationGraph method getCalibrationsLine.

@NonNull
public List<Line> getCalibrationsLine(List<Calibration> calibrations, int color) {
    if (calibrations == null)
        return new ArrayList<>();
    List<PointValue> values = new ArrayList<PointValue>();
    List<PointValue> valuesb = new ArrayList<PointValue>();
    List<PointValue> valuesc = new ArrayList<PointValue>();
    for (Calibration calibration : calibrations) {
        if (calibration.estimate_raw_at_time_of_calibration > end_x) {
            end_x = calibration.estimate_raw_at_time_of_calibration;
        }
        PointValue point = new PointValue((float) calibration.estimate_raw_at_time_of_calibration, doMgdl ? (float) calibration.bg : ((float) calibration.bg) * (float) Constants.MGDL_TO_MMOLL);
        PointValue pointb = new PointValue((float) calibration.raw_value, doMgdl ? (float) calibration.bg : ((float) calibration.bg) * (float) Constants.MGDL_TO_MMOLL);
        PointValue pointc = new PointValue((float) calibration.adjusted_raw_value, doMgdl ? (float) calibration.bg : ((float) calibration.bg) * (float) Constants.MGDL_TO_MMOLL);
        String time;
        if (show_days_since) {
            final int days_ago = daysAgo(calibration.raw_timestamp);
            time = (days_ago > 0) ? Integer.toString(days_ago) + "d  " : "";
            time = time + (JoH.hourMinuteString(calibration.raw_timestamp));
        } else {
            time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) calibration.raw_timestamp));
        }
        point.setLabel(time);
        values.add(point);
        // extra points showing real raw and age_adjusted raw for each calbration point
        valuesb.add(pointb);
        valuesc.add(pointc);
    }
    Line line = new Line(values);
    line.setColor(color);
    line.setHasLines(false);
    line.setPointRadius(4);
    line.setHasPoints(true);
    line.setHasLabels(true);
    List<Line> lines = new ArrayList<>();
    lines.add(line);
    if (Pref.getBooleanDefaultFalse("engineering_mode")) {
        // actual raw
        Line lineb = new Line(valuesb);
        lineb.setColor(Color.RED);
        lineb.setHasLines(false);
        lineb.setPointRadius(1);
        lineb.setHasPoints(true);
        lineb.setHasLabels(false);
        // age adjusted raw
        Line linec = new Line(valuesc);
        linec.setColor(Color.YELLOW);
        linec.setHasLines(false);
        linec.setPointRadius(1);
        linec.setHasPoints(true);
        linec.setHasLabels(false);
        lines.add(lineb);
        lines.add(linec);
    }
    return lines;
}
Also used : Line(lecho.lib.hellocharts.model.Line) PointValue(lecho.lib.hellocharts.model.PointValue) ArrayList(java.util.ArrayList) Calibration(com.eveningoutpost.dexdrip.Models.Calibration) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Example 52 with Calibration

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

the class CalibrationGraph method overWriteIntercept.

private void overWriteIntercept() {
    final EditText editText = new EditText(this);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    new AlertDialog.Builder(this).setTitle("Ovewrite Intercept").setMessage("Overwrite Intercept").setView(editText).setPositiveButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String text = editText.getText().toString();
            if (!TextUtils.isEmpty(text)) {
                double doubleValue = JoH.tolerantParseDouble(text);
                Calibration calibration = Calibration.lastValid();
                calibration.intercept = doubleValue;
                calibration.save();
                CalibrationSendQueue.addToQueue(calibration, getApplicationContext());
                recreate();
            } else {
                JoH.static_toast_long("Input not found! Cancelled!");
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            JoH.static_toast_long("Cancelled!");
        }
    }).show();
}
Also used : EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Calibration(com.eveningoutpost.dexdrip.Models.Calibration)

Example 53 with Calibration

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

the class CalibrationGraph method overWriteSlope.

private void overWriteSlope() {
    final EditText editText = new EditText(this);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    new AlertDialog.Builder(this).setTitle("Ovewrite Slope").setMessage("Overwrite Slope").setView(editText).setPositiveButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String text = editText.getText().toString();
            if (!TextUtils.isEmpty(text)) {
                double doubleValue = JoH.tolerantParseDouble(text);
                Calibration calibration = Calibration.lastValid();
                calibration.slope = doubleValue;
                calibration.save();
                CalibrationSendQueue.addToQueue(calibration, getApplicationContext());
                recreate();
            } else {
                JoH.static_toast_long("Input not found! Cancelled!");
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            JoH.static_toast_long("Cancelled!");
        }
    }).show();
}
Also used : EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Calibration(com.eveningoutpost.dexdrip.Models.Calibration)

Example 54 with Calibration

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

the class NewCalibration method upsertSensorCalibratonsFromJson.

static void upsertSensorCalibratonsFromJson(String json) {
    Log.i(TAG, "upsertSensorCalibratonsFromJson called");
    SensorCalibrations[] sensorCalibrations = getSensorCalibrations(json);
    for (SensorCalibrations SensorCalibration : sensorCalibrations) {
        Sensor.upsertFromMaster(SensorCalibration.sensor);
        for (Calibration calibration : SensorCalibration.calibrations) {
            Log.d(TAG, "upsertSensorCalibratonsFromJson updating calibration " + calibration.uuid);
            Calibration.upsertFromMaster(calibration);
        }
    }
}
Also used : Calibration(com.eveningoutpost.dexdrip.Models.Calibration)

Aggregations

Calibration (com.eveningoutpost.dexdrip.Models.Calibration)54 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)20 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 EditText (android.widget.EditText)8 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)8 DataMap (com.google.android.gms.wearable.DataMap)8 DialogInterface (android.content.DialogInterface)6 Intent (android.content.Intent)6 NonNull (android.support.annotation.NonNull)6 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)6 PolyTrendLine (com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine)6 TrendLine (com.eveningoutpost.dexdrip.Models.Forecast.TrendLine)6 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)6 CalibrationAbstract (com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract)6 PluggableCalibration (com.eveningoutpost.dexdrip.calibrations.PluggableCalibration)6 IOException (java.io.IOException)6 PointValue (lecho.lib.hellocharts.model.PointValue)6 JSONException (org.json.JSONException)6 View (android.view.View)4