private void GetSeasonTeProjections(ref Projections projections)
        {
            WebScraper   scraper  = new WebScraper(null, null, null);
            HtmlDocument document = scraper.Scrape("https://www.fantasypros.com/nfl/projections/te.php?week=draft");
            //HtmlDocument document = scraper.Scrape("https://web.archive.org/web/20150908002135/http://www.fantasypros.com/nfl/projections/te.php?week=draft");

            //get projection-data table from html
            HtmlNode table = document.GetElementbyId(FantasyProsProjectionTable).Descendants().Where(t => t.Name == "tbody").FirstOrDefault <HtmlNode>();

            //loop through rows in projection table
            foreach (HtmlNode row in table.SelectNodes("./tr"))
            {
                //create new datarow
                Player player = new Player();

                //parse name and team out of player cell
                FantasyProsParser parser = new FantasyProsParser(row.SelectSingleNode("./td[1]"));

                //convert to nfl values
                NflConverter converter = new NflConverter(parser.Name, parser.Team);

                //set row values
                player.Id                  = projections.SeasonProjectionPlayers.Count + 1;
                player.Name                = converter.Name;
                player.Position            = "TE";
                player.NflTeam             = converter.NflTeam;
                player.Receptions          = decimal.Parse(row.SelectSingleNode("./td[2]").InnerText) / 16;
                player.ReceivingYards      = decimal.Parse(row.SelectSingleNode("./td[3]").InnerText) / 16;
                player.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText) / 16;

                //add datarow to datatable
                projections.SeasonProjectionPlayers.Add(player);
            }
        }
Esempio n. 2
0
        public void ParseTeam(HtmlDocument document, League league, Team team, Projections projections)
        {
            //get table containing players of teams
            HtmlNode teamTable = document.GetElementbyId(TeamTableId);

            //get all rows with id's because they are the rows that have players
            List <HtmlNode> playerContainers = teamTable.Descendants().Where(row => row.Name == "div" &&
                                                                             row.Attributes["class"] != null &&
                                                                             row.Attributes["class"].Value.Contains(PlayerClass)
                                                                             ).ToList <HtmlNode>();

            foreach (HtmlNode playerContainer in playerContainers)
            {
                if (playerContainer != null && playerContainer.Id != null)
                {
                    HtmlNode nameAnchor = playerContainer.Descendants().Where(a => a.Name == "a" &&
                                                                              a.Attributes["class"] != null &&
                                                                              a.Attributes["class"].Value.Contains("name")
                                                                              ).FirstOrDefault <HtmlNode>();

                    //if nameanchor is null, then roster slot is empty
                    if (nameAnchor != null)
                    {
                        HtmlNode teamPositionSpan = playerContainer.Descendants().Where(a => a.Name == "span").FirstOrDefault <HtmlNode>();

                        //find indecies of start of team and position
                        int positionStart = teamPositionSpan.InnerText.LastIndexOf(" ") + 1;
                        int teamLength    = teamPositionSpan.InnerText.IndexOf(" ");

                        //get player attributes
                        string playerName     = nameAnchor.InnerText;
                        string playerPosition = teamPositionSpan.InnerText.Substring(positionStart);
                        string playerTeam     = teamPositionSpan.InnerText.Substring(0, teamLength).ToUpper();

                        //convert name and team to nfl values
                        NflConverter converter = new NflConverter(playerName, playerTeam);

                        //find player
                        Player player = projections.Players.Where(
                            p => p.Name == converter.Name && p.Position == playerPosition && p.NflTeam == converter.NflTeam
                            ).FirstOrDefault <Player>();

                        if (player != null)
                        {
                            projections.Players.Remove(player);
                            team.Players.Add(player);
                        }
                        else if (playerPosition == "QB" || playerPosition == "RB" || playerPosition == "WR" || playerPosition == "TE")
                        {
                            projections.UnMatchedPlayers.Add(playerName + ";" + playerPosition + ";" + playerTeam);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void ParseTeam(HtmlDocument document, League league, Team team, Projections projections)
        {
            //get table containing players of teams
            HtmlNode teamTable = document.GetElementbyId(TeamTableId);

            //get all rows with id's because they are the rows that have players
            List <HtmlNode> rows = teamTable.Descendants().Where(row => row.Name == "tr" && row.Id != null && row.Id != "").ToList <HtmlNode>();

            foreach (HtmlNode row in rows)
            {
                HtmlNode playerCell = row.SelectSingleNode("./td[2]");

                if (playerCell != null && playerCell.Id != null)
                {
                    HtmlNode statusNode = playerCell.Descendants().Where(s => s.Name == "span").FirstOrDefault <HtmlNode>();
                    if (statusNode != null)
                    {
                        playerCell.RemoveChild(statusNode);
                    }

                    string playerTeamPosition = playerCell.InnerText.Replace("&nbsp;", " ").Trim();

                    //find indecies of start of team and position
                    int positionStart = playerTeamPosition.LastIndexOf(" ") + 1;
                    int teamStart     = playerTeamPosition.Substring(0, positionStart - 1).LastIndexOf(" ");

                    //get player attributes
                    string playerName     = playerTeamPosition.Substring(0, teamStart - 1);
                    string playerPosition = playerTeamPosition.Substring(positionStart, playerTeamPosition.Length - positionStart).Trim();
                    string playerTeam     = playerTeamPosition.Substring(teamStart, positionStart - teamStart - 1).Trim().ToUpper();

                    //convert name and team to nfl values
                    NflConverter converter = new NflConverter(playerName, playerTeam);

                    //find player
                    Player player = projections.Players.Where(
                        p => p.Name == converter.Name && p.Position == playerPosition && p.NflTeam == converter.NflTeam
                        ).FirstOrDefault <Player>();

                    if (player != null)
                    {
                        projections.Players.Remove(player);
                        team.Players.Add(player);
                    }
                    else if (playerPosition == "QB" || playerPosition == "RB" || playerPosition == "WR" || playerPosition == "TE")
                    {
                        projections.UnMatchedPlayers.Add(playerName + ";" + playerPosition + ";" + playerTeam);
                    }
                }
            }
        }
Esempio n. 4
0
        public void ParseTeam(HtmlDocument document, League league, Team team, Projections projections)
        {
            //get table containing players of teams
            HtmlNode teamTable = document.GetElementbyId(TeamTableId).Descendants().Where(t => t.Name == "table").FirstOrDefault <HtmlNode>();

            //get all rows with id's because they are the rows that have players
            List <HtmlNode> rows = teamTable.Descendants().Where(row => row.Name == "tr" &&
                                                                 row.Attributes.Count > 0 &&
                                                                 row.Attributes["class"] != null &&
                                                                 row.Attributes["class"].Value.ToString() != "").ToList <HtmlNode>();

            foreach (HtmlNode row in rows)
            {
                HtmlNode playerCell = row.SelectSingleNode("./td[1]");

                if (playerCell != null && playerCell.Attributes["class"] != null && playerCell.Attributes["class"].Value == "player")
                {
                    string playerTeamPosition = playerCell.Descendants().Where(a => a.Name == "a").FirstOrDefault <HtmlNode>().InnerText;

                    //find indecies of start of team and position
                    int positionStart = playerTeamPosition.LastIndexOf(" ") + 1;
                    int teamStart     = playerTeamPosition.Substring(0, positionStart - 1).LastIndexOf(" ");

                    //split player names into array to rearange them
                    string[] playerNames = playerTeamPosition.Substring(0, teamStart).Split(',');

                    //get player attributes
                    string playerName     = playerNames[1].Trim() + " " + playerNames[0].Trim();
                    string playerPosition = playerTeamPosition.Substring(positionStart, playerTeamPosition.Length - positionStart).Trim();
                    string playerTeam     = playerTeamPosition.Substring(teamStart, positionStart - teamStart - 1).Trim().ToUpper();

                    //convert name and team to nfl values
                    NflConverter converter = new NflConverter(playerName, playerTeam);

                    //find player
                    Player player = projections.Players.Where(
                        p => p.Name == converter.Name && p.Position == playerPosition && p.NflTeam == converter.NflTeam
                        ).FirstOrDefault <Player>();

                    if (player != null)
                    {
                        projections.Players.Remove(player);
                        team.Players.Add(player);
                    }
                    else if (playerPosition == "QB" || playerPosition == "RB" || playerPosition == "WR" || playerPosition == "TE")
                    {
                        projections.UnMatchedPlayers.Add(playerName + ";" + playerPosition + ";" + playerTeam);
                    }
                }
            }
        }
Esempio n. 5
0
        public void ParseTeam(HtmlDocument document, League league, Team team, Projections projections)
        {
            //get table containing players of teams
            HtmlNode teamTable = document.DocumentNode.Descendants().Where(t => t.Name == "table" && t.Attributes["class"] != null && t.Attributes["class"].Value.Contains(TeamTableClass)).FirstOrDefault <HtmlNode>(); //

            //get all rows with id's because they are the rows that have players
            HtmlNode        body = teamTable.Descendants().Where(b => b.Name == "tbody").FirstOrDefault <HtmlNode>();
            List <HtmlNode> rows = body.Descendants().Where(row => row.Name == "tr" && row.Attributes["class"] != null && row.Attributes["class"].Value.Contains(PlayerRowClass)).ToList <HtmlNode>();

            foreach (HtmlNode row in rows)
            {
                //HtmlNode playerCell = row.SelectSingleNode("./td[4]").FirstChild;
                HtmlNode playerCell = row.Descendants().Where(c => c.Name == "td" && c.Attributes["class"] != null && c.Attributes["class"].Value == PlayerCellClass).FirstOrDefault();

                if (playerCell != null && playerCell.Id != null)
                {
                    HtmlNode playerNameAnchor = playerCell.Descendants().Where(a => a.Name == "a").FirstOrDefault <HtmlNode>();

                    if (playerNameAnchor != null)
                    {
                        //get player attributes
                        string playerName = playerCell.Descendants().Where(a => a.Name == "a").FirstOrDefault <HtmlNode>().InnerText;

                        string[] positionTeam   = playerCell.Descendants().Where(a => a.Name == "em").FirstOrDefault <HtmlNode>().InnerText.Split('-');
                        string   playerPosition = positionTeam[0].Trim();
                        string   playerTeam     = (positionTeam.Length > 1) ? positionTeam[1].Trim() : null;

                        //convert name and team to nfl values
                        NflConverter converter = new NflConverter(playerName, playerTeam);

                        //find player
                        Player player = projections.Players.Where(
                            p => p.Name == converter.Name && p.Position == playerPosition && p.NflTeam == converter.NflTeam
                            ).FirstOrDefault <Player>();

                        if (player != null)
                        {
                            projections.Players.Remove(player);
                            team.Players.Add(player);
                        }
                        else if (playerPosition == "QB" || playerPosition == "RB" || playerPosition == "WR" || playerPosition == "TE")
                        {
                            projections.UnMatchedPlayers.Add(playerName + ";" + playerPosition + ";" + playerTeam);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public void ParseTeam(HtmlDocument document, League league, Team team, Projections projections)
        {
            //get table containing players of teams
            HtmlNode teamTable = document.GetElementbyId(LeagueTableId);

            //get all rows with id's because they are the rows that have players
            List <HtmlNode> rows = teamTable.Descendants().Where(row => row.Name == "tr" && row.Id != null && row.Id != "").ToList <HtmlNode>();

            foreach (HtmlNode row in rows)
            {
                HtmlNode cell       = row.SelectSingleNode("./td[1]").FirstChild;
                HtmlNode nameAnchor = cell.FirstChild.Descendants().Where(a => a.Name == "a").FirstOrDefault <HtmlNode>();

                if (nameAnchor != null)
                {
                    string playerName     = cell.FirstChild.Descendants().Where(a => a.Name == "a").FirstOrDefault <HtmlNode>().InnerText;
                    string playerPosition = cell.LastChild.Descendants().Where(s => s.Name == "span" && s.Attributes["class"].Value == "position").FirstOrDefault <HtmlNode>().InnerText;
                    string playerTeam     = cell.LastChild.Descendants().Where(s => s.Name == "span" && s.Attributes["class"].Value == "player-team").FirstOrDefault <HtmlNode>().InnerText.ToUpper();

                    //convert name and team to nfl values
                    NflConverter converter = new NflConverter(playerName, playerTeam);

                    //find player
                    Player player = projections.Players.Where(
                        p => p.Name == converter.Name && p.Position == playerPosition && p.NflTeam == converter.NflTeam
                        ).FirstOrDefault <Player>();

                    if (player != null)
                    {
                        projections.Players.Remove(player);
                        team.Players.Add(player);
                    }
                    else if (playerPosition == "QB" || playerPosition == "RB" || playerPosition == "WR" || playerPosition == "TE")
                    {
                        projections.UnMatchedPlayers.Add(playerName + ";" + playerPosition + ";" + playerTeam);
                    }
                }
            }
        }
        private void GetSeasonStatistics(ref Projections projections)
        {
            WebScraper scraper = new WebScraper(null, null, null);
            //JObject json = scraper.ScrapeJson("http://api.fantasy.nfl.com/v1/players/stats?statType=seasonStats&season=2016&format=json");
            //JObject json = scraper.ScrapeJson("http://api.fantasy.nfl.com/v1/players/stats?statType=seasonStats&season=2015&format=json");
            JObject json = scraper.ScrapeJson("http://api.fantasy.nfl.com/v1/players/stats?statType=seasonStats&season=2016&format=json");
            //http://api.fantasy.nfl.com/v1/players/stats?statType=weekStats&season=2015&week=1&format=json

            var players =
                from player in json["players"]
                select player;

            //loop through rows in projection table
            foreach (JObject jPlayer in players)
            {
                //create new datarow
                Player player = new Player();

                //create fantasy pro converter
                NflConverter converter = new NflConverter(jPlayer["name"].ToString(), jPlayer["teamAbbr"].ToString());

                //set row values
                player.Id          = projections.StatisticsPlayers.Count + 1;
                player.Name        = jPlayer["name"].ToString();
                player.NflTeam     = jPlayer["teamAbbr"].ToString();
                player.Position    = jPlayer["position"].ToString().ToUpper();
                player.GamesPlayed = int.Parse(IsNullStat(jPlayer["stats"][GamesPlayed]));

                if (player.Position == "QB")
                {
                    player.PassingYards      = decimal.Parse(IsNullStat(jPlayer["stats"][PassingYards]));
                    player.PassingTouchdowns = decimal.Parse(IsNullStat(jPlayer["stats"][PassingTouchdowns]));
                    player.Interceptions     = decimal.Parse(IsNullStat(jPlayer["stats"][Interceptions]));
                    player.RushingYards      = decimal.Parse(IsNullStat(jPlayer["stats"][RushingYards]));
                    player.RushingTouchdowns = decimal.Parse(IsNullStat(jPlayer["stats"][RushingTouchdowns]));

                    //add datarow to datatable
                    projections.StatisticsPlayers.Add(player);
                }
                if (player.Position == "RB")
                {
                    player.RushingYards        = decimal.Parse(IsNullStat(jPlayer["stats"][RushingYards]));
                    player.RushingTouchdowns   = decimal.Parse(IsNullStat(jPlayer["stats"][RushingTouchdowns]));
                    player.Receptions          = decimal.Parse(IsNullStat(jPlayer["stats"][Receptions]));
                    player.ReceivingYards      = decimal.Parse(IsNullStat(jPlayer["stats"][ReceivingYards]));
                    player.ReceivingTouchdowns = decimal.Parse(IsNullStat(jPlayer["stats"][ReceivingTouchdowns]));

                    //add datarow to datatable
                    projections.StatisticsPlayers.Add(player);
                }
                if (player.Position == "WR")
                {
                    player.RushingYards        = decimal.Parse(IsNullStat(jPlayer["stats"][RushingYards]));
                    player.RushingTouchdowns   = decimal.Parse(IsNullStat(jPlayer["stats"][RushingTouchdowns]));
                    player.Receptions          = decimal.Parse(IsNullStat(jPlayer["stats"][Receptions]));
                    player.ReceivingYards      = decimal.Parse(IsNullStat(jPlayer["stats"][ReceivingYards]));
                    player.ReceivingTouchdowns = decimal.Parse(IsNullStat(jPlayer["stats"][ReceivingTouchdowns]));

                    //add datarow to datatable
                    projections.StatisticsPlayers.Add(player);
                }
                if (player.Position == "TE")
                {
                    player.Receptions          = decimal.Parse(IsNullStat(jPlayer["stats"][Receptions]));
                    player.ReceivingYards      = decimal.Parse(IsNullStat(jPlayer["stats"][ReceivingYards]));
                    player.ReceivingTouchdowns = decimal.Parse(IsNullStat(jPlayer["stats"][ReceivingTouchdowns]));

                    //add datarow to datatable
                    projections.StatisticsPlayers.Add(player);
                }
            }
        }