Ejemplo n.º 1
0
        public string GetWinnerOfSpecificContest(string name)
        {
            List <Scores>      ScoresList       = new List <Scores>();
            List <Game>        GamesList        = new List <Game>();
            List <ScoreStatus> ScoresStatusList = new List <ScoreStatus>();

            ScoreCollection.Reading(); //läser in användarna
            GameCollection.Reading();  //läser in alla matcher
            PersonCollection.Reading();

            var getScores     = ScoreCollection.GetEnumerator();
            var getGames      = GameCollection.GetEnumerator();
            var getAllPersons = PersonCollection.GetEnumerator();

            foreach (var items in getScores)
            {
                ScoresList.Add(items);
            }

            foreach (var items in getGames)
            {
                if (items.Name == name)
                {
                    GamesList.Add(items);
                }
            }

            var percentage   = 0.0;
            var amountScores = 0; //Hur många gånger en person återkommer i Gamesfilen
            var amountGames  = 0;

            foreach (var items in getAllPersons)
            {
                var text = $"{items.ContestNumber} {items.FirstName} {items.LastName}";

                amountScores = ScoresList.Where(x => x.Winner == text).Count();

                amountGames = GamesList.Where(x => x.PersonOne == text || x.PersonTwo == text).Count();

                // Create math proxy
                MathProxy proxy = new MathProxy();

                if (amountGames >= 10)
                {
                    if (amountScores == 0)
                    {
                        percentage = proxy.Mul(amountScores, amountGames);
                    }

                    percentage = proxy.Div((amountScores * 100), amountGames);

                    var ScoresStatus = new ScoreStatus(amountGames, amountScores, items.FirstName, items.LastName, percentage, items.ContestNumber);
                    ScoresStatusList.Add(ScoresStatus);
                }
            }


            if (ScoresStatusList.Count > 0)
            {
                var sort = ScoresStatusList.OrderByDescending(x => x.Percentage).FirstOrDefault();

                //return $"Årets champion: {sort.FirstName} {sort.LastName} vinnar andel: {sort.Percentage}%";
                return($"{sort.ContestNumber} {sort.FirstName} {sort.LastName}");
            }
            else
            {
                return("Ingen användare har spelat mer än 10 matcher");
            }
        }