Skip to content

Instantly share code, notes, and snippets.

@ROTGP
Created September 24, 2018 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ROTGP/8f3620423a8383c736b3498c26177aaa to your computer and use it in GitHub Desktop.
Save ROTGP/8f3620423a8383c736b3498c26177aaa to your computer and use it in GitHub Desktop.
Dart utils for calculating recommended calorie intake based on the Mifflin St Jeor equation
class ActivityLevel {
static const NONE = const ActivityLevel._(1.0);
static const SEDENTARY = const ActivityLevel._(1.2);
static const LIGHT = const ActivityLevel._(1.375);
static const MODERATE = const ActivityLevel._(1.55);
static const NORMAL = const ActivityLevel._(1.725);
static const VERY = const ActivityLevel._(1.9);
static get values => [NONE, SEDENTARY, LIGHT, MODERATE, NORMAL, VERY];
final double value;
const ActivityLevel._(this.value);
}
enum Gender { male, female }
class Utils {
/// https://wpcalc.com/en/mifflin-st-jeor/
/// https://www.dummies.com/health/nutrition/how-to-calculate-your-metabolic-rate/
static double mifflinStJeor(Gender gender, double kg, double cm, double years, ActivityLevel activityLevel) {
return ((((10.0 * kg) + (6.25 * cm) - (5.0 * years)) + (gender == Gender.male ? 5 : -161)) * activityLevel.value).roundToDouble();
}
/// https://www.healthline.com/nutrition/how-many-calories-per-day
static List<double> calculateIntakes(Gender gender, double kg, double cm, double years, ActivityLevel activityLevel) {
double bmi = mifflinStJeor(gender, kg, cm, years, activityLevel);
double loseWeight = (bmi * 0.8).roundToDouble();
double loseWeightFast = (bmi * 0.6).roundToDouble();
if (bmi < 1000 || (bmi * 0.8) < 1000 || (bmi * 0.6) < 1000) {
bmi = bmi < 1000.0 ? 1000.0 : bmi = bmi.roundToDouble();
loseWeight = (bmi * 0.8) < 1000 ? 1000.0 : (bmi * 0.8).roundToDouble();
loseWeightFast = (bmi * 0.6) < 1000 ? 1000.0 : (bmi * 0.6).roundToDouble();
}
return [bmi, loseWeight, loseWeightFast];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment