Beispiel #1
0
        private double EvaluateDailyMacro(GroupDiet diet, out bool feasible)
        {
            var distance = 0.0;

            feasible = true;
            foreach (var personalData in _personalData)
            {
                var dailySummary = _dietAnalyzer.SummarizeForPerson(diet, personalData.Id);

                var distanceForPerson =
                    Math.Abs(personalData.Requirements.ProteinRange.GetDistanceToRange(dailySummary.NutritionValues.Proteins)) +
                    Math.Abs(personalData.Requirements.FatRange.GetDistanceToRange(dailySummary.NutritionValues.Fat)) +
                    Math.Abs(personalData.Requirements.CarbohydratesRange.GetDistanceToRange(dailySummary.NutritionValues.Carbohydrates));

                for (var mealIndex = 0; mealIndex < dailySummary.CaloriesPerMeal.Count; mealIndex++)
                {
                    distanceForPerson +=
                        Math.Abs(
                            personalData.Requirements
                            .MealCaloriesSplit[mealIndex]
                            .GetDistanceToRange(dailySummary.CaloriesPerMeal[mealIndex]));
                }

                if (!personalData.Requirements.CaloriesAllowedRange.IsInRange(dailySummary.NutritionValues.Calories) || Math.Abs(distanceForPerson) > 200)
                {
                    feasible = false;
                }

                distance += distanceForPerson;
            }

            return(distance);
        }
        private List <List <double> > GetMealDifferences(GroupDiet diet)
        {
            var mealDifferences = new List <List <double> >();

            foreach (var personalData in _personalData)
            {
                var personMealDifferences = new List <double>();
                var dietSummary           = _dietAnalyzer.SummarizeForPerson(diet, personalData.Id);

                for (int i = 0; i < dietSummary.CaloriesPerMeal.Count; i++)
                {
                    personMealDifferences.Add(personalData.Requirements.MealCaloriesSplit[i].GetDistanceToRange(dietSummary.CaloriesPerMeal[i]));
                }
                mealDifferences.Add(personMealDifferences);
            }
            return(mealDifferences);
        }
        public GroupDietViewModel CreateGroupDietViewModel(GroupDietIndividual individual, List <PersonalData> personalDataList)
        {
            var groupDietViewModel = new GroupDietViewModel();
            var dietAnalizer       = new GroupDietAnalyzer();

            groupDietViewModel.Evaluations = individual.Evaluations;

            foreach (var personalData in personalDataList)
            {
                var personDiet = new PersonDietViewModel();

                personDiet.DietSummary = dietAnalizer.SummarizeForPerson(individual.GroupDiet, personalData.Id);
                personDiet.Meals       = GetMealsViewModel(personDiet.DietSummary, individual, personalData);
                groupDietViewModel.PersonDietViewModels.Add(personDiet);
            }

            return(groupDietViewModel);
        }
Beispiel #4
0
        private GroupDiet CreateRandomDailyDiet()
        {
            var diet = new GroupDiet();

            for (var j = 0; j < _numberOfMealsPerDay; j++)
            {
                var meal = new GroupMeal {
                    MealType = (MealType)j
                };
                diet.Meals.Add(meal);
            }

            List <int> idsWithDeficiency;

            while ((idsWithDeficiency = _personalData.Where(p => p.Requirements.CaloriesAllowedRange.Lower > _dietAnalyzer.SummarizeForPerson(diet, p.Id).NutritionValues.Calories).Select(pd => pd.Id).ToList()).Any())
            {
                var meal            = diet.Meals.GetRandomItem();
                var includedRecipes = diet.Meals.SelectMany(m => m.Recipes).Select(r => r.Recipe).Distinct().ToList();
                var split           = GetRanodmNotInvlolvedRecipe(includedRecipes, meal.MealType);

                split.Adjustments.RemoveAll(a => !idsWithDeficiency.Contains(a.PersonId));
                meal.Recipes.Add(split);
            }

            return(diet);
        }