1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-30 11:40:23 +02:00

Add option to estimate LBM based on weight - fat

As requested in #255.
This commit is contained in:
Erik Johansson
2018-05-02 20:55:34 +02:00
parent f71bc16594
commit 4753e66981
6 changed files with 63 additions and 12 deletions

View File

@@ -286,13 +286,6 @@ public class OpenScale {
scaleMeasurement.setWater(waterMetric.getWater(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
}
settings = new MeasurementViewSettings(prefs, LBMMeasurementView.KEY);
if (settings.isEnabled() && settings.isEstimationEnabled()) {
EstimatedLBMMetric lbmMetric = EstimatedLBMMetric.getEstimatedMetric(
EstimatedLBMMetric.FORMULA.valueOf(settings.getEstimationFormula()));
scaleMeasurement.setLbm(lbmMetric.getLBM(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
}
settings = new MeasurementViewSettings(prefs, FatMeasurementView.KEY);
if (settings.isEnabled() && settings.isEstimationEnabled()) {
EstimatedFatMetric fatMetric = EstimatedFatMetric.getEstimatedMetric(
@@ -300,6 +293,14 @@ public class OpenScale {
scaleMeasurement.setFat(fatMetric.getFat(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
}
// Must be after fat estimation as one formula is based on fat
settings = new MeasurementViewSettings(prefs, LBMMeasurementView.KEY);
if (settings.isEnabled() && settings.isEstimationEnabled()) {
EstimatedLBMMetric lbmMetric = EstimatedLBMMetric.getEstimatedMetric(
EstimatedLBMMetric.FORMULA.valueOf(settings.getEstimationFormula()));
scaleMeasurement.setLbm(lbmMetric.getLBM(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
}
if (measurementDAO.insert(scaleMeasurement) != -1) {
ScaleUser scaleUser = getScaleUser(scaleMeasurement.getUserId());

View File

@@ -15,12 +15,14 @@
*/
package com.health.openscale.core.bodymetric;
import android.content.Context;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
public abstract class EstimatedLBMMetric {
// Don't change enum names, they are stored persistent in preferences
public enum FORMULA { LBW_HUME, LBW_BOER }
public enum FORMULA { LBW_HUME, LBW_BOER, LBW_WEIGHT_MINUS_FAT }
public static EstimatedLBMMetric getEstimatedMetric(FORMULA metric) {
switch (metric) {
@@ -28,11 +30,13 @@ public abstract class EstimatedLBMMetric {
return new LBMHume();
case LBW_BOER:
return new LBMBoer();
case LBW_WEIGHT_MINUS_FAT:
return new LBMWeightMinusFat();
}
return null;
}
public abstract String getName();
public abstract String getName(Context context);
public abstract float getLBM(ScaleUser user, ScaleMeasurement data);
}

View File

@@ -16,12 +16,14 @@
package com.health.openscale.core.bodymetric;
import android.content.Context;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
public class LBMBoer extends EstimatedLBMMetric {
@Override
public String getName() {
public String getName(Context context) {
return "Boer (1984)";
}

View File

@@ -16,12 +16,14 @@
package com.health.openscale.core.bodymetric;
import android.content.Context;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
public class LBMHume extends EstimatedLBMMetric {
@Override
public String getName() {
public String getName(Context context) {
return "Hume (1966)";
}

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 2018 Erik Johansson <erik@ejohansson.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.health.openscale.core.bodymetric;
import android.content.Context;
import com.health.openscale.R;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
class LBMWeightMinusFat extends EstimatedLBMMetric {
@Override
public String getName(Context context) {
return String.format("%s - %s",
context.getResources().getString(R.string.label_weight),
context.getResources().getString(R.string.label_fat));
}
@Override
public float getLBM(ScaleUser user, ScaleMeasurement data) {
if (data.getFat() == 0) {
return 0;
}
float absFat = data.getWeight() * data.getFat() / 100.0f;
return data.getWeight() - absFat;
}
}

View File

@@ -75,7 +75,7 @@ public class LBMMeasurementView extends FloatMeasurementView {
int idx = 0;
for (EstimatedLBMMetric.FORMULA formula : EstimatedLBMMetric.FORMULA.values()) {
entries[idx] = EstimatedLBMMetric.getEstimatedMetric(formula).getName();
entries[idx] = EstimatedLBMMetric.getEstimatedMetric(formula).getName(getContext());
values[idx] = formula.name();
++idx;
}