1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-12 11:44:19 +02:00

add option to average data points in the diagram for one day/month

make time and date editable on new measurement dialog
This commit is contained in:
OliE
2017-06-18 08:37:34 +02:00
parent 5212578892
commit cadedb9a60
6 changed files with 56 additions and 26 deletions

View File

@@ -258,8 +258,8 @@ public class DataEntryActivity extends Activity {
btnRight.setVisibility(View.GONE);
expandButton.setVisibility(View.GONE);
switchEditMode.setVisibility(View.GONE);
dateMeasurement.setVisibility(View.GONE);
timeMeasurement.setVisibility(View.GONE);
dateMeasurement.setVisibility(View.VISIBLE);
timeMeasurement.setVisibility(View.VISIBLE);
break;
}

View File

@@ -292,7 +292,7 @@ public class UserSettingsActivity extends Activity {
String date = txtBirthday.getText().toString();
String goal_date = txtGoalDate.getText().toString();
int id = -1;
int id = 0;
if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST)
{
@@ -302,7 +302,7 @@ public class UserSettingsActivity extends Activity {
{
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;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

View File

@@ -42,6 +42,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Stack;
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
import lecho.lib.hellocharts.listener.ColumnChartOnValueSelectListener;
@@ -81,6 +82,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
private Calendar calLastSelected;
private ArrayList<ScaleData> scaleDataList;
private ArrayList<ScaleData> pointIndexScaleDataList;
public GraphFragment() {
calYears = Calendar.getInstance();
@@ -174,54 +176,79 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
generateGraphs();
}
/**
* Add a point to a point value stack.
*
* Average y value of point if x value is already on the stack and option "averageData" is enabled.
*
* @param pointValues stack of point values
* @param value_x x value of the point
* @param value_y y value of the point
* @return true if a new point was added otherwise false if point was average added to an existing point
*/
private boolean addPointValue(Stack<PointValue> pointValues, float value_x, float value_y) {
if (prefs.getBoolean("averageData", true) && !pointValues.isEmpty() && pointValues.peek().getX() == value_x) {
pointValues.push(new PointValue(value_x, (pointValues.pop().getY() + value_y) / 2.0f));
} else {
if (value_y != 0.0f) { // don't show zero values
pointValues.add(new PointValue(value_x, value_y));
return true;
}
}
return false;
}
private void generateLineData(int field)
{
SimpleDateFormat day_date = new SimpleDateFormat("D", Locale.getDefault());
if (field == Calendar.DAY_OF_MONTH) {
day_date = new SimpleDateFormat("dd", Locale.getDefault());
} else if (field == Calendar.MONTH) {
day_date = new SimpleDateFormat("MMM", Locale.getDefault());
}
Calendar calDays = (Calendar)calLastSelected.clone();
calDays.set(field, 1);
calDays.set(field, calDays.getActualMinimum(field));
int maxDays = calDays.getActualMaximum(field);
List<AxisValue> axisValues = new ArrayList<AxisValue>();
for (int i=0; i<maxDays; i++) {
for (int i=0; i<maxDays+1; i++) {
String day_name = day_date.format(calDays.getTime());
axisValues.add(new AxisValue(i, day_name.toCharArray()));
axisValues.add(new AxisValue(i+calDays.getActualMinimum(field), day_name.toCharArray()));
calDays.add(field, 1);
}
List<PointValue> valuesWeight = new ArrayList<PointValue>();
List<PointValue> valuesFat = new ArrayList<PointValue>();
List<PointValue> valuesWater = new ArrayList<PointValue>();
List<PointValue> valuesMuscle = new ArrayList<PointValue>();
List<PointValue> valuesWaist = new ArrayList<PointValue>();
List<PointValue> valuesHip = new ArrayList<PointValue>();
Stack<PointValue> valuesWeight = new Stack<PointValue>();
Stack<PointValue> valuesFat = new Stack<PointValue>();
Stack<PointValue> valuesWater = new Stack<PointValue>();
Stack<PointValue> valuesMuscle = new Stack<PointValue>();
Stack<PointValue> valuesWaist = new Stack<PointValue>();
Stack<PointValue> valuesHip = new Stack<PointValue>();
List<Line> lines = new ArrayList<Line>();
Calendar calDB = Calendar.getInstance();
pointIndexScaleDataList = new ArrayList<>();
for(ScaleData scaleEntry: scaleDataList)
{
calDB.setTime(scaleEntry.getDateTime());
valuesWeight.add(new PointValue(calDB.get(field)-1, scaleEntry.getConvertedWeight(openScale.getSelectedScaleUser().scale_unit)));
if (scaleEntry.getFat() != 0.0f)
valuesFat.add(new PointValue(calDB.get(field)-1, scaleEntry.getFat()));
if (scaleEntry.getWater() != 0.0f)
valuesWater.add(new PointValue(calDB.get(field)-1, scaleEntry.getWater()));
if (scaleEntry.getMuscle() != 0.0f)
valuesMuscle.add(new PointValue(calDB.get(field)-1, scaleEntry.getMuscle()));
if (scaleEntry.getWaist() != 0.0f)
valuesWaist.add(new PointValue(calDB.get(field)-1, scaleEntry.getWaist()));
if (scaleEntry.getHip() != 0.0f)
valuesHip.add(new PointValue(calDB.get(field)-1, scaleEntry.getHip()));
if (addPointValue(valuesWeight, calDB.get(field), scaleEntry.getConvertedWeight(openScale.getSelectedScaleUser().scale_unit))) {
pointIndexScaleDataList.add(scaleEntry); // if new point was added, add this point to pointIndexScaleDataList to get the correct point index after selecting an point
}
addPointValue(valuesFat, calDB.get(field), scaleEntry.getFat());
addPointValue(valuesWater, calDB.get(field), scaleEntry.getWater());
addPointValue(valuesMuscle, calDB.get(field), scaleEntry.getMuscle());
addPointValue(valuesWaist, calDB.get(field), scaleEntry.getWaist());
addPointValue(valuesHip, calDB.get(field), scaleEntry.getHip());
}
@@ -375,7 +402,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
scaleDataList = openScale.getScaleDataOfYear(calYears.get(Calendar.YEAR));
generateLineData(Calendar.DAY_OF_YEAR);
generateLineData(Calendar.MONTH);
}
}
@@ -414,7 +441,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
private class chartBottomValueTouchListener implements LineChartOnValueSelectListener {
@Override
public void onValueSelected(int lineIndex, int pointIndex, PointValue pointValue) {
ScaleData scaleData = scaleDataList.get(pointIndex);
ScaleData scaleData = pointIndexScaleDataList.get(pointIndex);
long id = scaleData.getId();

View File

@@ -130,4 +130,5 @@
<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>
<string name="label_average_data">Berechne Durchschnitt pro Tag/Monat</string>
</resources>

View File

@@ -149,4 +149,5 @@
<string name="label_not_found">not found</string>
<string name="label_ignoreOutOfRange">Ignore data that are out of range</string>
<string name="label_initial_weight">Initial weight</string>
<string name="label_average_data">Calculate average per day/month</string>
</resources>

View File

@@ -3,4 +3,5 @@
<CheckBoxPreference android:title="@string/label_enable_labels" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="labelsEnable" android:defaultValue="true"/>
<CheckBoxPreference android:title="@string/label_enable_points" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="pointsEnable" android:defaultValue="true"/>
<CheckBoxPreference android:title="@string/label_delete_confirmation" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="deleteConfirmationEnable" android:defaultValue="true" />
<CheckBoxPreference android:title="@string/label_average_data" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="averageData" android:defaultValue="true" />
</PreferenceScreen>