示例#1
0
        public override Round GetRoundResultsHomeAndAway(int year, int roundNo)
        {
            var isFinal    = roundNo > numHomeandAwayRounds[year];
            var parameters = new Dictionary <string, string> {
                { "SeasonID", year.ToString() }, { "Round", isFinal ? roundNo - numHomeandAwayRounds[year] + "-2" : roundNo + "-1" }
            };
            var page = WebsiteAPI.GetPage(MatchResults, parameters);

            var link = MatchResults + "?SeasonID=" + year.ToString() + "&Round=" + (isFinal ? roundNo - numHomeandAwayRounds[year] + "-2" : roundNo + "-1");//http://finalsiren.com/Results.asp?SeasonID=2021&Round=12-1

            var web = new HtmlWeb();
            var doc = web.Load(link);

            var nodes = doc.DocumentNode.SelectNodes("//table//tr").Where(n => n.InnerText.Contains("dftd") || n.InnerText.Contains("lost to") || n.InnerText.Contains("drew") || n.InnerHtml.Contains("<td>v</td>")).ToList();

            var matches     = new List <Match>();
            var headerCheck = ": Round " + roundNo + " " + year;

            if (!doc.DocumentNode.InnerText.Contains(headerCheck))
            {
                return(new Round(Convert.ToInt32(year), roundNo, isFinal, matches));
            }

            foreach (var node in nodes)
            {
                var details = new List <string>();
                var home    = node.SelectNodes("td")[0].FirstChild.InnerText;
                var away    = node.SelectNodes("td")[7].FirstChild.InnerText;


                var match = new Match(
                    Util.GetTeamByName(home),
                    new Score(node.SelectNodes("td")[1].InnerText),
                    new Score(node.SelectNodes("td")[2].InnerText) - new Score(node.SelectNodes("td")[1].InnerText),
                    new Score(node.SelectNodes("td")[3].InnerText) - new Score(node.SelectNodes("td")[2].InnerText),
                    new Score(node.SelectNodes("td")[4].InnerText) - new Score(node.SelectNodes("td")[3].InnerText),
                    Util.GetTeamByName(away),
                    new Score(node.SelectNodes("td")[8].InnerText),
                    new Score(node.SelectNodes("td")[9].InnerText) - new Score(node.SelectNodes("td")[8].InnerText),
                    new Score(node.SelectNodes("td")[10].InnerText) - new Score(node.SelectNodes("td")[9].InnerText),
                    new Score(node.SelectNodes("td")[11].InnerText) - new Score(node.SelectNodes("td")[10].InnerText),
                    Util.GetGroundByName(node.SelectNodes("td")[13].SelectSingleNode("a").InnerText),
                    Util.StringToDate(node.SelectNodes("td")[14].InnerText + " " + year.ToString())
                    );
                var statsUrl = Website + node.SelectNodes("td")[15].FirstChild.GetAttributes("href").First().Value.Replace("ft_match_statistics?mid=", "").Replace("&amp;", "&");
                if (statsUrl.Contains("MatchDetails"))
                {
                    var matchStatistics = GetMatchResults(statsUrl, year, roundNo);
                    match.HomeStats         = matchStatistics.Item1;
                    match.HomeStats.For     = home;
                    match.HomeStats.Against = away;
                    match.AwayStats         = matchStatistics.Item2;
                    match.AwayStats.For     = away;
                    match.AwayStats.Against = home;
                }
                matches.Add(match);
            }

            return(new Round(Convert.ToInt32(year), roundNo, isFinal, matches));
        }
示例#2
0
        public List <Match> GetRoundResults(IEnumerable <HtmlNode> matchNodes, int year)
        {
            var dateReg  = new Regex("(Sun|Mon|Tue|Wed|Thu|Fri|Sat) ([0-9])+ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?(([0-9])+:([0-9])+.*pm)?");
            var matches  = new List <Match>();
            var dateHold = "";

            foreach (var node in matchNodes)
            {
                var date      = node.SelectSingleNode("td").InnerText;
                var dateMatch = dateReg.Match(date);
                if (dateMatch.Success)
                {
                    dateHold = dateMatch.ToString();
                }

                //Teams
                var home = node.SelectSingleNode("td[2]").SelectSingleNode("a[1]").InnerText;
                var away = node.SelectSingleNode("td[2]").SelectSingleNode("a[2]").InnerText;

                //Ground
                var ground = node.SelectSingleNode("td[3]").InnerText;

                var match = new Match(
                    Util.GetTeamByName(home),
                    new Score(),
                    new Score(),
                    new Score(),
                    new Score(),
                    Util.GetTeamByName(away),
                    new Score(),
                    new Score(),
                    new Score(),
                    new Score(),
                    Util.GetGroundByName(ground),
                    Util.StringToDate(dateHold + " " + year)
                    );

                var midTag = node.SelectSingleNode("td[5]").SelectSingleNode("a");

                if (midTag != null)
                {
                    var mid = midTag.GetAttributes("href").First().Value.Replace("ft_match_statistics?mid=", "");
                    ExtendMatch(match, mid);
                    AppendMatchStatistics(match, mid);
                }

                matches.Add(match);
            }
            return(matches);
        }
示例#3
0
        public void ExtendMatch(Match match, string mid)
        {
            var NUM_QUARTERS = 4;
            var QUARTER_SKIP = 1;
            var link         = Website + "/afl/footy/ft_match_statistics?mid=" + mid;
            var web          = new HtmlWeb();
            var doc          = web.Load(link);

            var nodes = doc.DocumentNode.SelectNodes("//table[@id='matchscoretable']//tr");

            for (int j = 1; j < nodes.Count(); j++)
            {
                var quarters = nodes[j].SelectNodes("td");

                var team = Util.GetTeamByName(quarters[0].InnerText);

                var goals  = new List <int>();
                var points = new List <int>();

                for (int i = QUARTER_SKIP; i < NUM_QUARTERS + QUARTER_SKIP; i++)
                {
                    var scoreparts = quarters[i].InnerText.Split('.');
                    goals.Add(Int32.Parse(scoreparts[0]) - goals.Sum());
                    points.Add(Int32.Parse(scoreparts[1]) - points.Sum());

                    if (match.Home.Equals(team))
                    {
                        match.Quarters[i - QUARTER_SKIP].HomeScore =
                            new Score(goals[i - QUARTER_SKIP], points[i - QUARTER_SKIP]);
                    }
                    else
                    {
                        match.Quarters[i - QUARTER_SKIP].AwayScore =
                            new Score(goals[i - QUARTER_SKIP], points[i - QUARTER_SKIP]);
                    }
                }
            }
        }
示例#4
0
        public void AppendMatchStatistics(Match match, string mid)
        {
            var link = Website + "/afl/footy/ft_match_statistics?mid=" + mid;
            var web  = new HtmlWeb();
            var doc  = web.Load(link);

            var nodes = doc.DocumentNode.SelectNodes("//table[tr/td[contains(text(),'Head to Head')]]//tr");

            if (match.HomeStats is null)
            {
                match.HomeStats = new MatchStatistics();
            }
            if (match.AwayStats is null)
            {
                match.AwayStats = new MatchStatistics();
            }

            foreach (var row in nodes.Skip(2))
            {
                if (row.SelectNodes("td")[0].InnerText == "" || row.SelectNodes("td")[0].InnerText.Contains("%"))
                {
                    continue;
                }
                var left  = Double.Parse(row.SelectNodes("td")[0].InnerText);
                var type  = row.SelectNodes("td")[1].InnerText;
                var right = Double.Parse(row.SelectNodes("td")[2].InnerText);

                switch (type)
                {
                case "Kicks":
                    match.HomeStats.Kicks = (int)Math.Round(left);
                    match.AwayStats.Kicks = (int)Math.Round(right);
                    break;

                case "Handballs":
                    match.HomeStats.Handballs = (int)Math.Round(left);
                    match.AwayStats.Handballs = (int)Math.Round(right);
                    break;

                case "Marks":
                    match.HomeStats.Marks = (int)Math.Round(left);
                    match.AwayStats.Marks = (int)Math.Round(right);
                    break;

                case "Tackles":
                    match.HomeStats.Tackles = (int)Math.Round(left);
                    match.AwayStats.Tackles = (int)Math.Round(right);
                    break;

                case "Hitouts":
                    match.HomeStats.HitOuts = (int)Math.Round(left);
                    match.AwayStats.HitOuts = (int)Math.Round(right);
                    break;

                case "Frees For":
                    match.HomeStats.FreesFor = (int)Math.Round(left);
                    match.AwayStats.FreesFor = (int)Math.Round(right);
                    break;

                case "Frees Against":
                    match.HomeStats.FreesAgainst = (int)Math.Round(left);
                    match.AwayStats.FreesAgainst = (int)Math.Round(right);
                    break;

                case "Rushed Behinds":
                    match.HomeStats.RushedBehinds = (int)Math.Round(left);
                    match.AwayStats.RushedBehinds = (int)Math.Round(right);
                    break;

                case "Clearances":
                    match.HomeStats.Clearances = (int)Math.Round(left);
                    match.AwayStats.Clearances = (int)Math.Round(right);
                    break;

                case "Clangers":
                    match.HomeStats.Clangers = (int)Math.Round(left);
                    match.AwayStats.Clangers = (int)Math.Round(right);
                    break;

                case "Rebound 50s":
                    match.HomeStats.Rebound50s = (int)Math.Round(left);
                    match.AwayStats.Rebound50s = (int)Math.Round(right);
                    break;

                case "Inside 50s":
                    match.HomeStats.Inside50s = (int)Math.Round(left);
                    match.AwayStats.Inside50s = (int)Math.Round(right);
                    break;

                default:
                    break;
                }
            }
        }