Пример #1
0
        private Standings CalculateStandingForTeams(List <Team> teams)
        {
            List <Game> games = this.dataAccess.LoadGamesOfSeason(this.season.ID, this.date, teams.Select(t => t.ID).ToList());
            Dictionary <long, StandingsEntry> standingsEntries = new Dictionary <long, StandingsEntry>();

            foreach (Game game in games)
            {
                ScoreCalculation scoreCalculation = new ScoreCalculation(game);
                Score            score            = scoreCalculation.CalculateGuestTeamScore();
                StandingsCalculation.AddEntryValuesForTeam(standingsEntries, scoreCalculation.CalculateHomeTeamScore(), game.HomeTeam);
                StandingsCalculation.AddEntryValuesForTeam(standingsEntries, scoreCalculation.CalculateGuestTeamScore(), game.GuestTeam);
            }

            //make sure that there is an entry for each team
            foreach (Team team in teams)
            {
                GetStandingsEntryForTeam(standingsEntries, team);
            }

            List <StandingsEntry> sortedEntries = StandingsCalculation.SortStandingsEntries(standingsEntries.Values.ToList());

            StandingsCalculation.SetPosition(sortedEntries);

            return(new Standings(this.date, this.season, sortedEntries));
        }
Пример #2
0
        public TeamPointChart GetTeamPointChart()
        {
            List <TeamPointSeries> teamPointSeriesList = new List <TeamPointSeries>();

            foreach (Team team in this.dataAccess.LoadTeams())
            {
                List <Game> games = this.dataAccess.LoadGamesOfSeasonForTeam(this.season.ID, team.ID);
                if (games.Count() > 0)
                {
                    TeamPointSeries teamPointSeries   = new TeamPointSeries(team);
                    int             currentGameNumber = 1;
                    foreach (Game game in games.OrderBy(g => g.Date))
                    {
                        ScoreCalculation scoreCalculation = new ScoreCalculation(game);
                        Score            score            = null;
                        if (game.HomeTeam.ID == team.ID)
                        {
                            score = scoreCalculation.CalculateHomeTeamScore();
                        }
                        else
                        {
                            score = scoreCalculation.CalculateGuestTeamScore();
                        }
                        teamPointSeries.AddPointsOfGame(currentGameNumber, score.Points);
                        currentGameNumber++;
                    }
                    teamPointSeriesList.Add(teamPointSeries);
                }
            }

            //Add entry for theoretical eighth place
            teamPointSeriesList.Add(TeamPointSeries.GetEighthPlaceSeries());

            return(new TeamPointChart(this.season, teamPointSeriesList));
        }
Пример #3
0
        public Standings CalculateStanding()
        {
            List <Game> games = this.dataAccess.LoadGamesOfSeason(this.season.ID, this.date, null);
            Dictionary <long, StandingsEntry> standingsEntries = new Dictionary <long, StandingsEntry>();

            foreach (Game game in games)
            {
                ScoreCalculation scoreCalculation = new ScoreCalculation(game);
                Score            score            = scoreCalculation.CalculateGuestTeamScore();
                StandingsCalculation.AddEntryValuesForTeam(standingsEntries, scoreCalculation.CalculateHomeTeamScore(), game.HomeTeam);
                StandingsCalculation.AddEntryValuesForTeam(standingsEntries, scoreCalculation.CalculateGuestTeamScore(), game.GuestTeam);
            }

            List <StandingsEntry> sortedEntries = new List <StandingsEntry>();

            foreach (var entryGroup in standingsEntries.Values.GroupBy(se => se.SortString).OrderBy(eg => eg.Key))
            {
                if (entryGroup.Count() == 1)
                {
                    sortedEntries.Add(entryGroup.First());
                }
                else
                {
                    Standings groupStandings = this.CalculateStandingForTeams(entryGroup.Select(eg => eg.Team).ToList());
                    foreach (var groupStandingsEntryGroup in groupStandings.Entries.GroupBy(se => se.Position))
                    {
                        if (groupStandingsEntryGroup.Count() == 1)
                        {
                            sortedEntries.Add(entryGroup.First(se => se.Team.ID == groupStandingsEntryGroup.First().Team.ID));
                        }
                        else
                        {
                            List <StandingsEntry> entriesToInsert = new List <StandingsEntry>();
                            foreach (StandingsEntry entry in groupStandingsEntryGroup)
                            {
                                entriesToInsert.Add(entryGroup.First(se => se.Team.ID == entry.Team.ID));
                            }
                            List <StandingsEntry> sortedGroupEntries = StandingsCalculation.SortStandingsEntries(entriesToInsert);
                            foreach (StandingsEntry entryToInsert in sortedGroupEntries)
                            {
                                sortedEntries.Add(entryToInsert);
                            }
                        }
                    }
                }
            }

            int position = 1;

            foreach (StandingsEntry entry in sortedEntries)
            {
                entry.Position = position;
                position++;
            }

            return(new Standings(this.date, this.season, sortedEntries));
        }