Пример #1
0
        public IEnumerable <DisplayTeam> BestOverallTeams()
        {
            var overallTeams = new List <DisplayTeam>();

            foreach (var team1 in teams)
            {
                if (overallTeams.Where(t => (t.DefenseID == team1.DefenseID && t.OffenseID == team1.OffenseID) || (t.DefenseID == team1.OffenseID && t.OffenseID == team1.DefenseID)).Count() > 0)
                {
                    continue;
                }

                var tempTeam = new DisplayTeam
                {
                    DefenseID   = team1.DefenseID,
                    OffenseID   = team1.OffenseID,
                    GamesPlayed = team1.GamesPlayed,
                    GamesWon    = team1.GamesWon,
                    DefenseName = team1.DefenseName,
                    OffenseName = team1.OffenseName,
                    TeamID      = team1.TeamID
                };
                foreach (var team2 in teams)
                {
                    if ((team1.DefenseID == team2.OffenseID) && (team1.OffenseID == team2.DefenseID))
                    {
                        tempTeam.GamesPlayed += team2.GamesPlayed;
                        tempTeam.GamesWon    += team2.GamesWon;
                    }
                }
                tempTeam.WinPct = (float)tempTeam.GamesWon / tempTeam.GamesPlayed * 100;
                overallTeams.Add(tempTeam);
            }
            return(overallTeams.Where(t => t.GamesPlayed > 3).OrderByDescending(t => t.WinPct));
        }
    void ButtonMethod()
    {
        DisplayTeam team = FindObjectOfType <DisplayTeam>();

        if (team != null)
        {
            team.ShowInfo(unit);
        }
    }
Пример #3
0
        public void Generate()
        {
            HistoricalTeamRanks = new Dictionary <string, List <int> >();
            foreach (var team in teamRepository.GetTeams())
            {
                HistoricalTeamRanks.Add(TeamToKey(team), new List <int> {
                    EloHandler.StartingScore
                });
            }
            foreach (var game in gameRepository.GetGames().OrderBy(g => g.GameTime))
            {
                var blueTeam = new DisplayTeam
                {
                    DefenseID = game.BlueDefense,
                    OffenseID = game.BlueOffense,
                };
                var redTeam = new DisplayTeam
                {
                    DefenseID = game.RedDefense,
                    OffenseID = game.RedOffense
                };

                blueTeam.GamesPlayed = HistoricalTeamRanks[TeamToKey(blueTeam)].Count - 1;
                redTeam.GamesPlayed  = HistoricalTeamRanks[TeamToKey(redTeam)].Count - 1;


                var blueRankList = HistoricalTeamRanks[TeamToKey(blueTeam)];
                var redRankList  = HistoricalTeamRanks[TeamToKey(redTeam)];

                blueTeam.Rank = blueRankList[blueRankList.Count - 1];
                redTeam.Rank  = redRankList[redRankList.Count - 1];

                var updatedRanks = EloHandler.UpdatedRanks(blueTeam, redTeam, game);

                HistoricalTeamRanks[TeamToKey(blueTeam)].Add(updatedRanks[0]);
                HistoricalTeamRanks[TeamToKey(redTeam)].Add(updatedRanks[1]);
            }
            //var blueIDs = $"{blueTeam.DefenseID} {blueTeam.OffenseID}";
            //var redIDs = $"{blueTeam.DefenseID} {blueTeam.OffenseID}";
            //try
            //{
            //    HistoricalTeamRanks[blueIDs].Add(blueTeam.Rank);
            //}
            //catch
            //{
            //    HistoricalTeamRanks.Add(blueIDs, new List<int> { 1200,blueTeam.Rank });
            //}
            //try
            //{
            //    HistoricalTeamRanks[redIDs].Add(redTeam.Rank);
            //}
            //catch
            //{
            //    HistoricalTeamRanks.Add(redIDs, new List<int> { 1200,redTeam.Rank });
            //}
        }
Пример #4
0
        public ActionResult DisplayTeam(int id = 0, string Month = "0")
        {
            DisplayTeam         model          = new DisplayTeam();
            List <TeamSchedule> team_schedules = new List <TeamSchedule>();
            List <Player>       Roster         = db.Players.ToList();
            Team team = db.Teams.Find(id);


            //Find out if the View is for specific month.
            if (Month == "0")
            {
                Month = DateTime.Now.Month.ToString();
            }

            //Grab all the schedule for this team.
            List <Schedule> schedules = db.Schedules.ToList().FindAll(o => (o.HomeTeam == id || o.RoadTeam == id) && o.GameDateTime.Month.ToString() == Month);

            foreach (Schedule item in schedules)
            {
                TeamSchedule ts = new TeamSchedule();
                ts.GameDateTime = item.GameDateTime;
                ts.Home_Team    = db.Teams.Find(item.HomeTeam);
                ts.Road_Team    = db.Teams.Find(item.RoadTeam);
                ts.HomeScore    = item.HomeScore;
                ts.RoadScore    = item.RoadScore;

                team_schedules.Add(ts);
            }

            if (team != null)
            {
                model.ID        = id;
                model.Name      = team.Name;
                model.Players   = Roster.FindAll(o => o.TeamID == id);
                model.Schedules = team_schedules;
                model.ShowMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(System.Convert.ToInt32(Month));
            }
            else
            {
                return(View(team));
            }

            return(View(model));
        }
Пример #5
0
        public IActionResult OnGet(Guid teamID)
        {
            team = teamRetriever.GetTeamById(teamID);
            if (team == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            labels = new List <int>();
            games  = teamDetailRetriever.GetGamesInvolved(teamID);

            gamesPlayed = games.Count();
            bluePlayed  = games.Where(g => g.BlueDefense == team.DefenseID && g.BlueOffense == team.OffenseID).Count();
            redPlayed   = games.Where(g => g.RedDefense == team.DefenseID && g.RedOffense == team.OffenseID).Count();
            redWins     = games.Where(g => g.RedDefense == team.DefenseID && g.RedOffense == team.OffenseID && g.RedScore > g.BlueScore).Count();
            blueWins    = games.Where(g => g.BlueDefense == team.DefenseID && g.BlueOffense == team.OffenseID && g.BlueScore > g.RedScore).Count();
            gamesWon    = redWins + blueWins;

            record     = new[] { gamesWon, gamesPlayed - gamesWon };
            redRecord  = new int[] { redWins, redPlayed - redWins };
            blueRecord = new int[] { blueWins, bluePlayed - blueWins };
            redPct     = (float)redWins / redPlayed * 100;
            bluePct    = (float)blueWins / bluePlayed * 100;
            if (float.IsNaN(redPct))
            {
                redPct = 0;
            }
            if (float.IsNaN(bluePct))
            {
                bluePct = 0;
            }
            var goalsFor     = games.Where(g => g.BlueDefense == team.DefenseID && g.BlueOffense == team.OffenseID).Select(r => r.BlueScore).Sum() + games.Where(g => g.RedDefense == team.DefenseID && g.RedOffense == team.OffenseID).Select(r => r.RedScore).Sum();
            var goalsAgainst = games.Where(g => g.BlueDefense == team.DefenseID && g.BlueOffense == team.OffenseID).Select(r => r.RedScore).Sum() + games.Where(g => g.RedDefense == team.DefenseID && g.RedOffense == team.OffenseID).Select(r => r.BlueScore).Sum();

            avgGoalsFor     = (float)goalsFor / gamesPlayed;
            avgGoalsAgainst = (float)goalsAgainst / gamesPlayed;

            historicalElo = teamDetailRetriever.GetHistoricalEloForTeam(teamID);
            for (var i = 0; i < historicalElo.Count; i++)
            {
                labels.Add(i);
            }
            return(Page());
        }
Пример #6
0
        public void Update(Game newGame)
        {
            //win = {blue,red}
            var win = new[] { 0, 0 };

            if (newGame.BlueScore > newGame.RedScore)
            {
                win = new[] { 1, 0 };
            }
            else
            {
                win = new[] { 0, 1 };
            }

            var blueTeam = teamStatsRetriever.GetTeamByPlayers(newGame.BlueDefense, newGame.BlueOffense);
            var redTeam  = teamStatsRetriever.GetTeamByPlayers(newGame.RedDefense, newGame.RedOffense);

            if (blueTeam == null)
            {
                teamCreator.Create(new Team
                {
                    DefenseID   = newGame.BlueDefense,
                    OffenseID   = newGame.BlueOffense,
                    GamesPlayed = 0,
                    GamesWon    = 0,
                });
                blueTeam = new DisplayTeam
                {
                    DefenseID   = newGame.BlueDefense,
                    OffenseID   = newGame.BlueOffense,
                    GamesPlayed = 0,
                    GamesWon    = 0,
                    Rank        = EloHandler.StartingScore
                };
            }
            if (redTeam == null)
            {
                teamCreator.Create(new Team
                {
                    DefenseID   = newGame.RedDefense,
                    OffenseID   = newGame.RedOffense,
                    GamesPlayed = 0,
                    GamesWon    = 0,
                });
                redTeam = new DisplayTeam
                {
                    DefenseID   = newGame.RedDefense,
                    OffenseID   = newGame.RedOffense,
                    GamesPlayed = 0,
                    GamesWon    = 0,
                    Rank        = EloHandler.StartingScore
                };
            }
            var updatedScores = EloHandler.UpdatedRanks(blueTeam, redTeam, newGame);

            blueTeam.GamesPlayed += 1;
            blueTeam.GamesWon    += win[0];
            blueTeam.Rank         = updatedScores[0];


            redTeam.GamesPlayed += 1;
            redTeam.GamesWon    += win[1];
            redTeam.Rank         = updatedScores[1];

            teamRepository.Update(blueTeam);
            teamRepository.Update(redTeam);
        }
Пример #7
0
        public ActionResult DisplayTeam(int id = 0, string Month = "0")
        {
            DisplayTeam model = new DisplayTeam();
            List<TeamSchedule> team_schedules = new List<TeamSchedule>();
            List<Player> Roster = db.Players.ToList();
            Team team = db.Teams.Find(id);

            //Find out if the View is for specific month.
            if (Month == "0")
            {
                Month = DateTime.Now.Month.ToString();
            }

            //Grab all the schedule for this team.
            List<Schedule> schedules = db.Schedules.ToList().FindAll(o => (o.HomeTeam == id || o.RoadTeam == id) && o.GameDateTime.Month.ToString() == Month);

            foreach (Schedule item in schedules)
            {
                TeamSchedule ts = new TeamSchedule();
                ts.GameDateTime = item.GameDateTime;
                ts.Home_Team = db.Teams.Find(item.HomeTeam);
                ts.Road_Team = db.Teams.Find(item.RoadTeam);
                ts.HomeScore = item.HomeScore;
                ts.RoadScore = item.RoadScore;

                team_schedules.Add(ts);
            }

            if (team != null)
            {
                model.ID = id;
                model.Name = team.Name;
                model.Players = Roster.FindAll(o => o.TeamID == id);
                model.Schedules = team_schedules;
                model.ShowMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(System.Convert.ToInt32(Month));
            }
            else
                return View(team);

            return View(model);
        }
Пример #8
0
        public List <DisplayTeam> FairTeams(IEnumerable <Guid> selectedPlayers)
        {
            random = new Random();
            var selectedPlayersList = selectedPlayers.ToList();
            var shuffled            = selectedPlayers;

            if (selectedPlayers.Count() < 4)
            {
                return(new List <DisplayTeam>());
            }
            if (selectedPlayers.Count() > 4)
            {
                shuffled = Shuffle(selectedPlayers);
            }
            var matchup       = new List <DisplayTeam>();
            var minDifference = 10000;
            var minPerm       = Enumerable.Empty <Guid>();

            foreach (var perm in permute4(shuffled))
            {
                var blueTeam = teams.FirstOrDefault(t => (t.DefenseID == perm[0]) && (t.OffenseID == perm[1]));
                var redTeam  = teams.FirstOrDefault(t => (t.DefenseID == perm[2]) && (t.OffenseID == perm[3]));
                if ((blueTeam == null))
                {
                    blueTeam = new DisplayTeam
                    {
                        DefenseName = playerRetriever.GuidToName(perm[0]),
                        OffenseName = playerRetriever.GuidToName(perm[1]),
                        Rank        = ELO.EloHandler.StartingScore
                    };
                }
                if ((redTeam == null))
                {
                    redTeam = new DisplayTeam
                    {
                        DefenseName = playerRetriever.GuidToName(perm[2]),
                        OffenseName = playerRetriever.GuidToName(perm[3]),
                        Rank        = ELO.EloHandler.StartingScore
                    };
                }
                var difference = Math.Abs(blueTeam.Rank + 100 - redTeam.Rank); //Blue Team with blue advantage minus redd rank
                if (difference < minDifference)
                {
                    minDifference = difference;
                    matchup       = new List <DisplayTeam> {
                        blueTeam, redTeam
                    };
                    minPerm = perm;
                }
            }
            if (minDifference == 10000)
            {
                return(new List <DisplayTeam>());
            }
            foreach (var id in minPerm)
            {
                selectedPlayersList.Remove(id);
            }
            foreach (var id in selectedPlayersList)
            {
                matchup.Add(new DisplayTeam {
                    DefenseName = playerRetriever.GuidToName(id)
                });
            }
            return(matchup);
        }