public ObservableCollection <csMlbTrends> ScrapTeams(string url) { ObservableCollection <csMlbTrends> data = new ObservableCollection <csMlbTrends>(); try { string result = string.Empty; HtmlAgilityPack.HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); csMlbTrends t1 = new csMlbTrends(); t1.TeamValue = ""; t1.Team = "ALL"; data.Add(t1); doc = web.Load(url); HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table"); if (tables != null) { for (int k = 0; k < tables.Count; k++) { HtmlNodeCollection rows = tables[k].SelectNodes(".//tr"); if (rows != null) { for (int i = 1; i < rows.Count; ++i) { csMlbTrends t = new csMlbTrends(); HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); if (cols != null) { for (int j = 0; j < (cols.Count - 1); ++j) { string txt = cols[j].InnerText.Replace("\r\n", "").Trim().Replace("\t\t (R)", "").Trim().Replace("\t\t (L)", "").Trim().Replace("\n\t\t", "").Trim(); if (!String.IsNullOrWhiteSpace(txt)) { if (j == 0) { t.Team = t.TeamValue = txt; } } } data.Add(t); } } } } } } catch (Exception ex) { int dsd = 0; } return(data); }
public csMlbTrends GetRank(string url) { csMlbTrends t = null; try { string result = string.Empty; HtmlAgilityPack.HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc = web.Load(url); HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table"); if (tables != null) { for (int k = 0; k < 1; k++) { HtmlNodeCollection rows = tables[k].SelectNodes(".//tr"); if (rows != null) { for (int i = 1; i < 2; ++i) { t = new csMlbTrends(); HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); if (cols != null) { for (int j = 0; j < cols.Count; ++j) { string txt = cols[j].InnerText.ToUpper().Replace("\r\n", "").Trim().Replace("\t\t (R)", "").Trim().Replace("\t\t (L)", "").Trim().Replace("\n\t\t", "").Trim().Replace("RECORD", "").Trim().Replace("PREDICTIVE RANK", "").Trim().Replace("#", "").Trim().Replace("STREAK", "").Trim(); if (!String.IsNullOrWhiteSpace(txt)) { if (j == 0) { t.Record = txt; } else if (j == 1) { t.Rank = txt; } else if (j == 2) { t.Streak = txt; } } } } } } } } } catch (Exception ex) { int dsd = 0; } return(t); }
public ObservableCollection <csMlbTrends> GetTrends(csMlbTrends t) { ObservableCollection <csMlbTrends> data = new ObservableCollection <csMlbTrends>(); try { //code here } catch (Exception ex) { throw new Exception(ex.Message); } return(data); }
public void PuclicateRank(csMlbTrends t) { try { if (t != null) { parameters.Clear(); parameters.Add("@pTeam", t.Team); parameters.Add("@pRank", t.Rank); parameters.Add("@pRecord", t.Record); parameters.Add("@pStreak", t.Streak); parameters.Add("@pSport", t.SportName); parameters.Add("@pDescription", null); parameters.Add("@pZone", null); csStats.ExecutePA("[dbo].[web_insertTeam]", parameters); } } catch (Exception ex) { int zxfc = 0; } }
protected void Trends(object sender, EventArgs e) { int year = Convert.ToInt32(inYear.Items[inYear.SelectedIndex].Value); string team = inTeam.Items[inTeam.SelectedIndex].Value; string OriginalTeam = team; if (team == "Chicago White Sox") { team = "sox"; } else if (team == "Chicago Cubs") { team = "cubs"; } else if (team == "Los Angeles Angels") { team = "angels"; } else if (team == "Los Angeles Dodgers") { team = "dodgers"; } else if (team == "New York Mets") { team = "mets"; } else if (team == "New York Yankees") { team = "yankees"; } else if (team == "San Francisco Giants") { team = "giants"; } TrendList = MLBInfo.ScrapTrends(year, year.ToString(), inShow.Items[inShow.SelectedIndex].Value, inSituation.Items[inSituation.SelectedIndex].Value, inType.Items[inType.SelectedIndex].Value, 3, "MLB", team); if (OriginalTeam != "") { csMlbTrends mlb = MLBInfo.GetRank("https://www.teamrankings.com/mlb/team/" + OriginalTeam.ToLower().Replace(" ", "-").Trim().Replace(".", "").Trim()); if (mlb != null) { lbRecord.Text = mlb.Record; lbRank.Text = mlb.Rank; lbStreak.Text = mlb.Streak; lbTeam.Text = OriginalTeam; mlb.SportName = "MLB"; mlb.Team = OriginalTeam; MLBInfo.PuclicateRank(mlb); } else { SetDefaultValue(); } } else { SetDefaultValue(); } rptTable.DataSource = TrendList; rptTable.DataBind(); MLBInfo.PuclicateTrends(TrendList); //runs per game Runs = MLBInfo.RunsPerGame("https://www.teamrankings.com/mlb/stat/runs-per-game?date=" + year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day, team, year); if (Runs != null) { runsTable.DataSource = Runs; runsTable.DataBind(); MLBInfo.PuclicateStats(Runs, "Runs Per Game", year, "MLB"); } //outs pitched OutPitched = MLBInfo.OutsPitched("https://www.teamrankings.com/mlb/stat/outs-pitched-per-game?date=" + year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day, team, year); if (OutPitched != null) { rptOutPitched.DataSource = OutPitched; rptOutPitched.DataBind(); MLBInfo.PuclicateStats(OutPitched, "Outs Pitched", year, "MLB"); } //runs allowed RunsAllowed = MLBInfo.RunsAllowed("https://www.teamrankings.com/mlb/player-stat/runs-allowed?season_id=" + (year - 1380), team, year); if (RunsAllowed != null) { rptRunsAllowed.DataSource = RunsAllowed; rptRunsAllowed.DataBind(); MLBInfo.PuclicateStats(RunsAllowed, "Runs Allowed", year, "MLB"); } }
public ObservableCollection <csMlbTrends> RunsAllowed(string url, string team, int year) { ObservableCollection <csMlbTrends> data = new ObservableCollection <csMlbTrends>(); try { string result = string.Empty; HtmlAgilityPack.HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc = web.Load(url); HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table"); if (tables != null) { for (int k = 0; k < tables.Count; k++) { HtmlNodeCollection rows = tables[k].SelectNodes(".//tr"); if (rows != null) { for (int i = 1; i < rows.Count; ++i) { csMlbTrends t = new csMlbTrends(); HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); if (cols != null) { for (int j = 0; j < cols.Count; ++j) { string txt = cols[j].InnerText.Replace("\r\n", "").Trim().Replace("\t\t (R)", "").Trim().Replace("\t\t (L)", "").Trim().Replace("\n\t\t", "").Trim(); if (!String.IsNullOrWhiteSpace(txt)) { if (j == 0) { t.Rank = txt; } else if (j == 1) { t.Player = txt; } else if (j == 2) { t.Team = t.TeamValue = txt; if (!(team.ToUpper().Contains(t.Team.ToUpper().Trim()) || t.Team.ToUpper().Contains(team.ToUpper().Trim()))) { break; } } else if (j == 3) { t.Pos = txt; } else if (j == 4) { t.Value = txt; } } } if (team.ToUpper().Contains(t.Team.ToUpper().Trim()) || t.Team.ToUpper().Contains(team.ToUpper().Trim())) { data.Add(t); } } } } } } } catch (Exception ex) { int dsd = 0; } return(data); }
public ObservableCollection <csMlbTrends> ScrapTrends(int yearInt, string year, string zone, string situation, string type, int idSport, string sportName, string team) { ObservableCollection <csMlbTrends> data = new ObservableCollection <csMlbTrends>(); try { string result = string.Empty; HtmlAgilityPack.HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); if (sportName == "NFL") { doc = web.Load("https://www.teamrankings.com/nfl/trends/" + type + "_trends/?range=yearly_" + year + "&group=" + zone + "&sc=" + situation); } else if (sportName == "MLB") { doc = web.Load("https://www.teamrankings.com/mlb/trends/" + type + "_trends/?range=yearly_mlb_" + year + "&group=" + zone + "&sc=" + situation); } else if (sportName == "NBA") { doc = web.Load("https://www.teamrankings.com/nba/trends/" + type + "_trends/?range=yearly_" + year + "&group=" + zone + "&sc=" + situation); } else if (sportName == "NCAAF") { //https://www.teamrankings.com/ncf/trends/win_trends/?range=yearly_2011&group=0&sc=all_games doc = web.Load("https://www.teamrankings.com/ncf/trends/" + type + "_trends/?range=yearly_" + year + "&group=" + zone + "&sc=" + situation); } else if (sportName == "NCAAB") { //https://www.teamrankings.com/ncb/trends/win_trends/?range=yearly_2011&group=0&sc=all_games doc = web.Load("https://www.teamrankings.com/ncb/trends/" + type + "_trends/?range=yearly_" + year + "&sc=" + situation + "&group=" + zone); } HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table"); if (tables != null) { for (int k = 0; k < tables.Count; k++) { HtmlNodeCollection rows = tables[k].SelectNodes(".//tr"); if (rows != null) { for (int i = 1; i < rows.Count; ++i) { csMlbTrends t = new csMlbTrends(); t.IdSport = idSport; t.Year = yearInt.ToString(); t.Situation = situation; t.Zone = zone; t.Type = type; t.SportName = sportName; //Headers HtmlNodeCollection headers = tables[k].SelectNodes(".//th"); if (headers != null) { for (int j = 0; j < headers.Count; ++j) { string txt = headers[j].InnerText.Trim(); if (j == 0) { t.H1 = txt; } else if (j == 1) { t.H2 = txt; } else if (j == 2) { t.H3 = txt; } else if (j == 3) { t.H4 = txt; } else if (j == 4) { t.H5 = txt; } } } HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); if (cols != null) { for (int j = 0; j < cols.Count; ++j) { string txt = cols[j].InnerText.Replace("\r\n", "").Trim().Replace("\t\t (R)", "").Trim().Replace("\t\t (L)", "").Trim().Replace("\n\t\t", "").Trim(); if (!String.IsNullOrWhiteSpace(txt)) { if (j == 0) { t.Team = t.TeamValue = txt; if (!(team.ToUpper().Contains(t.Team.ToUpper().Trim()) || t.Team.ToUpper().Contains(team.ToUpper().Trim()))) { break; } } else if (j == 1) { t.Line1 = txt; } else if (j == 2) { t.Line2 = txt; } else if (j == 3) { t.Line3 = txt; } else if (j == 4) { t.Line4 = txt; } } } if (team.ToUpper().Contains(t.Team.ToUpper().Trim()) || t.Team.ToUpper().Contains(team.ToUpper().Trim())) { data.Add(t); } } } } } } } catch (Exception ex) { int dsd = 0; } return(data); }