public void ImportQbHtml() { //get qb data string html = ""; //Thread qbThread = new Thread(() => html = ScrapeBrowser(qbProjectionUrl)); //qbThread.SetApartmentState(ApartmentState.STA); //qbThread.Start(); //qbThread.Join(); Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); String path = Directory.GetCurrentDirectory() + "\\Html\\quarterbacks.html"; html = File.ReadAllText(path); //create html object and load html into it HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(html); //get projection-data table from html HtmlNode projectionTable = document.GetElementbyId(projectionTableName); //loop through rows in projection-data foreach (HtmlNode row in projectionTable.SelectNodes("./tr")) { //create new datarow Quarterback quarterback = new Quarterback(); NumberFireParser numberFireParser = new NumberFireParser(row.SelectSingleNode("./td[1]").InnerText); //set row values quarterback.SessionId = _league.CurrentSessionId; quarterback.LeagueId = _league.LeagueId; quarterback.Name = numberFireParser.Player; quarterback.Position = numberFireParser.Position; quarterback.NflTeam = numberFireParser.Team; quarterback.NflAlternateTeam = numberFireParser.AlternateTeam; quarterback.PassingAttempts = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText.Split('/')[0]); quarterback.PassingCompletions = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText.Split('/')[1]); quarterback.PassingYards = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText); quarterback.PassingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[6]").InnerText); quarterback.Interceptions = decimal.Parse(row.SelectSingleNode("./td[7]").InnerText); quarterback.RushingAttempts = decimal.Parse(row.SelectSingleNode("./td[8]").InnerText); quarterback.RushingYards = decimal.Parse(row.SelectSingleNode("./td[9]").InnerText); quarterback.RushingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[10]").InnerText); quarterback.Points = decimal.Parse(row.SelectSingleNode("./td[12]").InnerText); //add datarow to datatable db.Players.Add(quarterback); db.SaveChanges(); } }
private DataTable GetPositionPlayers(DataTable players, HtmlDocument document) { //initialize datatable to return DataTable teamPlayers = new DataTable(); teamPlayers.Columns.Add("Player", typeof(string)); teamPlayers.Columns.Add("Position", typeof(string)); teamPlayers.Columns.Add("Team", typeof(string)); foreach (DataRow dataRow in players.Rows) { NumberFireParser parser = new NumberFireParser(dataRow["Player"].ToString()); string playerName = parser.Player; string playerPosition = parser.Position; string playerTeam = parser.Team; string playerAlternateTeam = parser.AlternateTeam; if (FindPlayerInHtml(document, Team.League.LeagueHost.StarterTableName, playerName, playerPosition, playerTeam, playerAlternateTeam)) { DataRow row = teamPlayers.NewRow(); row["Player"] = playerName; row["Position"] = playerPosition; row["Team"] = playerTeam; teamPlayers.Rows.Add(row); } } return teamPlayers; }
public void ImportWrHtml() { //get wr data string html = ""; //Thread wrThread = new Thread(() => html = ScrapeBrowser(wrProjectionUrl)); //wrThread.SetApartmentState(ApartmentState.STA); //wrThread.Start(); //wrThread.Join(); Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); String path = Directory.GetCurrentDirectory() + "\\Html\\widereceivers.html"; html = File.ReadAllText(path); //create html object and load html into it HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(html); //get projection-data table from html and initialize datatable to return HtmlNode projectionTable = document.GetElementbyId(projectionTableName); //loop through rows in projection-data foreach (HtmlNode row in projectionTable.SelectNodes("./tr")) { //create new datarow WideReceiver wideReceiver = new WideReceiver(); NumberFireParser numberFireParser = new NumberFireParser(row.SelectSingleNode("./td[1]").InnerText); //set row values wideReceiver.SessionId = _league.CurrentSessionId; wideReceiver.LeagueId = _league.LeagueId; wideReceiver.Name = numberFireParser.Player; wideReceiver.Position = numberFireParser.Position; wideReceiver.NflTeam = numberFireParser.Team; wideReceiver.NflAlternateTeam = numberFireParser.AlternateTeam; wideReceiver.RushingAttempts = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText); wideReceiver.RushingYards = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText); wideReceiver.RushingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[6]").InnerText); wideReceiver.Receptions = decimal.Parse(row.SelectSingleNode("./td[7]").InnerText); wideReceiver.ReceivingYards = decimal.Parse(row.SelectSingleNode("./td[8]").InnerText); wideReceiver.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[9]").InnerText); wideReceiver.Points = decimal.Parse(row.SelectSingleNode("./td[11]").InnerText); //add datarow to datatable db.Players.Add(wideReceiver); db.SaveChanges(); } }
public decimal OptimalLineUpPoints(List<DataRow> playersGained, List<DataRow> playersLost) { //get array of datarows for current team List<DataRow> team = new List<DataRow>(TeamTable.AsEnumerable()); //add gained players to team foreach (DataRow player in playersGained) { team.Add(player); } //remove lost players from team foreach (DataRow player in playersLost) { //make numberFireParser to compare lost player with players in team table NumberFireParser numberFireParser = new NumberFireParser(player["Player"].ToString()); //find lost player DataRow lostPlayer = FindPlayerInDataRows(team, numberFireParser.Player, numberFireParser.Position, numberFireParser.Team, numberFireParser.AlternateTeam); //remove lost player if (lostPlayer != null) { team.Remove(lostPlayer); } } return OptimalLineUpPoints(team); }