Beispiel #1
0
        public List <Team> GetTeamsWithPlayers(List <Player> players, League league)
        {
            ScraperManager scraperManager = new ScraperManager(_context);
            PlayerManager  playerManager  = new PlayerManager(_context);
            List <Team>    teams          = scraperManager.ScrapeLeague(league);

            foreach (Team team in teams)
            {
                for (int i = 0; i < team.Players.Count; i++)
                {
                    //get player with attributes that matches team's player
                    Player match = players.Where(p => p.Equals(team.Players[i])).FirstOrDefault();

                    if (team.Players[i].Position == "QB" || team.Players[i].Position == "RB" || team.Players[i].Position == "WR" || team.Players[i].Position == "TE")
                    {
                        playerManager.AddUnmatchedPlayer(new UnmatchedPlayer(team.Players[i]));
                    }

                    team.Players[i] = match;
                }

                team.Players.RemoveAll(p => p == null);
            }

            teams.RemoveAll(t => t == null || t.Players == null || t.Players.Count == 0);

            return(teams);
        }
Beispiel #2
0
        public List <Player> GetTradeValues(List <Player> players, League league)
        {
            ScraperManager scraperManager = new ScraperManager(_context);
            List <Team>    teams          = scraperManager.ScrapeLeague(league);

            //cuttoffs to determine baseline player
            int qbCuttoff = teams.Count * league.Quarterbacks;
            int rbCuttoff = teams.Count * (league.RunningBacks + league.Flexes);
            int wrCuttoff = teams.Count * (league.WideReceivers + league.Flexes);
            int teCuttoff = teams.Count * league.TightEnds;

            List <Player> quarterbacks  = players.Where(p => p.Position == "QB").ToList();
            List <Player> runningBacks  = players.Where(p => p.Position == "RB").ToList();
            List <Player> wideReceivers = players.Where(p => p.Position == "WR").ToList();
            List <Player> tightEnds     = players.Where(p => p.Position == "TE").ToList();

            int qbCuttoffIndex = Math.Min(qbCuttoff, quarterbacks.Count() - 1);
            int rbCuttoffIndex = Math.Min(rbCuttoff, runningBacks.Count() - 1);
            int wrCuttoffIndex = Math.Min(wrCuttoff, wideReceivers.Count() - 1);
            int teCuttoffIndex = Math.Min(teCuttoff, tightEnds.Count() - 1);

            //get baseline players
            Player qbBaseline = players.Where(p => p.Position == "QB").OrderByDescending(p => p.FantasyPoints).ElementAt(qbCuttoffIndex);
            Player rbBaseline = players.Where(p => p.Position == "RB").OrderByDescending(p => p.FantasyPoints).ElementAt(rbCuttoffIndex);
            Player wrBaseline = players.Where(p => p.Position == "WR").OrderByDescending(p => p.FantasyPoints).ElementAt(wrCuttoffIndex);
            Player teBaseline = players.Where(p => p.Position == "TE").OrderByDescending(p => p.FantasyPoints).ElementAt(teCuttoffIndex);

            foreach (Player player in players)
            {
                if (player.Position == "QB")
                {
                    player.TradeValue = player.FantasyPoints - qbBaseline.FantasyPoints;
                }
                else if (player.Position == "RB")
                {
                    player.TradeValue = player.FantasyPoints - rbBaseline.FantasyPoints;
                }
                else if (player.Position == "WR")
                {
                    player.TradeValue = player.FantasyPoints - wrBaseline.FantasyPoints;
                }
                else if (player.Position == "TE")
                {
                    player.TradeValue = player.FantasyPoints - teBaseline.FantasyPoints;
                }
            }

            return(players);
        }
        public List <Player> GetProjections()
        {
            ScraperManager scraperManager = new ScraperManager(_context);

            //assemble weekly projections
            List <List <Player> > projections            = new List <List <Player> >();
            List <Player>         beginSeasonProjections = null;
            List <Player>         nextWeekProjections    = null;

            int year        = GetCurrentYear();
            int currentWeek = GetCurrentWeek();
            int startWeek   = currentWeek - 5;

            if (currentWeek == 0)
            {
                return(scraperManager.ScrapeFantasyPros(0));
            }

            if (startWeek <= 0)
            {
                beginSeasonProjections = scraperManager.ScrapeFantasyPros(0);
            }

            for (int week = startWeek; week < currentWeek; week++)
            {
                if (week <= 0)
                {
                    projections.Add(beginSeasonProjections);
                }
                else
                {
                    List <Player> nflPlayers = scraperManager.ScrapeNfl(year, week);
                    projections.Add(nflPlayers);
                }
            }

            nextWeekProjections = scraperManager.ScrapeFantasyPros(currentWeek);

            return(MergeProjections(projections));
        }