Пример #1
0
        public AnalyzerResult GetPrediction(Recipe recipe)
        {
            var rankBreakfast = new Ranking(Category.Breakfast);
            var rankLunch = new Ranking(Category.Lunch);
            var rankDinner = new Ranking(Category.Dinner);
            var rankDessert = new Ranking(Category.Dessert);

            // Setup Tournament
            this.Compete(recipe, this.breakfastIndex, this.lunchIndex, rankBreakfast, rankLunch, rankDinner, rankDessert);
            this.Compete(recipe, this.breakfastIndex, this.dinnerIndex, rankBreakfast, rankLunch, rankDinner, rankDessert);
            this.Compete(recipe, this.breakfastIndex, this.dessertIndex, rankBreakfast, rankLunch, rankDinner, rankDessert);
            this.Compete(recipe, this.lunchIndex, this.dinnerIndex, rankBreakfast, rankLunch, rankDinner, rankDessert);
            this.Compete(recipe, this.lunchIndex, this.dessertIndex, rankBreakfast, rankLunch, rankDinner, rankDessert);
            this.Compete(recipe, this.dinnerIndex, this.dessertIndex, rankBreakfast, rankLunch, rankDinner, rankDessert);

            // Choose winner
            var result = this.GetWinner(rankBreakfast, rankLunch, rankDinner, rankDessert);

            return result;
        }
Пример #2
0
        private void Compete(Recipe entry, RecipeIndex first, RecipeIndex second, Ranking rankBreakfast, Ranking rankLunch, Ranking rankDinner, Ranking rankDessert)
        {
            var chance = this.GetPrediction(entry, first, second);
            if (chance > 0.5f - Tolerance && chance < 0.5f + Tolerance)
            {
                return; // No winner
            }

            var diff = (float)Math.Abs(chance - 0.5);
            var winner = chance < 0.5 ? second : first;

            if (winner == this.breakfastIndex)
            {
                rankBreakfast.Score += diff;
            }

            if (winner == this.lunchIndex)
            {
                rankLunch.Score += diff;
            }

            if (winner == this.dinnerIndex)
            {
                rankDinner.Score += diff;
            }

            if (winner == this.dessertIndex)
            {
                rankDessert.Score += diff;
            }
        }
Пример #3
0
        private AnalyzerResult GetWinner(Ranking rankBreakfast, Ranking rankLunch, Ranking rankDinner, Ranking rankDessert)
        {
            var meals = new Ranking[] { rankBreakfast, rankLunch, rankDinner, rankDessert };
            var sorted = meals.OrderByDescending(m => m.Score).ToArray();

            var firstPlace = sorted[0];
            var difference = sorted[1].Score / sorted[0].Score;
            var secondPlace = difference > SecondPlaceDifferenceTolerance ? sorted[1] : null;

            var result = new AnalyzerResult(firstPlace.Type, secondPlace != null ? secondPlace.Type : Category.None);
            return result;
        }