Example #1
0
        public UserGoalModel GetUserGoal()
        {
            GoalType       goalType       = default(GoalType);
            GoalTimePeriod goalTimePeriod = default(GoalTimePeriod);
            int            goalPeriod     = 0;
            decimal        loseGainWeitgh = 0;

            goalType       = (GoalType)Settings.GetValueOrDefault(GOAL_TYPE, (int)goalType);
            goalTimePeriod = (GoalTimePeriod)Settings.GetValueOrDefault(GOAL_TIME_PERIOD, (int)goalTimePeriod);
            goalPeriod     = Settings.GetValueOrDefault(GOAL_PERIOD, goalPeriod);
            loseGainWeitgh = Settings.GetValueOrDefault(GOAL_LOSE_GAIN, loseGainWeitgh);
            return(new UserGoalModel(goalType, goalTimePeriod, goalPeriod, loseGainWeitgh));
        }
Example #2
0
        private int WeightChangePeriodToDays(GoalTimePeriod timePeriod, int periodNumber)
        {
            switch (timePeriod)
            {
            case GoalTimePeriod.Days:
                return(periodNumber);

            case GoalTimePeriod.Weeks:
                return(periodNumber * 7);

            case GoalTimePeriod.Months:
                return(Convert.ToInt32(periodNumber * 30.4));

            case GoalTimePeriod.Years:
                return(periodNumber * 365);

            default: return(0);
            }
        }
Example #3
0
        public WeightChangeEstimationResult CalculateWeightChangeEstimation(int age, decimal height, decimal weight, Gender gender, ActivityLevel activityFactor, GoalTimePeriod timePeriod, int periodNumber, GoalType goalType, decimal weightLoseGain, bool imperialUnits = false)
        {
            if (imperialUnits)
            {
                height = UnitConverter.FeetToCentimeters(height);
                weight = UnitConverter.PoundsToKilograms(weight);
            }

            var bmr = BMRHarrisBenedict(weight, height, age, gender, imperialUnits);

            var dailyCalorieNeed = GetDailyCaloriesEstimation(bmr, activityFactor);

            var totalGoalDays = WeightChangePeriodToDays(timePeriod, periodNumber);
            var totalCalories = UnitConverter.KilogramsToPounds(weightLoseGain) * 3500;

            decimal dailyCaloriesChange = 0m;

            if (goalType != GoalType.Maintain)
            {
                dailyCaloriesChange = totalCalories / totalGoalDays;
            }

            if (dailyCaloriesChange > 3500m)
            {
                return(new WeightChangeEstimationResult(Convert.ToInt32(dailyCalorieNeed)));
            }

            if (goalType == GoalType.Lose)
            {
                var caloriesToReachGoal    = dailyCalorieNeed - dailyCaloriesChange;
                var caloriesToMaintainGoal =
                    GetDailyCaloriesEstimation(bmr, activityFactor) * (UnitConverter.KilogramsToPounds(weight) - UnitConverter.KilogramsToPounds(weightLoseGain)) / UnitConverter.KilogramsToPounds(weight);
                return(new WeightChangeEstimationResult(Convert.ToInt32(caloriesToReachGoal), Convert.ToInt32(caloriesToMaintainGoal)));
            }
            else if (goalType == GoalType.Gain)
            {
                var caloriesToReachGoal    = dailyCalorieNeed + dailyCaloriesChange;
                var caloriesToMaintainGoal =
                    GetDailyCaloriesEstimation(bmr, activityFactor) * (UnitConverter.KilogramsToPounds(weight) + UnitConverter.KilogramsToPounds(weightLoseGain)) / UnitConverter.KilogramsToPounds(weight);
                return(new WeightChangeEstimationResult(Convert.ToInt32(caloriesToReachGoal), Convert.ToInt32(caloriesToMaintainGoal)));
            }
            else if (goalType == GoalType.Maintain)
            {
                return(new WeightChangeEstimationResult(Convert.ToInt32(dailyCalorieNeed), Convert.ToInt32(dailyCalorieNeed)));
            }
            return(new WeightChangeEstimationResult(Convert.ToInt32(dailyCalorieNeed)));
        }