1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 16:53:04 +02:00

for smart assigning to the correct user if no weight data is available an initial weight field has been added.

This commit is contained in:
OliE
2017-06-10 13:58:50 +02:00
parent 870d6ed08e
commit 13f45072fd
9 changed files with 68 additions and 12 deletions

View File

@@ -90,7 +90,7 @@ public class OpenScale {
return instance; return instance;
} }
public void addScaleUser(String name, String birthday, int body_height, int scale_unit, int gender, float goal_weight, String goal_date) public void addScaleUser(String name, String birthday, int body_height, int scale_unit, int gender, float initial_weight, float goal_weight, String goal_date)
{ {
ScaleUser scaleUser = new ScaleUser(); ScaleUser scaleUser = new ScaleUser();
@@ -100,6 +100,7 @@ public class OpenScale {
scaleUser.body_height = body_height; scaleUser.body_height = body_height;
scaleUser.scale_unit = scale_unit; scaleUser.scale_unit = scale_unit;
scaleUser.gender = gender; scaleUser.gender = gender;
scaleUser.initial_weight = initial_weight;
scaleUser.goal_weight = goal_weight; scaleUser.goal_weight = goal_weight;
scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date); scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date);
@@ -139,7 +140,7 @@ public class OpenScale {
scaleUserDB.deleteEntry(id); scaleUserDB.deleteEntry(id);
} }
public void updateScaleUser(int id, String name, String birthday, int body_height, int scale_unit, int gender, float goal_weight, String goal_date) public void updateScaleUser(int id, String name, String birthday, int body_height, int scale_unit, int gender, float initial_weight, float goal_weight, String goal_date)
{ {
ScaleUser scaleUser = new ScaleUser(); ScaleUser scaleUser = new ScaleUser();
@@ -150,6 +151,7 @@ public class OpenScale {
scaleUser.body_height = body_height; scaleUser.body_height = body_height;
scaleUser.scale_unit = scale_unit; scaleUser.scale_unit = scale_unit;
scaleUser.gender = gender; scaleUser.gender = gender;
scaleUser.initial_weight = initial_weight;
scaleUser.goal_weight = goal_weight; scaleUser.goal_weight = goal_weight;
scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date); scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date);
} catch (ParseException e) { } catch (ParseException e) {
@@ -202,14 +204,18 @@ public class OpenScale {
for (int i = 0; i < scaleUser.size(); i++) { for (int i = 0; i < scaleUser.size(); i++) {
ArrayList<ScaleData> scaleUserData = scaleDB.getScaleDataList(scaleUser.get(i).id); ArrayList<ScaleData> scaleUserData = scaleDB.getScaleDataList(scaleUser.get(i).id);
float lastWeight = 0;
if (scaleUserData.size() > 0) { if (scaleUserData.size() > 0) {
float lastWeight = scaleUserData.get(0).getWeight(); lastWeight = scaleUserData.get(0).getWeight();
} else {
lastWeight = scaleUser.get(i).initial_weight;
}
if ((lastWeight - range) <= weight && (lastWeight + range) >= weight) { if ((lastWeight - range) <= weight && (lastWeight + range) >= weight) {
inRangeWeights.put(Math.abs(lastWeight - weight), scaleUser.get(i).id); inRangeWeights.put(Math.abs(lastWeight - weight), scaleUser.get(i).id);
} }
} }
}
if (inRangeWeights.size() > 0) { if (inRangeWeights.size() > 0) {
// return the user id which is nearest to the weight (first element of the tree map) // return the user id which is nearest to the weight (first element of the tree map)

View File

@@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
public class ScaleUserDatabase extends SQLiteOpenHelper { public class ScaleUserDatabase extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 2; private static final int DATABASE_VERSION = 3;
private static final String DATABASE_NAME = "openScaleUserDatabase.db"; private static final String DATABASE_NAME = "openScaleUserDatabase.db";
private static final String TABLE_NAME = "scaleuserdata"; private static final String TABLE_NAME = "scaleuserdata";
@@ -42,6 +42,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
private static final String COLUMN_NAME_BODY_HEIGHT = "body_height"; private static final String COLUMN_NAME_BODY_HEIGHT = "body_height";
private static final String COLUMN_NAME_SCALE_UNIT = "scale_unit"; private static final String COLUMN_NAME_SCALE_UNIT = "scale_unit";
private static final String COLUMN_NAME_GENDER = "gender"; private static final String COLUMN_NAME_GENDER = "gender";
private static final String COLUMN_NAME_INITIAL_WEIGHT = "initial_weight";
private static final String COLUMN_NAME_GOAL_WEIGHT = "goal_weight"; private static final String COLUMN_NAME_GOAL_WEIGHT = "goal_weight";
private static final String COLUMN_NAME_GOAL_DATE = "goal_date"; private static final String COLUMN_NAME_GOAL_DATE = "goal_date";
@@ -53,6 +54,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
COLUMN_NAME_BODY_HEIGHT + " INTEGER," + COLUMN_NAME_BODY_HEIGHT + " INTEGER," +
COLUMN_NAME_SCALE_UNIT + " INTEGER," + COLUMN_NAME_SCALE_UNIT + " INTEGER," +
COLUMN_NAME_GENDER + " INTEGER," + COLUMN_NAME_GENDER + " INTEGER," +
COLUMN_NAME_INITIAL_WEIGHT + " REAL," +
COLUMN_NAME_GOAL_WEIGHT + " REAL," + COLUMN_NAME_GOAL_WEIGHT + " REAL," +
COLUMN_NAME_GOAL_DATE + " TEXT" + COLUMN_NAME_GOAL_DATE + " TEXT" +
")"; ")";
@@ -67,6 +69,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
COLUMN_NAME_BODY_HEIGHT, COLUMN_NAME_BODY_HEIGHT,
COLUMN_NAME_SCALE_UNIT, COLUMN_NAME_SCALE_UNIT,
COLUMN_NAME_GENDER, COLUMN_NAME_GENDER,
COLUMN_NAME_INITIAL_WEIGHT,
COLUMN_NAME_GOAL_WEIGHT, COLUMN_NAME_GOAL_WEIGHT,
COLUMN_NAME_GOAL_DATE COLUMN_NAME_GOAL_DATE
}; };
@@ -89,6 +92,10 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_GOAL_WEIGHT + " REAL DEFAULT 0"); db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_GOAL_WEIGHT + " REAL DEFAULT 0");
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_GOAL_DATE + " TEXT DEFAULT '2014-01-01 00:00'"); db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_GOAL_DATE + " TEXT DEFAULT '2014-01-01 00:00'");
} }
if (oldVersion == 2 && newVersion == 3) {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_INITIAL_WEIGHT + " REAL DEFAULT 0");
}
} }
public void clearDatabase() { public void clearDatabase() {
@@ -106,6 +113,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height); values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit); values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
values.put(COLUMN_NAME_GENDER, scaleUser.gender); values.put(COLUMN_NAME_GENDER, scaleUser.gender);
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.initial_weight);
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight); values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date)); values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
@@ -138,6 +146,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height); values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit); values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
values.put(COLUMN_NAME_GENDER, scaleUser.gender); values.put(COLUMN_NAME_GENDER, scaleUser.gender);
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.initial_weight);
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight); values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date)); values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
@@ -206,12 +215,14 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
scaleUser.body_height = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_BODY_HEIGHT)); scaleUser.body_height = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_BODY_HEIGHT));
scaleUser.scale_unit = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_SCALE_UNIT)); scaleUser.scale_unit = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_SCALE_UNIT));
scaleUser.gender = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_GENDER)); scaleUser.gender = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_GENDER));
double initial_weight = cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_INITIAL_WEIGHT));
double goal_weight = cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_GOAL_WEIGHT)); double goal_weight = cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_GOAL_WEIGHT));
String goal_date = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_GOAL_DATE)); String goal_date = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_GOAL_DATE));
scaleUser.birthday = formatDateTime.parse(birthday); scaleUser.birthday = formatDateTime.parse(birthday);
scaleUser.goal_date = formatDateTime.parse(goal_date); scaleUser.goal_date = formatDateTime.parse(goal_date);
scaleUser.initial_weight = Math.round(initial_weight * 100.0f) / 100.0f;
scaleUser.goal_weight = Math.round(goal_weight * 100.0f) / 100.0f; scaleUser.goal_weight = Math.round(goal_weight * 100.0f) / 100.0f;
} catch (ParseException ex) { } catch (ParseException ex) {
Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage()); Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());

View File

@@ -27,6 +27,7 @@ public class ScaleUser {
public int body_height; public int body_height;
public int scale_unit; public int scale_unit;
public int gender; public int gender;
public float initial_weight;
public float goal_weight; public float goal_weight;
public Date goal_date; public Date goal_date;
@@ -37,6 +38,7 @@ public class ScaleUser {
body_height = -1; body_height = -1;
scale_unit = 0; scale_unit = 0;
gender = 0; gender = 0;
initial_weight = -1;
goal_weight = -1; goal_weight = -1;
goal_date = new Date(); goal_date = new Date();
} }
@@ -52,6 +54,6 @@ public class ScaleUser {
@Override @Override
public String toString() public String toString()
{ {
return "ID : " + id + " NAME: " + user_name + " BIRTHDAY: " + birthday.toString() + " BODY_HEIGHT: " + body_height + " SCALE_UNIT: " + UNIT_STRING[scale_unit] + " GENDER " + gender + " GOAL WEIGHT " + goal_weight + " GOAL DATE " + goal_date.toString(); return "ID : " + id + " NAME: " + user_name + " BIRTHDAY: " + birthday.toString() + " BODY_HEIGHT: " + body_height + " SCALE_UNIT: " + UNIT_STRING[scale_unit] + " GENDER " + gender + " INITIAL WEIGHT " + initial_weight + " GOAL WEIGHT " + goal_weight + " GOAL DATE " + goal_date.toString();
} }
} }

View File

@@ -47,6 +47,7 @@ public class UserSettingsActivity extends Activity {
private EditText txtUserName; private EditText txtUserName;
private EditText txtBodyHeight; private EditText txtBodyHeight;
private EditText txtBirthday; private EditText txtBirthday;
private EditText txtInitialWeight;
private EditText txtGoalWeight; private EditText txtGoalWeight;
private EditText txtGoalDate; private EditText txtGoalDate;
private RadioGroup radioScaleUnit; private RadioGroup radioScaleUnit;
@@ -70,6 +71,7 @@ public class UserSettingsActivity extends Activity {
txtBodyHeight = (EditText) findViewById(R.id.txtBodyHeight); txtBodyHeight = (EditText) findViewById(R.id.txtBodyHeight);
radioScaleUnit = (RadioGroup) findViewById(R.id.groupScaleUnit); radioScaleUnit = (RadioGroup) findViewById(R.id.groupScaleUnit);
radioGender = (RadioGroup) findViewById(R.id.groupGender); radioGender = (RadioGroup) findViewById(R.id.groupGender);
txtInitialWeight = (EditText) findViewById(R.id.txtInitialWeight);
txtGoalWeight = (EditText) findViewById(R.id.txtGoalWeight); txtGoalWeight = (EditText) findViewById(R.id.txtGoalWeight);
txtBirthday = (EditText) findViewById(R.id.txtBirthday); txtBirthday = (EditText) findViewById(R.id.txtBirthday);
@@ -131,6 +133,7 @@ public class UserSettingsActivity extends Activity {
txtBodyHeight.setText(Integer.toString(scaleUser.body_height)); txtBodyHeight.setText(Integer.toString(scaleUser.body_height));
txtBirthday.setText(dateFormat.format(scaleUser.birthday)); txtBirthday.setText(dateFormat.format(scaleUser.birthday));
txtGoalDate.setText(dateFormat.format(scaleUser.goal_date)); txtGoalDate.setText(dateFormat.format(scaleUser.goal_date));
txtInitialWeight.setText(scaleUser.initial_weight+"");
txtGoalWeight.setText(scaleUser.goal_weight+""); txtGoalWeight.setText(scaleUser.goal_weight+"");
switch (scaleUser.scale_unit) switch (scaleUser.scale_unit)
@@ -173,6 +176,12 @@ public class UserSettingsActivity extends Activity {
validate = false; validate = false;
} }
if( txtInitialWeight.getText().toString().length() == 0 )
{
txtInitialWeight.setError(getResources().getString(R.string.error_initial_weight_required));
validate = false;
}
if( txtGoalWeight.getText().toString().length() == 0 ) if( txtGoalWeight.getText().toString().length() == 0 )
{ {
txtGoalWeight.setError(getResources().getString(R.string.error_goal_weight_required)); txtGoalWeight.setError(getResources().getString(R.string.error_goal_weight_required));
@@ -252,6 +261,7 @@ public class UserSettingsActivity extends Activity {
int body_height = Integer.valueOf(txtBodyHeight.getText().toString()); int body_height = Integer.valueOf(txtBodyHeight.getText().toString());
int checkedRadioButtonId = radioScaleUnit.getCheckedRadioButtonId(); int checkedRadioButtonId = radioScaleUnit.getCheckedRadioButtonId();
int checkedGenderId = radioGender.getCheckedRadioButtonId(); int checkedGenderId = radioGender.getCheckedRadioButtonId();
float initial_weight = Float.valueOf(txtInitialWeight.getText().toString());
float goal_weight = Float.valueOf(txtGoalWeight.getText().toString()); float goal_weight = Float.valueOf(txtGoalWeight.getText().toString());
int scale_unit = -1; int scale_unit = -1;
@@ -287,10 +297,10 @@ public class UserSettingsActivity extends Activity {
if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST) if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST)
{ {
id = getIntent().getExtras().getInt("id"); id = getIntent().getExtras().getInt("id");
openScale.updateScaleUser(id, name, date, body_height, scale_unit, gender, goal_weight, goal_date); openScale.updateScaleUser(id, name, date, body_height, scale_unit, gender, initial_weight, goal_weight, goal_date);
} else } else
{ {
openScale.addScaleUser(name, date, body_height, scale_unit, gender, goal_weight, goal_date); openScale.addScaleUser(name, date, body_height, scale_unit, gender, initial_weight, goal_weight, goal_date);
id = openScale.getScaleUserList().get(openScale.getScaleUserList().size()-1).id; id = openScale.getScaleUserList().get(openScale.getScaleUserList().size()-1).id;
} }

View File

@@ -162,6 +162,25 @@
</TableRow> </TableRow>
<TableRow
android:id="@+id/tableRowInitialWeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_initial_weight" />
<EditText
android:id="@+id/txtInitialWeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/info_enter_initial_weight"
android:inputType="numberDecimal|numberSigned" />
</TableRow>
<TableRow <TableRow
android:id="@+id/tableRow6" android:id="@+id/tableRow6"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -14,7 +14,6 @@
<string name="info_delete_bluetooth_data">Lösche alle Bluetooth Daten</string> <string name="info_delete_bluetooth_data">Lösche alle Bluetooth Daten</string>
<string name="info_delete_bluetooth_data_success">Bluetooth Daten wurden erfolgreich gelöscht</string> <string name="info_delete_bluetooth_data_success">Bluetooth Daten wurden erfolgreich gelöscht</string>
<string name="info_enter_comment">Gebe ein optionalen Kommentar ein</string> <string name="info_enter_comment">Gebe ein optionalen Kommentar ein</string>
<string name="info_enter_goal_weight">Gebe dein Gewicht in deiner Einheit an</string>
<string name="info_enter_user_name">Gebe dein Namen ein</string> <string name="info_enter_user_name">Gebe dein Namen ein</string>
<string name="info_enter_value_cm">Gebe dein Wert in cm an</string> <string name="info_enter_value_cm">Gebe dein Wert in cm an</string>
<string name="info_enter_value_percent">Gebe dein Wert in % an</string> <string name="info_enter_value_percent">Gebe dein Wert in % an</string>
@@ -127,4 +126,8 @@
<string name="label_export_dir">Export Ordner</string> <string name="label_export_dir">Export Ordner</string>
<string name="label_not_found">nicht gefunden</string> <string name="label_not_found">nicht gefunden</string>
<string name="label_ignoreOutOfRange">Ignoriere Daten außerhalb des zulässigen Bereiches</string> <string name="label_ignoreOutOfRange">Ignoriere Daten außerhalb des zulässigen Bereiches</string>
<string name="label_initial_weight">Anfangsgewicht</string>
<string name="info_enter_initial_weight">Gebe dein Gewicht in deiner Einheit an</string>
<string name="info_enter_goal_weight">Gebe dein Gewicht in deiner Einheit an</string>
<string name="error_initial_weight_required">Fehler Anfangsgewicht ist erforderlich</string>
</resources> </resources>

View File

@@ -136,4 +136,5 @@
<string name="Saturday">Samedi</string> <string name="Saturday">Samedi</string>
<string name="Sunday">Dimanche</string> <string name="Sunday">Dimanche</string>
<string name="title_statistics">Statistiques</string> <string name="title_statistics">Statistiques</string>
<string name="info_enter_initial_weight">Entrez votre objectif de poids dans votre unité d\'échelle</string>
</resources> </resources>

View File

@@ -117,4 +117,5 @@
<string name="error_value_required">値が必要です</string> <string name="error_value_required">値が必要です</string>
<string name="error_value_range">エラー値の範囲</string> <string name="error_value_range">エラー値の範囲</string>
<string name="title_statistics">統計</string> <string name="title_statistics">統計</string>
<string name="info_enter_initial_weight">あなたの体重をあなたの単位で入力してください</string>
</resources> </resources>

View File

@@ -70,6 +70,7 @@
<string name="error_importing">Error importing</string> <string name="error_importing">Error importing</string>
<string name="error_user_name_required">Error user name is required</string> <string name="error_user_name_required">Error user name is required</string>
<string name="error_body_height_required">Error body height is required</string> <string name="error_body_height_required">Error body height is required</string>
<string name="error_initial_weight_required">Error initial weight is required</string>
<string name="error_goal_weight_required">Error goal weight is required</string> <string name="error_goal_weight_required">Error goal weight is required</string>
<string name="error_hip_value_required">hip circumference is required</string> <string name="error_hip_value_required">hip circumference is required</string>
@@ -82,6 +83,7 @@
<string name="info_enter_value_percent">Enter value in %</string> <string name="info_enter_value_percent">Enter value in %</string>
<string name="info_enter_value_unit">Enter value in</string> <string name="info_enter_value_unit">Enter value in</string>
<string name="info_enter_comment">Enter an optional comment</string> <string name="info_enter_comment">Enter an optional comment</string>
<string name="info_enter_initial_weight">Enter your initial weight in your scale unit</string>
<string name="info_enter_goal_weight">Enter your goal weight in your scale unit</string> <string name="info_enter_goal_weight">Enter your goal weight in your scale unit</string>
<string name="info_is_visible">is visible</string> <string name="info_is_visible">is visible</string>
<string name="info_is_not_visible">is not visible</string> <string name="info_is_not_visible">is not visible</string>
@@ -146,4 +148,5 @@
<string name="label_export_dir">Export dir</string> <string name="label_export_dir">Export dir</string>
<string name="label_not_found">not found</string> <string name="label_not_found">not found</string>
<string name="label_ignoreOutOfRange">Ignore data that are out of range</string> <string name="label_ignoreOutOfRange">Ignore data that are out of range</string>
<string name="label_initial_weight">Initial weight</string>
</resources> </resources>