예제 #1
0
        public SeasonStatistics CreateStatistics()
        {
            List <Game>      games            = this.dataAccess.LoadGamesOfSeason(this.season.ID);
            SeasonStatistics seasonStatistics = new SeasonStatistics(this.season);

            foreach (Game game in games)
            {
                seasonStatistics.AddGame(game);
            }
            return(seasonStatistics);
        }
예제 #2
0
        public void CreateFirstSeason(List <Team> teams, TransactionManager transactionManager)
        {
            // First check the number of teams can be evenly divided into the number of leagues.
            bool teamsOk = teams.Count % Constants.HowManyLeagues == 0;

            if (!teamsOk)
            {
                throw new Exception($"The number of teams must be divided by {Constants.HowManyLeagues}");
            }

            var newSeasonInfo = new NewSeasonInfo {
                StartYear = DateTime.Now.Year
            };

            // Divide all teams between the four leagues based on the team rating.
            teams.Sort((team1, team2) => team2.Rating.CompareTo(team1.Rating));
            int countTeamsPerLeague = teams.Count / Constants.HowManyLeagues;

            newSeasonInfo.TeamsLeague1 = teams.Take(countTeamsPerLeague).ToList();
            newSeasonInfo.TeamsLeague2 = teams.Skip(countTeamsPerLeague).Take(countTeamsPerLeague).ToList();
            newSeasonInfo.TeamsLeague3 = teams.Skip(countTeamsPerLeague * 2).Take(countTeamsPerLeague).ToList();
            newSeasonInfo.TeamsLeague4 = teams.Skip(countTeamsPerLeague * 3).ToList();

            // The teams have been sorted on rating, so given them an initial league table position.
            AssignInitialLeagueTablePosition(teams);

            // In the first season there are no champion and cup winner yet, so pick the two best teams.
            // Because the champion and cup winner are determined via the previous season's statistics, create a dummy PreviousSeasonStatistics for this.
            var dummySeasonStatistics = new SeasonStatistics()
            {
                NationalChampion = teams[0], CupWinner = teams[1], NationalChampionRunnerUp = teams[1]
            };

            newSeasonInfo.PreviousSeasonStatistics = dummySeasonStatistics;

            // Now all teams have been placed in the right leagues, so create match schedules for all competitions.
            var seasonAndCompetitionSchedules = CreateSeasonAndCompetitionSchedules(newSeasonInfo);

            // Insert the season and all competition schedules.
            InsertSeasonAndCompetitionSchedule(transactionManager, seasonAndCompetitionSchedules);

            InsertGameDateTimes(transactionManager, seasonAndCompetitionSchedules);

            // Insert statistics.
            InsertSeasonRelatedStatistics(transactionManager, teams, seasonAndCompetitionSchedules);
            InsertTeamStatistics(transactionManager, teams);
        }
예제 #3
0
        public static SeasonStatisticsResource ToResource(this SeasonStatistics model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new SeasonStatisticsResource
            {
                NextAiring = model.NextAiring,
                PreviousAiring = model.PreviousAiring,
                EpisodeFileCount = model.EpisodeFileCount,
                EpisodeCount = model.EpisodeFileCount,
                TotalEpisodeCount = model.TotalEpisodeCount,
                SizeOnDisk = model.SizeOnDisk
            });
        }
예제 #4
0
        public ObjectResult Get(long seasonID)
        {
            ObjectResult response = null;
            Season       season   = this.dataAccess.LoadSeason(seasonID);

            if (season == null)
            {
                response = this.StatusCode(StatusCodes.Status404NotFound, "Not Found");
            }
            else
            {
                SeasonAnalizer   seasonAnalizer = new SeasonAnalizer(season, this.dataAccess);
                SeasonStatistics statistics     = seasonAnalizer.CreateStatistics();
                response = this.StatusCode(StatusCodes.Status200OK, statistics);
            }
            return(response);
        }
예제 #5
0
        private void InsertSeasonRelatedStatistics(TransactionManager transactionManager, IEnumerable <Team> teams, SeasonAndCompetitionSchedules seasonAndCompetitionSchedules)
        {
            string league1LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[0].Id;
            string league2LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[1].Id;
            string league3LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[2].Id;
            string league4LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[3].Id;

            // SeasonStatistics.
            var seasonStatistics = new SeasonStatistics(seasonAndCompetitionSchedules.Season, league1LeagueTableId, league2LeagueTableId, league3LeagueTableId, league4LeagueTableId);

            transactionManager.RegisterInsert(seasonStatistics);

            // SeasonTeamStatistics.
            foreach (var team in teams)
            {
                var seasonTeamStatistic = new SeasonTeamStatistics(seasonAndCompetitionSchedules.Season, team, team.CurrentLeagueCompetition.Name);
                transactionManager.RegisterInsert(seasonTeamStatistic);
            }
        }