Search in sources :

Example 31 with ScaleMeasurement

use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.

the class ScreenshotRecorder method prepareData.

private void prepareData() {
    int userId = openScale.addScaleUser(getTestUser());
    openScale.selectScaleUser(userId);
    List<ScaleMeasurement> scaleMeasurementList = getTestMeasurements();
    for (ScaleMeasurement measurement : scaleMeasurementList) {
        openScale.addScaleData(measurement, true);
    }
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement)

Example 32 with ScaleMeasurement

use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.

the class ScreenshotRecorder method getTestMeasurements.

List<ScaleMeasurement> getTestMeasurements() {
    List<ScaleMeasurement> scaleMeasurementList = new ArrayList<>();
    String data = "\"dateTime\",\"weight\",\"fat\",\"water\",\"muscle\",\"lbw\",\"bone\",\"waist\",\"hip\",\"comment\"\n" + "04.08.2015 08:08,89.7,21.2,58.0,41.5\n" + "03.08.2015 05:17,89.0,26.4,54.6,41.6\n" + "02.08.2015 07:32,88.8,25.0,55.6,41.7\n" + "31.07.2015 04:39,89.1,29.2,52.8,41.6\n" + "18.07.2015 07:54,91.3,22.1,57.4,41.2\n" + "12.07.2015 07:14,91.1,21.9,57.6,41.3\n" + "16.06.2015 05:16,89.5,25.3,55.4,41.5\n" + "15.06.2015 05:34,90.1,26.3,54.7,41.4\n" + "12.06.2015 05:36,90.3,26.4,54.6,41.4\n" + "10.06.2015 04:22,90.8,22.3,57.3,41.3\n" + "07.06.2015 10:17,90.0,22.6,57.1,41.4\n" + "06.06.2015 06:36,91.0,21.6,57.8,41.3\n" + "05.06.2015 06:57,91.6,21.7,57.7,41.2\n" + "04.06.2015 06:35,90.4,23.5,56.5,41.4\n" + "25.05.2015 10:25,89.5,21.6,57.8,41.5\n" + "17.05.2015 09:55,92.5,21.9,57.6,41.0\n" + "09.05.2015 09:30,89.0,21.6,57.8,41.6\n" + "29.04.2015 08:25,89.2,21.0,58.2,41.4\n" + "13.04.2015 04:54,87.6,32.7,50.6,41.9\n" + "11.04.2015 07:41,86.8,20.9,58.3,42.0\n" + "10.04.2015 05:27,86.4,24.0,56.3,42.1\n" + "06.04.2015 06:45,87.6,24.4,56.0,41.9\n" + "01.04.2015 05:03,88.6,25.6,55.2,41.7\n" + "28.03.2015 07:06,87.1,23.5,56.6,42.2\n" + "21.03.2015 18:21,88.1,20.7,58.5,42.0\n" + "15.03.2015 20:56,90.3,22.6,57.1,41.6\n" + "14.03.2015 07:37,87.2,25.3,55.5,42.1\n" + "13.03.2015 06:11,85.6,27.4,54.1,42.4\n" + "17.02.2015 10:32,86.6,20.6,58.5,42.2\n" + "16.02.2015 07:59,87.5,27.6,53.9,42.1\n" + "15.02.2015 10:38,86.4,23.4,56.7,42.3\n" + "14.02.2015 09:18,87.5,20.5,58.6,42.1\n" + "08.02.2015 07:05,85.5,26.6,54.6,42.4\n" + "06.02.2015 06:09,85.8,30.3,52.2,42.4\n" + "05.02.2015 06:16,86.5,31.2,51.6,42.3\n" + "04.02.2015 06:10,86.7,28.3,53.5,42.2\n" + "01.02.2015 08:59,87.4,22.2,57.5,42.1\n" + "24.01.2015 09:55,85.1,24.1,56.2,42.5\n" + "18.01.2015 11:11,86.1,20.1,58.9,42.3\n" + "14.01.2015 06:11,86.9,26.3,54.8,42.2\n" + "07.01.2015 07:08,85.6,20.3,58.7,42.4\n" + "06.01.2015 10:34,85.5,19.7,59.1,42.4\n" + "05.01.2015 08:25,85.6,26.1,54.9,42.4\n" + "02.01.2015 18:06,86.3,19.8,59.1,42.3\n" + "13.12.2014 13:16,85.2,19.3,59.4,42.5\n" + "09.12.2014 19:36,86.9,20.3,58.7,42.2\n" + "08.12.2014 20:28,86.8,19.9,59.0,42.2\n" + "05.12.2014 18:21,86.7,20.3,58.7,42.2\n";
    try {
        scaleMeasurementList = CsvHelper.importFrom(new BufferedReader(new StringReader(data)));
    } catch (IOException e) {
        Log.e("ScreenshotRecorder", e.getMessage());
    } catch (ParseException e) {
        Log.e("ScreenshotRecorder", e.getMessage());
    }
    // set current year to the measurement data
    Calendar measurementDate = Calendar.getInstance();
    int year = measurementDate.get(Calendar.YEAR);
    for (ScaleMeasurement measurement : scaleMeasurementList) {
        measurementDate.setTime(measurement.getDateTime());
        measurementDate.set(Calendar.YEAR, year);
        measurement.setDateTime(measurementDate.getTime());
    }
    return scaleMeasurementList;
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 33 with ScaleMeasurement

use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.

the class OpenScale method importData.

public void importData(Uri uri) {
    try {
        final String filename = getFilenameFromUri(uri);
        InputStream input = context.getContentResolver().openInputStream(uri);
        List<ScaleMeasurement> csvScaleMeasurementList = CsvHelper.importFrom(new BufferedReader(new InputStreamReader(input)));
        final int userId = getSelectedScaleUser().getId();
        for (ScaleMeasurement measurement : csvScaleMeasurementList) {
            measurement.setUserId(userId);
        }
        measurementDAO.insertAll(csvScaleMeasurementList);
        updateScaleData();
        Toast.makeText(context, context.getString(R.string.info_data_imported) + " " + filename, Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        Toast.makeText(context, context.getString(R.string.error_importing) + ": " + e.getMessage(), Toast.LENGTH_SHORT).show();
    } catch (ParseException e) {
        Toast.makeText(context, context.getString(R.string.error_importing) + ": " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 34 with ScaleMeasurement

use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.

the class BluetoothSanitasSbf70 method parseScaleData.

private ScaleMeasurement parseScaleData(byte[] data) throws ParseException {
    if (data.length != 11 + 11)
        throw new ParseException("Parse scala data: unexpected length", 0);
    ScaleMeasurement receivedMeasurement = new ScaleMeasurement();
    // Parse timestamp
    long timestamp = ByteBuffer.wrap(data, 0, 4).getInt() * 1000L;
    SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy 'at' h:mm a");
    String date = sdf.format(timestamp);
    receivedMeasurement.setDateTime(new Date(timestamp));
    // little endian
    float weight = ((float) (((data[4] & 0xFF) << 8) + (data[5] & 0xFF))) * 50.0f / // unit is 50g
    1000.0f;
    receivedMeasurement.setWeight(weight);
    // Parse impedance level
    int impedance = ((data[6] & 0xFF) << 8) + (data[7] & 0xFF);
    // Parse fat
    float fat = ((float) (((data[8] & 0xFF) << 8) + (data[9] & 0xFF))) / // unit is 0.1%
    10.0f;
    receivedMeasurement.setFat(fat);
    float water = ((float) (((data[10] & 0xFF) << 8) + (data[11] & 0xFF))) / // unit is 0.1%
    10.0f;
    receivedMeasurement.setWater(water);
    float muscle = ((float) (((data[12] & 0xFF) << 8) + (data[13] & 0xFF))) / // unit is 0.1%
    10.0f;
    receivedMeasurement.setMuscle(muscle);
    float boneMass = ((float) (((data[14] & 0xFF) << 8) + (data[15] & 0xFF))) * 50.0f / // unit is 50g
    1000.0f;
    receivedMeasurement.setBone(boneMass);
    // basal metabolic rate
    float bmr = ((float) (((data[16] & 0xFF) << 8) + (data[17] & 0xFF))) / 10.0f;
    // active metabolic rate
    int amr = ((data[18] & 0xFF) << 8) + (data[19] & 0xFF);
    float bmi = ((data[20] & 0xFF) << 8) + (data[21] & 0xFF);
    Log.i(TAG, "Measurement: " + date + " Impedance: " + impedance + " Weight:" + weight + " Fat: " + fat + " Water: " + water + " Muscle: " + muscle + " BoneMass: " + boneMass + " BMR: " + bmr + " AMR: " + amr + " BMI: " + bmi);
    return receivedMeasurement;
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 35 with ScaleMeasurement

use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.

the class CsvHelperTest method newStyleSingleEntry.

@Test
public void newStyleSingleEntry() throws Exception {
    final String data = HEADERS + "1.0,\"some text\",\"01.03.2018 12:45\",2.0,3.0,4.0,5.0,6.0,7.0,8.0\n";
    List<ScaleMeasurement> list = CsvHelper.importFrom(new BufferedReader(new StringReader(data)));
    assertEquals(1, list.size());
    validateEntry(list.get(0), 5);
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)39 Date (java.util.Date)13 ScaleUser (com.health.openscale.core.datatypes.ScaleUser)12 BufferedReader (java.io.BufferedReader)9 ParseException (java.text.ParseException)9 StringReader (java.io.StringReader)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 Calendar (java.util.Calendar)7 MeasurementView (com.health.openscale.gui.views.MeasurementView)6 SimpleDateFormat (java.text.SimpleDateFormat)5 BMRMeasurementView (com.health.openscale.gui.views.BMRMeasurementView)4 FloatMeasurementView (com.health.openscale.gui.views.FloatMeasurementView)4 WeightMeasurementView (com.health.openscale.gui.views.WeightMeasurementView)4 IOException (java.io.IOException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Stack (java.util.Stack)2 SimpleLineChartValueFormatter (lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter)2 Axis (lecho.lib.hellocharts.model.Axis)2 AxisValue (lecho.lib.hellocharts.model.AxisValue)2