Ejemplo n.º 1
0
        public static void AddFromFile(string file, bool force = false)
        {
            if (string.IsNullOrEmpty(file))
            {
                return;
            }

            Console.WriteLine($"Adding playoff probabilities from: {file}");

            var playoffProbs = JsonConvert.DeserializeObject <Models.Import.PlayoffProbabilities>(File.ReadAllText(file));

            var weekExists = PlayoffProbabilityHandler.WeekExists(playoffProbs.Year, playoffProbs.Week);

            if (weekExists)
            {
                if (force)
                {
                    PlayoffProbabilityHandler.DeleteWeek(playoffProbs.Year, playoffProbs.Week);
                }
                else
                {
                    return;
                }
            }

            var teams             = TeamHandler.GetAllTeams();
            var playoffProbsToAdd = new List <PlayoffProbability>();

            foreach (var playoffProb in playoffProbs.Probability)
            {
                Console.WriteLine($" Adding playoff prob for {playoffProb.Team}");

                if (playoffProb.ExcludingTiebreakers > playoffProb.IncludingTiebreakers)
                {
                    throw new ArgumentException($"Excluding ({playoffProb.ExcludingTiebreakers}) > Including ({playoffProb.IncludingTiebreakers})");
                }

                var team = teams.Find(t => t.Name == playoffProb.Team);

                playoffProbsToAdd.Add(new PlayoffProbability
                {
                    Year   = playoffProbs.Year,
                    Week   = playoffProbs.Week,
                    TeamId = team.Id,
                    IncludingTiebreaker = playoffProb.IncludingTiebreakers,
                    ExcludingTiebreaker = playoffProb.ExcludingTiebreakers
                });
            }

            PlayoffProbabilityHandler.Add(playoffProbsToAdd);
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            var teams = TeamHandler.GetAllTeams();

            teams.Sort((t1, t2) => t1.Name.CompareTo(t2.Name));

            var model = teams.Select(t => new TeamOverallInfo
            {
                Team         = t,
                YearsActive  = TeamRecordHandler.GetYearsActive(t.Id),
                NumChampion  = SeasonInfoHandler.GetNumChampion(t.Id),
                CareerRecord = TeamRecordHandler.GetCareerRecord(t.Id)
            }).ToList();

            return(View(model));
        }
Ejemplo n.º 3
0
        public static void Add(string scheduleFile, bool force = false)
        {
            if (string.IsNullOrEmpty(scheduleFile))
            {
                return;
            }

            var schedule = JsonConvert.DeserializeObject <Models.Import.Schedule>(File.ReadAllText(scheduleFile));

            var weeksInDb = GameHandler.GetWeeksInYear(schedule.Year);

            if (weeksInDb.Count > 0 && force)
            {
                GameHandler.DeleteGamesInYear(schedule.Year);
                weeksInDb.Clear();
            }

            var teams      = TeamHandler.GetAllTeams().ToDictionary(t => t.Name);
            var gamesToAdd = new List <Game>();

            foreach (var week in schedule.Weeks)
            {
                if (weeksInDb.Contains(week.Week))
                {
                    // this week already exists in database
                    continue;
                }

                foreach (var game in week.Games)
                {
                    if (!teams.ContainsKey(game.Team1))
                    {
                        var team = TeamHandler.Add(new Team {
                            Name = game.Team1
                        });
                        teams.Add(team.Name, team);
                    }
                    if (!teams.ContainsKey(game.Team2))
                    {
                        var team = TeamHandler.Add(new Team {
                            Name = game.Team2
                        });
                        teams.Add(team.Name, team);
                    }

                    var team1 = teams[game.Team1];
                    var team2 = teams[game.Team2];

                    gamesToAdd.Add(new Game
                    {
                        Year       = schedule.Year,
                        Week       = week.Week,
                        GameScores = new List <GameScore>
                        {
                            new GameScore
                            {
                                Year   = schedule.Year,
                                Week   = week.Week,
                                TeamId = team1.Id
                            },
                            new GameScore
                            {
                                Year   = schedule.Year,
                                Week   = week.Week,
                                TeamId = team2.Id
                            }
                        }
                    });
                }
            }

            GameHandler.AddGames(gamesToAdd);

            if (SeasonInfoHandler.GetSeason(schedule.Year) == null)
            {
                SeasonInfoHandler.Add(new SeasonInfo
                {
                    Year                = schedule.Year,
                    NumTeams            = schedule.NumTeams,
                    NumPlayoffTeams     = schedule.NumPlayoffTeams,
                    RegularSeasonLength = schedule.RegularSeasonLength,
                    PlayoffLength       = schedule.PlayoffLength
                });
            }
        }