Exemplo n.º 1
0
        public static decimal?CalculateCalories(decimal met, decimal?duration, IPerson person)
        {
            if (duration == null)
            {//we don't have time of exercising then we cannot calculate calories
                return(null);
            }
            DateTime?birthday = null;
            Gender   gender   = Gender.Male;
            decimal  weight   = 0;
            decimal  height   = 0;

            if (person.Birthday != null)
            {
                birthday = person.Birthday;
            }
            gender = person.Gender;
            if (person.Wymiary != null)
            {
                weight = person.Wymiary.Weight;
                height = person.Wymiary.Height;
            }
            if (gender == Gender.NotSet)
            {
                gender = Gender.Male;
            }

            if (weight == 0)
            {//set default weight if not defined
                if (gender == Gender.Female)
                {
                    weight = 70;
                }
                else
                {
                    weight = 100;
                }
            }
            if (gender == Gender.Male)
            {
                if (height == 0)
                {
                    height = 177.4M;
                }
            }
            else
            {//female
                if (height == 0)
                {
                    height = 163M;
                }
            }
            if (birthday == null)
            {//if birthday is not set then assume 30 years old
                birthday = DateTime.UtcNow.AddYears(-30).AddDays(-1);
            }

            int age = birthday.Value.GetAge();

            return(WilksFormula.CalculateCaloriesUsingMET(gender == Gender.Male, met, TimeSpan.FromSeconds((double)duration), age, weight, height));
        }
Exemplo n.º 2
0
        public void CalculatorUsingMet_Female()
        {
            var calories = WilksFormula.CalculateCaloriesUsingMET(false, 8.0m, TimeSpan.FromMinutes(60), 32, 93, 188);

            Assert.AreEqual(581m, (int)calories);
        }
Exemplo n.º 3
0
        public void CalculatorUsingMet_Male()
        {
            var calories = WilksFormula.CalculateCaloriesUsingMET(true, 8.0m, TimeSpan.FromMinutes(60), 32, 93, 188);

            Assert.AreEqual(689m, calories);
        }