Skip to content

Instantly share code, notes, and snippets.

@phillwiggins
Last active February 18, 2019 18:32
Show Gist options
  • Save phillwiggins/21a8a48aad4768b23ee4def3ef9247d0 to your computer and use it in GitHub Desktop.
Save phillwiggins/21a8a48aad4768b23ee4def3ef9247d0 to your computer and use it in GitHub Desktop.
Calculations on body fat vs calories
import 'dart:math';
import 'package:bodycal/src/domain/calculations/math_calculations.dart';
import 'package:bodycal/src/domain/calculations/measurement_conversions.dart';
import 'package:bodycal/src/domain/constants/keys_constants.dart';
import 'package:bodycal/src/domain/preferences/pref_fluid.dart';
import 'package:bodycal/src/domain/preferences/pref_gender.dart';
///Mifflin-St Jeor
///
///Mifflin-St Jeor equation is believed to give the most accurate result and it's
///what we use in this calculator. This BMR formula is as follows:
///
///BMR = (10 * weight / 1kg + 6.25 * height / 1cm - 5 * age / 1 year + s) kcal / day,
///where s is +5 for males and -161 for females.
Map<String, int> getBodyStatsUsingMifflinStJeor(Gender gender, double weightLB,
double heightCM, int age, double activityLevel) {
var bmr = 0;
var tdee = 0;
if (weightLB == 0.0 || heightCM == 0.0 || age == 0) {
return {keyTdee: tdee, keyBmr: bmr};
}
if (gender == Gender.female) {
bmr = (10 * convertLBtoKG(weightLB) +
6.25 * heightCM -
(5 * age).toDouble() -
161.0)
.toInt();
tdee = (bmr * activityLevel).toInt();
} else {
bmr =
(10 * convertLBtoKG(weightLB) + 6.25 * heightCM - 5 * age + 5).toInt();
tdee = (bmr * activityLevel).toInt();
}
return {keyTdee: tdee, keyBmr: bmr};
}
///Harris-Benedict
///
///The Harris Benedict Equation is a formula that uses your BMR and
///then applies an activity factor to determine your total daily energy expenditure (calories).
Map<String, int> getBodyStatsUsingHarrisBenedict(Gender gender, double weightLB,
double heightCM, int age, double activityLevel) {
var bmr = 0;
var tdee = 0;
if (weightLB == 0.0 || heightCM == 0.0 || age == 0) {
return {keyTdee: tdee, keyBmr: bmr};
}
if (gender == Gender.female) {
bmr = (655.1 +
9.563 * convertLBtoKG(weightLB) +
1.85 * heightCM -
4.676 * age)
.toInt();
tdee = (bmr * activityLevel).toInt();
} else {
bmr = (66.5 +
13.75 * convertLBtoKG(weightLB) +
5.003 * heightCM -
6.775 * age)
.toInt();
tdee = (bmr * activityLevel).toInt();
}
return {keyTdee: tdee, keyBmr: bmr};
}
/// Katch-Mcardle
///
///The Katch Mcardle Basal Metabolic Rate Calculator works by asking for the following
///information to be input:
///
///Weight (specified as either kilograms or pounds)
///Body Fat Percentage (in numeric form)
Map<String, int> getBodyStatsUsingKatchMcardle(double bodyFatPercent,
double weightLB, double heightCM, int age, double activityLevel) {
var leanBodyMass = 0.0;
var bmr = 0;
var tdee = 0;
if (weightLB == 0.0 || heightCM == 0.0 || age == 0) {
return {keyLeanBodyMass: leanBodyMass.toInt(), keyTdee: tdee, keyBmr: bmr};
}
leanBodyMass = convertLBtoKG(weightLB) * (100 - bodyFatPercent) / 100;
bmr = (370 + 21.6 * leanBodyMass).toInt();
tdee = (bmr * activityLevel).toInt();
return {
keyLeanBodyMass: convertKGtoLB(leanBodyMass).round(),
keyTdee: tdee,
keyBmr: bmr
};
}
/// Calorie loss/gain weekly
///
/// Calculate calorie loss based on weeks, percentage above or below and exercise
int getCaloriesLostOrGainedByWeek(int weeks, int percent,
int caloriesConsumedDaily, int caloriesBurntDailyDuringExercise) {
var percentage = percent;
var isLost = false;
var totalCaloriesLost = 0.0;
if (percent < 0) {
percentage = percent.abs();
isLost = true;
}
for (int i = 0; i < weeks; i++) {
totalCaloriesLost += ((percentage / 100) * caloriesConsumedDaily) * 7;
totalCaloriesLost += caloriesBurntDailyDuringExercise * 7;
}
if (isLost) {
totalCaloriesLost -= (totalCaloriesLost * 2);
}
return totalCaloriesLost.round();
}
/// Calorie loss/gain daily
///
/// Calculate calorie loss or gained in a day, percentage above or below and exercise
/// outputs the total calorie intake for the day
int caloriesReducedDaily(int percent, int caloriesConsumedDaily,
int caloriesBurntDailyDuringExercise) {
var percentage = percent;
var isLost = false;
var totalCaloriesLostOrGained = 0.0;
if (percent < 0) {
percentage = percentage.abs();
isLost = true;
}
totalCaloriesLostOrGained += ((percentage / 100) * caloriesConsumedDaily);
totalCaloriesLostOrGained += caloriesBurntDailyDuringExercise;
if (isLost) {
totalCaloriesLostOrGained -= (totalCaloriesLostOrGained * 2);
}
return caloriesConsumedDaily += totalCaloriesLostOrGained.round();
}
/// Calorie loss/gain daily without consumed
///
/// Calculate calorie loss or gained in a day, percentage above or below and exercise
/// outputs the total calorie intake for the day
int caloriesDailyDifference(int percent, int caloriesConsumedDaily,
int caloriesBurntDailyDuringExercise) {
var percentage = percent;
var isLost = false;
var totalCaloriesLostOrGained = 0.0;
if (percent < 0) {
percentage = percentage.abs();
isLost = true;
}
totalCaloriesLostOrGained += ((percentage / 100) * caloriesConsumedDaily);
totalCaloriesLostOrGained += caloriesBurntDailyDuringExercise;
if (isLost) {
totalCaloriesLostOrGained -= (totalCaloriesLostOrGained * 2);
}
return totalCaloriesLostOrGained.round();
}
/// Pounds loss/gained
///
/// Calculate pounds loss based on weeks, percentage above or below and exercise
double getPoundsLostOrGained(int weeks, int percent, int caloriesConsumedDaily,
int caloriesBurntDailyDuringExercise) {
var calories = getCaloriesLostOrGainedByWeek(
weeks, percent, caloriesConsumedDaily, caloriesBurntDailyDuringExercise);
return caloriesPerPound(calories);
}
/// Convert calories to pounds
///
/// Estimated amount of calories burnt to lose 1 pounds is 3500
double caloriesPerPound(int calories) => calories / 3500;
/// Convert calories to pounds
///
/// Estimated amount of calories burnt to lose 1 pounds is 3500
int poundsPerCalories(double pounds) => (pounds * 3500.0).round();
/// BMI
///
/// BMI is based on weight in LBS and height in CM
double getBmi(double weightLB, double heightCM) {
if (weightLB == 0.0 || heightCM == 0.0) {
return 0.0;
} else {
return decimalPlaces(
convertLBtoKG(weightLB) / ((heightCM / 100) * (heightCM / 100)), 1);
}
}
/// Lean Body Mass using body percent
///
/// Lean body mass based on bodyfat and weight
double getLeanBodyMassPercent(double weightLB, double bodyFatPercent) {
if (weightLB == 0.0 || bodyFatPercent == 0.0) {
return 0.0;
} else {
return (weightLB / 100) * (100 - bodyFatPercent);
}
}
/// Bodyfat % using BMI stats
///
/// Calculates body fat % based on a BMI
double getBodyFatUsingBMI(
Gender gender, int age, double weightLB, double heightCM) {
if (weightLB == 0.0 || heightCM == 0.0 || age == 0) {
return 0.0;
} else {
if (gender == Gender.female) {
return ((getBmi(weightLB, heightCM) * 1.2) + (age * 0.23) - 5.4);
} else {
return ((getBmi(weightLB, heightCM) * 1.2) + (age * 0.23) - 16.2);
}
}
}
/// Recommended water intake
///
/// Calculates recommended water intake based on body, age, exercise
int getRecommendedWaterIntake(Fluid waterPref, int minutesSpendExercisingPerDay,
double weightLB, int age) {
var waterNeedsOz = weightLB / 2.2;
var multipleFigure = 30;
if (age <= 30) {
multipleFigure = 40;
} else if (age > 30 && age <= 55) {
multipleFigure = 35;
} else {
multipleFigure = 30;
}
var waterInOz = (waterNeedsOz * multipleFigure) / 28.3;
var includingGymMinutes =
waterInOz + (minutesSpendExercisingPerDay / 30) * 12;
if (waterPref == Fluid.milliliters) {
return convertOZtoML(includingGymMinutes).toInt();
} else {
return includingGymMinutes.toInt();
}
}
/// Ideal weight (Robinson formula)
///
/// There many many ways to estimate the ideal weight.
/// Truth be told, none of them is perfectly accurate,
/// as there are a lot of factors influencing it.
///
/// formula = 52 kg + 1.9 kg per every inch over 5 feet
double getIdealWeightRobinson(double heightCM, Gender gender) {
var heightInInches = convertCMtoIN(heightCM);
if (heightInInches <= 59) return 0.0;
if (gender == Gender.female) {
return decimalPlaces(convertKGtoLB(((heightInInches - 60) * 1.7) + 49), 2);
} else {
return decimalPlaces(convertKGtoLB(((heightInInches - 60) * 1.9) + 52), 2);
}
}
/// Ideal weight (Miller formula)
///
/// formula = 56.2 kg + 1.41 kg per every inch over 5 feet
double getIdealWeightMiller(double heightCM, Gender gender) {
var heightInInches = convertCMtoIN(heightCM);
if (heightInInches <= 59) return 0.0;
if (gender == Gender.female) {
return decimalPlaces(
convertKGtoLB(((heightInInches - 60) * 1.36) + 53.1), 2);
} else {
return decimalPlaces(
convertKGtoLB(((heightInInches - 60) * 1.41) + 56.2), 2);
}
}
/// Ideal weight (Devine formula)
///
/// formula = 50.0 kg + 2.3 kg per every inch over 5 feet
double getIdealWeightDevine(double heightCM, Gender gender) {
var heightInInches = convertCMtoIN(heightCM);
if (heightInInches <= 59) return 0.0;
if (gender == Gender.female) {
return decimalPlaces(
convertKGtoLB(((heightInInches - 60) * 2.3) + 45.5), 2);
} else {
return decimalPlaces(convertKGtoLB(((heightInInches - 60) * 2.3) + 50), 2);
}
}
/// Ideal weight (Hamwi formula)
///
/// formula = 48.0 kg + 2.7 kg per every inch over 5 feet
double getIdealWeightHamwi(double heightCM, Gender gender) {
var heightInInches = convertCMtoIN(heightCM);
if (heightInInches <= 59) return 0.0;
if (gender == Gender.female) {
return decimalPlaces(
convertKGtoLB(((heightInInches - 60) * 2.2) + 45.5), 2);
} else {
return decimalPlaces(convertKGtoLB(((heightInInches - 60) * 2.7) + 48), 2);
}
}
/// Simple max heart rate
///
/// Calculates maximum heart rate based on age and gender - very inaccurate
int getSimpleMaxHearRate(int age, Gender gender) {
if (age == 0) return 0;
if (gender == Gender.female) {
return (209 - age * 0.7).toInt();
} else {
return (214 - age * 0.8).toInt();
}
}
List<double> getOneRepConfigs(double max, {List<double> customConfigs}) {
var configs = [1.035, 1.08, 1.115, 1.15, 1.18, 1.211, 1.22, 1.255, 1.325];
if (customConfigs != null) configs = customConfigs;
return [
max,
max / configs[0],
max / configs[1],
max / configs[2],
max / configs[3],
max / configs[4],
max / configs[5],
max / configs[6],
max / configs[7],
max / configs[8],
];
}
/// One rep max (Brzycki)
///
/// Calculates one rep max
List<double> getOneRepMaxBrzycki(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(weightLifted / (1.0278 - 0.0278 * repetitions),
customConfigs: customConfigs);
}
/// One rep max (Lombardi)
///
/// Calculates one rep max
List<double> getOneRepMaxLombardi(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(weightLifted * (pow((repetitions.toDouble()), 0.1)),
customConfigs: customConfigs);
}
/// One rep max (Mayhew)
///
/// Calculates one rep max
List<double> getOneRepMaxMayhew(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(
((100 * weightLifted) / (52.2 + (41.9 * exp((-0.055 * repetitions))))),
customConfigs: customConfigs);
}
/// One rep max (Wathen)
///
/// Calculates one rep max
List<double> getOneRepMaxWathen(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(
(100.0 * weightLifted) /
(48.8 + (53.8 * (exp((-0.075) * (repetitions))))),
customConfigs: customConfigs);
}
/// One rep max (Baechle)
///
/// Calculates one rep max
List<double> getOneRepMaxBaechle(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(weightLifted * (1 + (0.0333 * repetitions)),
customConfigs: customConfigs);
}
/// One rep max (Eply)
///
/// Calculates one rep max
List<double> getOneRepMaxEply(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs((0.033 * repetitions * weightLifted) + weightLifted,
customConfigs: customConfigs);
}
/// One rep max (Lander)
///
/// Calculates one rep max
List<double> getOneRepMaxLander(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(
(100 * weightLifted) / (101.3 - 2.67123 * repetitions),
customConfigs: customConfigs);
}
/// One rep max (OConner)
///
/// Calculates one rep max
List<double> getOneRepMaxOConner(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
return getOneRepConfigs(weightLifted * (1 + 0.025 * repetitions),
customConfigs: customConfigs);
}
/// One rep max (BodyCal)
///
/// Calculates one rep max based on most common calculations and amalgamates them
List<double> getOneRepMaxBodyCal(double weightLifted, int repetitions,
{List<double> customConfigs}) {
if (weightLifted == 0) return [];
var calculation = (getOneRepMaxBaechle(weightLifted, repetitions).first +
getOneRepMaxBrzycki(weightLifted, repetitions).first +
getOneRepMaxEply(weightLifted, repetitions).first +
getOneRepMaxLander(weightLifted, repetitions).first +
getOneRepMaxLombardi(weightLifted, repetitions).first +
getOneRepMaxMayhew(weightLifted, repetitions).first +
getOneRepMaxOConner(weightLifted, repetitions).first +
getOneRepMaxWathen(weightLifted, repetitions).first) /
8;
return getOneRepConfigs(calculation, customConfigs: customConfigs);
}
/// Body Fat Percentage Test Using Jackson-Pollock Formula 3
///
/// This calculation is used for females
///
/// the Jackson-Pollock-Ward formula, is: 1.0994921 -
/// (0.0009929 x the sum of the triceps, thigh and
/// suprailiac measurements) + (0.0000023 x the square of
/// the sum of the triceps, thigh and suprailiac measurements) -
/// (0.0001392 x age) = body density
Map<String, double> getJackson3Female(
int tricepMM, int subscapilliaMM, int thighMM, int age) {
if (tricepMM == 0 || subscapilliaMM == 0 || thighMM == 0 || age == 0)
return {keyDensity: 0.0, keyBodyFatPercentage: 0.0};
var sum = tricepMM + subscapilliaMM + thighMM;
var density = (1.0994921 -
(0.0009929 * sum) +
(0.0000023 * (sum * sum)) -
(0.0001392 * age));
return {
keyDensity: density,
keyBodyFatPercentage: getBodyFatPercentageFromDensity(density)
};
}
/// Body Fat Percentage Test Using Jackson-Pollock Formula 3
///
/// The formula for men is: 1.10938 - (0.0008267 x the sum of the
/// chest, abdomen and thigh measurements in millimeters) +
/// (0.0000016 x the square of the sum of the chest, abdomen and
/// thigh measurements in millimeters) - (0.0002574 x age) = body
/// density
Map<String, double> getJackson3Male(
int chestMM, int abdomenMM, int thighMM, int age) {
if (chestMM == 0 || abdomenMM == 0 || thighMM == 0 || age == 0)
return {keyDensity: 0.0, keyBodyFatPercentage: 0.0};
var sum = chestMM + abdomenMM + thighMM;
var density = (1.10938 -
(0.0008267 * sum) +
(0.0000016 * (sum * sum)) -
(0.0002574 * age));
return {
keyDensity: density,
keyBodyFatPercentage: getBodyFatPercentageFromDensity(density)
};
}
/// Body Fat Percentage Test Using Jackson-Pollock Formula 4
///
/// This calculation is used for females
///
/// Body Density = (0.29669 x sum of skinfolds) –
/// (0.00043 x square of the sum of skinfolds) +
/// (0.02963 x age) + 1.4072
///
/// Body Fat Percentage (%) = (495 / Body Density) – 450
double getJackson4Female(
int abdomenMM, int tricepMM, int thighMM, int suprailiacMM, int age) {
if (abdomenMM == 0 ||
tricepMM == 0 ||
thighMM == 0 ||
suprailiacMM == 0 ||
age == 0) return 0.0;
var sum = abdomenMM + tricepMM + thighMM + suprailiacMM;
return (0.29669 * sum) - (0.00043 * (sum * sum)) + (0.02963 * age) + 1.4072;
}
/// Body Fat Percentage Test Using Jackson-Pollock Formula 4
///
/// This calculation is used for males
///
/// Body Density = (0.29669 x sum of skinfolds) –
/// (0.00043 x square of the sum of skinfolds) +
/// (0.02963 x age) + 1.4072
///
/// Body Fat Percentage (%) = (495 / Body Density) – 450
double getJackson4Male(
int abdomenMM, int tricepMM, int thighMM, int suprailiacMM, int age) {
if (abdomenMM == 0 ||
tricepMM == 0 ||
thighMM == 0 ||
suprailiacMM == 0 ||
age == 0) return 0.0;
var sum = abdomenMM + tricepMM + thighMM + suprailiacMM;
return ((0.29288 * sum) - (0.00043 * (sum * sum)) + (0.15845 * age)) -
5.763772;
}
/// Body Fat Percentage Test Using Jackson-Pollock Formula 7
///
/// This calculation is used for males
///
/// Body Density = 1.112 – (0.00043499 x sum of skinfolds) +
/// (0.00000055 x square of the sum of skinfold sites) –
/// (0.00028826 x age)
///
/// Body Fat Percentage (%) = (495 / Body Density) – 450
Map<String, double> getJackson7Male(
int chestMM,
int axilaMM,
int tricepMM,
int subscapularMM,
int abdominalMM,
int suprailliacMM,
int thighMM,
int age) {
if (chestMM == 0 ||
axilaMM == 0 ||
tricepMM == 0 ||
subscapularMM == 0 ||
abdominalMM == 0 ||
suprailliacMM == 0 ||
thighMM == 0 ||
age == 0) return {keyDensity: 0.0, keyBodyFatPercentage: 0.0};
var sum = chestMM +
axilaMM +
tricepMM +
subscapularMM +
abdominalMM +
suprailliacMM +
thighMM;
var density = (1.112 -
(0.00043499 * sum) +
(0.00000055 * (sum * sum)) -
(0.00028826 * age));
return {
keyDensity: density,
keyBodyFatPercentage: getBodyFatPercentageFromDensity(density)
};
}
double getBodyFatPercentageFromDensity(double density) {
return ((4.95 / density) - 4.5) * 100;
}
/// Body Fat Percentage Test Using Jackson-Pollock Formula 7
///
/// This calculation is used for females
///
/// Body Density = 1.097 – (0.00046971 x sum of skinfolds) +
/// (0.00000056 x square of the sum of skinfold sites) –
/// (0.00012828 x age)
///
/// Body Fat Percentage (%) = (495 / Body Density) – 450
Map<String, double> getJackson7Female(
int chestMM,
int axilaMM,
int tricepMM,
int subscapularMM,
int abdominalMM,
int suprailliacMM,
int thighMM,
int age) {
if (chestMM == 0 ||
axilaMM == 0 ||
tricepMM == 0 ||
subscapularMM == 0 ||
abdominalMM == 0 ||
suprailliacMM == 0 ||
thighMM == 0 ||
age == 0) return {keyDensity: 0.0, keyBodyFatPercentage: 0.0};
var sum = chestMM +
axilaMM +
tricepMM +
subscapularMM +
abdominalMM +
suprailliacMM +
thighMM;
var density = (1.097 -
(0.00046971 * sum) +
(0.00000056 * (sum * sum)) -
(0.00012828 * age));
return {
keyDensity: density,
keyBodyFatPercentage: getBodyFatPercentageFromDensity(density)
};
}
///Parillo Body Fat Formula for Males and Females
///
/// Measure the following skinfolds (in millimeters) with body fat calipers:
/// Chest, Abdominal, Thigh, Bicep, Tricep, Subscapular, Suprailiac, Lower Back and Calf
///
/// Body Fat Percentage (%) = (27 x sum of skinfolds sites) divided by bodyweight (lbs)
double getParillo(
int chest,
int abdomen,
int thigh,
int bicep,
int tricep,
int subscapular,
int suprailiac,
int lowerBack,
int calf,
double bodyWeighLB) {
var sum = chest +
abdomen +
thigh +
bicep +
tricep +
subscapular +
suprailiac +
lowerBack +
calf;
return (27 * sum) / bodyWeighLB;
}
/// Body Density Equations: Durnin & Womersley Female
///
/// These formula developed by Durnin and Womersley (1974) can be used to
/// estimate body fat percentage using skinfold test results.
Map<String, double> getDurninFemale(
int tricepMM, int bicepMM, int subscapularMM, int suprailiacMM, int age) {
var sum = tricepMM + bicepMM + subscapularMM + suprailiacMM;
double density;
if (age <= 16) {
density = 1.1369 - (0.0598 * log10(sum));
} else if (age > 16 && age <= 20) {
density = 1.1549 - (0.0678 * log10(sum));
} else if (age > 20 && age <= 30) {
density = 1.1599 - 0.0717 * log10(sum);
} else if (age > 30 && age <= 40) {
density = 1.1423 - (0.0632 * log10(sum));
} else if (age > 40 && age <= 50) {
density = 1.1333 - (0.0612 * log10(sum));
} else {
density = 1.1339 - (0.0645 * log10(sum));
}
return {
keyDensity: density,
keyBodyFatPercentage: getBodyFatPercentageFromDensity(density)
};
}
/// Body Density Equations: Durnin & Womersley Male
///
/// These formula developed by Durnin and Womersley (1974) can be used to
/// estimate body fat percentage using skinfold test results.
Map<String, double> getDurninMale(
int tricepMM, int bicepMM, int subscapularMM, int suprailiacMM, int age) {
var sum = tricepMM + bicepMM + subscapularMM + suprailiacMM;
double density;
if (age <= 16) {
density = 1.1533 - (0.0643 * log10(sum));
} else if (age > 16 && age <= 20) {
density = 1.1620 - (0.0630 * log10(sum));
} else if (age > 20 && age <= 30) {
density = 1.1599 - 0.0717 * log10(sum);
} else if (age > 30 && age <= 40) {
density = 1.1423 - (0.0632 * log10(sum));
} else if (age > 40 && age <= 50) {
density = 1.1333 - (0.0612 * log10(sum));
} else {
density = 1.1339 - (0.0645 * log10(sum));
}
return {
keyDensity: density,
keyBodyFatPercentage: getBodyFatPercentageFromDensity(density)
};
}
/// Covert Bailey Body Fat Percentage Female
///
/// Women's Formula
/// To compute a woman's body fat percentage using this method, you will need to measure 4
/// different factors: A) Hips, B) Thigh, C) Calf, and D) Wrist. All measurements should be
/// taken at their widest points and should be recorded in inches.
///
/// Fat% = A+0.8B - 2C - D (for Women 30 years old or younger)
///
/// Fat% = A+ B - 2C - D (for Women over age 30)
double getCovertBaileyFemale(
int thighMM, int wristMM, int hipMM, int calfMM, int age) {
var thighIN = convertMMtoIN(thighMM);
var wristIN = convertMMtoIN(wristMM);
var hipIN = convertMMtoIN(hipMM);
var calfIN = convertMMtoIN(calfMM);
var bodyFatPercentage;
if (age <= 30) {
bodyFatPercentage = (hipIN + (0.8 * thighIN) - (2 * calfIN) - wristIN);
} else {
bodyFatPercentage = (hipIN + thighIN - (2 * calfIN) - wristIN).toDouble();
}
if (bodyFatPercentage < 0) {
bodyFatPercentage -= (bodyFatPercentage * 2);
}
return bodyFatPercentage;
}
/// Covert Bailey Body Fat Percentage Male
///
/// Mens Formula
/// The measurements needed to compute body fat percentage using the Covert Bailey Method for
/// a male are: A) Hips, B) Waist, C) Forearm Circumference, and D)Wrist.
/// All measurements should be taken at their widest points and should be recorded in inches.
///
/// Fat% = B + 0.5A - 3C - D (for Men 30 years old or younger)
///
/// Fat% = B + 0.5A - 2.7C - D (for Men over age 30)
double getCovertBaileyMale(
int hipMM, int waistMM, int forearmMM, int wristMM, int age) {
var hipIN = convertMMtoIN(hipMM);
var waistIN = convertMMtoIN(waistMM);
var forearmIN = convertMMtoIN(forearmMM);
var wristIN = convertMMtoIN(wristMM);
var bodyFatPercentage;
if (age <= 30) {
bodyFatPercentage = waistIN + (0.5 * hipIN) - (3 * forearmIN) - wristIN;
} else {
bodyFatPercentage = waistIN + (0.5 * hipIN) - (2.7 * forearmIN) - wristIN;
}
if (bodyFatPercentage < 0) {
bodyFatPercentage -= (bodyFatPercentage * 2);
}
return bodyFatPercentage;
}
/// US Navy Body Fat Percentage
///
/// Men's Formula
/// The measurements needed to compute body fat percentage using the
/// Department of Defense Method for a male are: A) Height,
/// B) Neck Circumference, and C) Waist (at navel).
/// All measurements are in inches.
///
// Fat% = 86.01 × Log10(C - B) - 70.041 × Log10(A) + 36.76
double getUSNavyMale(int waistMM, int neckMM, double heightCM) {
var waistIN = convertMMtoIN(waistMM);
var neckIN = convertMMtoIN(neckMM);
var heightIN = convertCMtoIN(heightCM);
return (86.010 * log10(waistIN - neckIN)) -
(70.041 * log10(heightIN)) +
36.76;
}
/// US Navy Body Fat Percentage
///
/// Female's Formula
/// The measurements needed to compute body fat percentage using the
/// Department of Defense Method for a male are: A) Height,
/// B) Neck Circumference, and C) Waist (at navel).
/// All measurements are in inches.
///
// Fat% = 86.01 × Log10(C - B) - 70.041 × Log10(A) + 36.76
double getUSNavyFemale(int waistMM, int hipMM, int neckMM, double heightCM) {
var waistIN = convertMMtoIN(waistMM);
var hipIN = convertMMtoIN(hipMM);
var neckIN = convertMMtoIN(neckMM);
var heightIN = convertCMtoIN(heightCM);
return (163.205 * log10(waistIN + hipIN - neckIN)) -
(97.684 * log10(heightIN)) -
78.387;
}
/// YMCA Body Fat Formula Male
///
/// The YMCA formula from the YMCA guide to Physical Fitness Assessment.
///
/// Men's %Fat = (-98.42 + 4.15*waist - .082 * weight) / weight*100
/// Women's %Fat = (-76.76 + 4.15 * waist - .082 * weight) / weight*100
double getYMCAMale(int waistMM, double weightLB) {
return (((4.15 * convertMMtoIN(waistMM)) - (0.082 * weightLB) - 98.42) *
100) /
weightLB;
}
/// YMCA Body Fat Formula Female
///
/// The YMCA formula from the YMCA guide to Physical Fitness Assessment.
///
/// Men's %Fat = (-98.42 + 4.15*waist - .082 * weight) / weight*100
/// Women's %Fat = (-76.76 + 4.15 * waist - .082 * weight) / weight*100
double getYMCAFemale(int waistMM, double weightLB) {
return (((4.15 * convertMMtoIN(waistMM)) - (0.082 * weightLB) - 76.76) *
100) /
weightLB;
}
/// Modified YMCA Body Fat Formula Male
///
/// The Modified YMCA formula from the YMCA guide to Physical Fitness Assessment.
double getModifiedYMCAMale(int waistMM, double weightLB) {
return 100 *
(4.15 * convertMMtoIN(waistMM) - 0.082 * weightLB - 94.42) /
weightLB;
}
/// Modified YMCA Body Fat Formula Female
///
/// The Modified YMCA formula from the YMCA guide to Physical Fitness Assessment.
double getModifiedYMCAFemale(
int wristMM, int waistMM, int hipMM, int forearmMM, double weightLB) {
var wristIN = convertMMtoIN(wristMM);
var waistIN = convertMMtoIN(waistMM);
var hipIN = convertMMtoIN(hipMM);
var forearmIN = convertMMtoIN(forearmMM);
return 100 *
(0.268 * weightLB -
0.318 * wristIN +
0.157 * waistIN +
0.245 * hipIN -
0.434 * forearmIN -
8.987) /
weightLB;
}
/// Londeree Heart Rate
///
/// A paper by Londeree and Moeschberger (1982)[2] from the University of Missouri-Columbia indicates that the
/// HRmax varies mostly with age, but the relationship is not a linear one. They suggest an alternative formula of
///
/// HRmax = 206.3 - (0.711 × Age)
double getHRLonderee(int age) {
return 206.3 - (0.711 * age);
}
/// Miller Heart Rate
///
/// A paper by Miller et al. (1993)[4] proposed the following formula as a suitable formula to calculate HRmax
///
/// HRmax = 217 - (0.85 x Age)
double getHRMiller(int age) {
return 206.9 - (0.85 * age);
}
/// USA Researchers Heart Rate
///
/// Evidence from USA researchers, Jackson et al. (2007)[5], identified the following formula as more
/// accurately reflecting the relationship between age and maximum heart rate.
///
/// HRmax = 206.9 - (0.67 x age)
double getHRUSA(int age) {
return 206.9 - (0.67 * age);
}
/// UK Researchers Heart Rate Male
///
/// Research by Whyte et al. (2008)[7] came up with with the following formulae for predicting
/// maximum heart rates in both endurance and anaerobically trained athletes:
///
/// Male athletes - HRmax = 202 - (0.55 x age)
double getHRUKMale(int age) {
return 202 - (0.55 * age);
}
/// UK Researchers Heart Rate Female
///
/// Research by Whyte et al. (2008)[7] came up with with the following formulae for predicting
/// maximum heart rates in both endurance and anaerobically trained athletes:
///
/// Female athletes - HRmax = 216 - (1.09 x age)
double getHRUKFemale(int age) {
return 216 - (1.09 * age);
}
/// Marthas Heart Rate Female
///
/// Research conducted by Gulati et al. (2010)[3] identified that the traditional male-based calculation (220-age)
/// overestimates the maximum heart rate for age in women. They investigated the association
/// between heart rate response to exercise testing and age with 5437 women. It was found that mean peak
/// heart rate for women = 206 - (0.88 x age).
double getHRMarthaFemale(int age) {
return 220 - age.toDouble();
}
/// Marthas Heart Rate Male
///
/// Research conducted by Gulati et al. (2010)[3] identified that the traditional male-based calculation (220-age)
/// overestimates the maximum heart rate for age in women. They investigated the association
/// between heart rate response to exercise testing and age with 5437 women. It was found that mean peak
/// heart rate for women = 206 - (0.88 x age).
double getHRMarthaMale(int age) {
return 217 - (0.85 * age);
}
/// BodyCal Heart Rate Male
double getHRMaxAverageMale(int age) {
return (getHRLonderee(age) +
getHRMiller(age) +
getHRUSA(age) +
getHRUKMale(age) +
getHRMarthaMale(age)) /
5;
}
/// BodyCal Heart Rate Male
double getHRMaxAverageFemale(int age) {
return (getHRLonderee(age) +
getHRMiller(age) +
getHRUSA(age) +
getHRUKFemale(age) +
getHRMarthaFemale(age)) /
5;
}
/// Calories burnt formula (Female)
///
/// We take in your average heart rate for an exercise, your age, your weight and calculate how many calories have been burnt
int getCaloriesBurntDuringExerciseFemale(
int averageHeartRate, double weightLB, int age, int time) {
var weightKG = convertLBtoKG(weightLB);
return ((((-55.0969 +
(0.6309 * averageHeartRate) +
(0.1988 * weightKG) +
(0.2017 * age)) /
4.184) *
60) *
(time / 60))
.toInt();
}
/// Calories burnt formula (Male)
///
/// We take in your average heart rate for an exercise, your age, your weight and calculate how many calories have been burnt
int getCaloriesBurntDuringExerciseMale(
int averageHeartRate, double weightLB, int age, int time) {
var weightKG = convertLBtoKG(weightLB);
return ((((-20.4022 +
(0.4472 * averageHeartRate) -
(0.1263 * weightKG) +
(0.074 * age)) /
4.184) *
60) *
(time / 60))
.toInt();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment