static AnalyzerResult GetWinner(Ranking winsBr, Ranking winsLu, Ranking winsDi, Ranking winsDe, out Ranking firstPlace, out Ranking secondPlace)
        {
            var meals = new Ranking[] {winsBr, winsLu, winsDi, winsDe};
             var sorted = (from m in meals orderby m.Score descending select m).ToArray();

             firstPlace = sorted[0];

             secondPlace = sorted[1].Score/sorted[0].Score > 0.8f ? sorted[1] : null;

             var ret = new AnalyzerResult(firstPlace.Type, (secondPlace != null ? secondPlace.Type : Category.None));
             return ret;
        }
コード例 #2
0
        public AnalyzerResult GetPrediction(Recipe recipe)
        {
            var winsBreakfast = new Ranking(Category.Breakfast);
            var winsLunch = new Ranking(Category.Lunch);
            var winsDinner = new Ranking(Category.Dinner);
            var winsDessert = new Ranking(Category.Dessert);

            // Setup Tournament
            this.Compete(recipe, this.breakfastIndex, this.lunchIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.breakfastIndex, this.dinnerIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.breakfastIndex, this.dessertIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.lunchIndex, this.dinnerIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.lunchIndex, this.dessertIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.dinnerIndex, this.dessertIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);

            // Choose winner
            var result = GetWinner(winsBreakfast, winsLunch, winsDinner, winsDessert);
            return result;
        }
        public AnalyzerResult GetPrediction(Recipe recipe)
        {
            var winsBr = new Ranking(Category.Breakfast);
             var winsLu = new Ranking(Category.Lunch);
             var winsDi = new Ranking(Category.Dinner);
             var winsDe = new Ranking(Category.Dessert);

             //Setup Tournament
             Compete(recipe, BreakfastIndex, LunchIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, BreakfastIndex, DinnerIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, BreakfastIndex, DessertIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, LunchIndex, DinnerIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, LunchIndex, DessertIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, DinnerIndex, DessertIndex, winsBr, winsLu, winsDi, winsDe);

             //Choose winner
             Ranking tag1, tag2;
             var result = GetWinner(winsBr, winsLu, winsDi, winsDe, out tag1, out tag2);

             return result;
        }
コード例 #4
0
 private static AnalyzerResult GetWinner(Ranking winsBreakfast, Ranking winsLunch, Ranking winsDinner, Ranking winsDessert)
 {
     var meals = new Ranking[] { winsBreakfast, winsLunch, winsDinner, winsDessert };
     var sortedMealsByScore = meals.OrderByDescending(meal => meal.Score).ToArray();
     var firstPlace = sortedMealsByScore[0];
     var secondPlace = (sortedMealsByScore[1].Score / sortedMealsByScore[0].Score > 0.8f) ? sortedMealsByScore[1] : null;
     var result =
         new AnalyzerResult(
             firstPlace.Type,
             secondPlace != null
             ? secondPlace.Type
             : Category.None);
     return result;
 }
コード例 #5
0
        private void Compete(Recipe entryRecipe, RecipeIndex firstIndex, RecipeIndex secondIndex, Ranking winsBreakfast, Ranking winsLunch, Ranking winsDinner, Ranking winsDessert)
        {
            var prediction = this.GetPrediction(entryRecipe, firstIndex, secondIndex);
            if (.5f - Tolerance < prediction && prediction < .5f + Tolerance)
            {
                return; // No winner
            }

            float difference = (float)Math.Abs(prediction - 0.5);
            var winner = prediction >= 0.5 ? firstIndex : secondIndex;

            if (winner == this.breakfastIndex)
            {
                winsBreakfast.Score += difference;
            }

            if (winner == this.lunchIndex)
            {
                winsLunch.Score += difference;
            }

            if (winner == this.dinnerIndex)
            {
                winsDinner.Score += difference;
            }

            if (winner == this.dessertIndex)
            {
                winsDessert.Score += difference;
            }
        }
        void Compete(Recipe entry, RecipeIndex first, RecipeIndex second, Ranking winsBr, Ranking winsLu, Ranking winsDi, Ranking winsDe)
        {
            var res = GetPrediction(entry, first, second);
             if (res > .5f - TOLERANCE && res < .5f + TOLERANCE)
            return; //No winner

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

             if (winner == BreakfastIndex) winsBr.Score += diff;
             if (winner == LunchIndex) winsLu.Score += diff;
             if (winner == DinnerIndex) winsDi.Score += diff;
             if (winner == DessertIndex) winsDe.Score += diff;
        }
コード例 #7
0
        void Compete(Recipe entry, RecipeIndex first, RecipeIndex second, Ranking winsBr, Ranking winsLu, Ranking winsDi, Ranking winsDe)
        {
            var res = GetPrediction(entry, first, second);

            if (res > .5f - TOLERANCE && res < .5f + TOLERANCE)
            {
                return; //No winner
            }
            var diff   = (float)Math.Abs(res - 0.5);
            var winner = (res < 0.5 ? second : first);

            if (winner == BreakfastIndex)
            {
                winsBr.Score += diff;
            }
            if (winner == LunchIndex)
            {
                winsLu.Score += diff;
            }
            if (winner == DinnerIndex)
            {
                winsDi.Score += diff;
            }
            if (winner == DessertIndex)
            {
                winsDe.Score += diff;
            }
        }
コード例 #8
0
        static AnalyzerResult GetWinner(Ranking winsBr, Ranking winsLu, Ranking winsDi, Ranking winsDe, out Ranking firstPlace, out Ranking secondPlace)
        {
            var meals  = new Ranking[] { winsBr, winsLu, winsDi, winsDe };
            var sorted = (from m in meals orderby m.Score descending select m).ToArray();

            firstPlace = sorted[0];

            secondPlace = sorted[1].Score / sorted[0].Score > 0.8f ? sorted[1] : null;

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

            return(ret);
        }
        private void Compete(
            Recipe entry,
            RecipeIndex first,
            RecipeIndex second,
            Ranking winsBr,
            Ranking winsLu,
            Ranking winsDi,
            Ranking winsDe)
        {
            var res = this.GetPrediction(entry, first, second);
            if (res > .5f - Tolerance && res < .5f + Tolerance)
            {
                return; // No winner
            }

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

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

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

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

            if (winner == this.dessertIndex)
            {
                winsDe.Score += diff;
            }
        }