示例#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);
        }
示例#2
0
        public static void CalculatePlayoffProb(int year, int week, bool force = false)
        {
            var exists = PlayoffProbabilityHandler.WeekExists(year, week);

            if (exists)
            {
                if (force)
                {
                    PlayoffProbabilityHandler.DeleteWeek(year, week);
                }
                else
                {
                    return;
                }
            }

            var apiStandings = GetStandings(year, week);
            var apiSchedule  = GetSchedule(year);

            Console.WriteLine("Calculating playoff probability for {0} week {1}", year, week);

            Api.Calculate(ref apiStandings, ref apiSchedule, out Api.PlayoffProbOutput apiPlayoffProbs);

            var playoffProbs = apiPlayoffProbs.PlayoffProbs.Select(pp =>
            {
                return(new PlayoffProbability
                {
                    Year = year,
                    Week = week,
                    TeamId = pp.TeamId,
                    ExcludingTiebreaker = pp.ExcludingTiebreakers,
                    IncludingTiebreaker = pp.IncludingTiebreakers
                });
            }).ToList();

            PlayoffProbabilityHandler.Add(playoffProbs);
        }