Search in sources :

Example 16 with ScaleMeasurement

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

the class BluetoothExingtechY1 method parseBytes.

private void parseBytes(byte[] weightBytes) {
    int userId = (int) (weightBytes[0] & 0x0F);
    // 0x00 male; 0x01 female
    int gender = (int) (weightBytes[1]);
    // 10 ~ 99
    int age = (int) (weightBytes[2]);
    // 0 ~ 255
    int height = (int) (weightBytes[3]);
    // kg
    float weight = (float) (((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f;
    // %
    float fat = (float) (((weightBytes[6] & 0xFF) << 8) | (weightBytes[7] & 0xFF)) / 10.0f;
    // %
    float water = (float) (((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f;
    // kg
    float bone = (float) (((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / weight * 10.0f;
    // %
    float muscle = (float) (((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f;
    // %
    float visc_muscle = (float) (weightBytes[14] & 0xFF);
    float calorie = (float) (((weightBytes[15] & 0xFF) << 8) | (weightBytes[16] & 0xFF));
    float bmi = (float) (((weightBytes[17] & 0xFF) << 8) | (weightBytes[18] & 0xFF)) / 10.0f;
    ScaleMeasurement scaleBtData = new ScaleMeasurement();
    final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
    scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
    scaleBtData.setFat(fat);
    scaleBtData.setMuscle(muscle);
    scaleBtData.setWater(water);
    scaleBtData.setBone(bone);
    scaleBtData.setDateTime(new Date());
    addScaleData(scaleBtData);
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ScaleUser(com.health.openscale.core.datatypes.ScaleUser) Date(java.util.Date)

Example 17 with ScaleMeasurement

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

the class BluetoothHesley method parseBytes.

private void parseBytes(byte[] weightBytes) {
    // 10 ~ 99
    int bodyage = (int) (weightBytes[17]);
    // kg
    float weight = (float) (((weightBytes[2] & 0xFF) << 8) | (weightBytes[3] & 0xFF)) / 100.0f;
    // %
    float fat = (float) (((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f;
    // %
    float water = (float) (((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f;
    // %
    float muscle = (float) (((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / 10.0f;
    // %
    float bone = (float) (((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f;
    // kcal
    float calorie = (float) (((weightBytes[14] & 0xFF) << 8) | (weightBytes[15] & 0xFF));
    ScaleMeasurement scaleBtData = new ScaleMeasurement();
    scaleBtData.setWeight(weight);
    scaleBtData.setFat(fat);
    scaleBtData.setMuscle(muscle);
    scaleBtData.setWater(water);
    scaleBtData.setBone(bone);
    scaleBtData.setDateTime(new Date());
    addScaleData(scaleBtData);
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) Date(java.util.Date)

Example 18 with ScaleMeasurement

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

the class ScaleDatabase method readAtCursor.

private ScaleMeasurement readAtCursor(Cursor cur) {
    ScaleMeasurement scaleMeasurement = new ScaleMeasurement();
    try {
        scaleMeasurement.setId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_ID)));
        scaleMeasurement.setUserId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_USER_ID)));
        String date_time = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_DATE_TIME));
        scaleMeasurement.setWeight(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WEIGHT)));
        scaleMeasurement.setFat(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_FAT)));
        scaleMeasurement.setWater(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WATER)));
        scaleMeasurement.setMuscle(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_MUSCLE)));
        scaleMeasurement.setLbw(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_LBW)));
        scaleMeasurement.setBone(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_BONE)));
        scaleMeasurement.setWaist(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WAIST)));
        scaleMeasurement.setHip(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_HIP)));
        scaleMeasurement.setComment(cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_COMMENT)));
        scaleMeasurement.setDateTime(formatDateTime.parse(date_time));
    } catch (ParseException ex) {
        Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());
    } catch (IllegalArgumentException ex) {
        Log.e("ScaleDatabase", "Illegal argument while reading from scale database: " + ex.getMessage());
    }
    return scaleMeasurement;
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ParseException(java.text.ParseException)

Example 19 with ScaleMeasurement

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

the class ScaleDatabase method getScaleDataList.

public ArrayList<ScaleMeasurement> getScaleDataList(int userId) {
    ArrayList<ScaleMeasurement> scaleMeasurementList = new ArrayList<ScaleMeasurement>();
    try {
        String sortOrder = COLUMN_NAME_DATE_TIME + " DESC";
        Cursor cursorScaleDB = getReadableDatabase().query(// The table to query
        TABLE_NAME, // The columns to return
        projection, // The columns for the WHERE clause
        COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ENABLE + "=1", // The values for the WHERE clause
        new String[] { Integer.toString(userId) }, // don't group the rows
        null, // don't filter by row groups
        null, // The sort order
        sortOrder);
        cursorScaleDB.moveToFirst();
        while (!cursorScaleDB.isAfterLast()) {
            scaleMeasurementList.add(readAtCursor(cursorScaleDB));
            cursorScaleDB.moveToNext();
        }
        cursorScaleDB.close();
    } catch (SQLException ex) {
        Log.e("ScaleDatabase", "SQL exception occured while getting scale data list: " + ex.getMessage());
    }
    return scaleMeasurementList;
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) SQLException(android.database.SQLException) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 20 with ScaleMeasurement

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

the class CsvHelperTest method oldVersion10SingleEntry.

@Test
public void oldVersion10SingleEntry() throws Exception {
    final String data = "01.03.2018 12:45,8.0,2.0,7.0,some text\n";
    List<ScaleMeasurement> list = CsvHelper.importFrom(new BufferedReader(new StringReader(data)));
    assertEquals(1, list.size());
    validateEntry(list.get(0), 0);
}
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