Exemplo n.º 1
0
        private void AddBatting(HtmlNode battingNode, Innings innings)
        {
            HtmlNodeCollection rows = battingNode.SelectNodes(".//tr");

            ExtractWhoseInnings(rows[0], innings);

            innings.Batting = new List <BatsmanInnings>();

            int i = 1;

            while (i < rows.Count)
            {
                HtmlNode cell       = rows[i].SelectSingleNode("./td[1]");
                HtmlNode playerNode = cell.SelectSingleNode("./a");
                if (playerNode == null && (cell.InnerText == "Extras" || cell.InnerText == "Total" || cell.InnerText == "Innings Forfeited"))
                {
                    break;
                }
                BatsmanInnings batsman = ParseBatsmanInnings(rows[i], (innings.BattingTeam == "Somerset" && innings.TeamInningsNumber == 1));
                batsman.Number = i;
                batsman.Team   = innings.BattingTeam;
                innings.Batting.Add(batsman);

                i++;
            }

            while (i < rows.Count)
            {
                HtmlNode cell  = rows[i].SelectSingleNode("./td[1]");
                string   label = (cell != null ? cell.InnerText : null);
                if (string.IsNullOrEmpty(label))
                {
                    i++;
                    continue;
                }

                if (label == "Innings Forfeited")
                {
                    innings.Forfeited = true;
                    break;
                }

                if (label == "Extras")
                {
                    ProcessExtras(rows[i], innings);
                }
                if (label == "Total")
                {
                    ProcessTotal(rows[i], innings);
                }
                if (label == "Fall of wickets:")
                {
                    ProcessFallOfWickets(rows[i + 1], innings);
                    i++;
                }

                i++;
            }
        }
Exemplo n.º 2
0
        private static void ProcessHowOut(HtmlNode cell, BatsmanInnings innings)
        {
            List <string>      players     = new List <string>();
            HtmlNodeCollection playerNodes = cell.SelectNodes("./a");

            if (playerNodes != null && playerNodes.Count > 0)
            {
                players.AddRange(cell.SelectNodes("./a").Select(FindPlayerId));
            }

            IHowOut howOut = HowOutFactory.GetHowOut(GetTrimmedInnerText(cell.FirstChild));

            innings.HowOut    = howOut.HowOutType;
            innings.IsInnings = howOut.IsInnings;
            innings.IsOut     = howOut.IsOut;
            if (howOut.HasFielder)
            {
                innings.FielderId = howOut.GetFielder(players);
            }
            if (howOut.HasBowler)
            {
                innings.BowlerId = howOut.GetBowler(players);
            }
        }
Exemplo n.º 3
0
        private BatsmanInnings ParseBatsmanInnings(HtmlNode row, bool saveCaptainAndKeeper)
        {
            BatsmanInnings     innings = new BatsmanInnings();
            HtmlNodeCollection cells   = row.SelectNodes("./td");

            HtmlNode player = cells[0].LastChild;

            if (player.NodeType == HtmlNodeType.Element && player.Name == "a")
            {
                string batsmanId = FindPlayerId(player);
                innings.PlayerId = batsmanId;

                if (saveCaptainAndKeeper)
                {
                    string icons = "";
                    if (cells[0].FirstChild.NodeType == HtmlNodeType.Text)
                    {
                        icons = cells[0].FirstChild.InnerText;
                    }

                    bool isKeeper  = icons.Contains("+");
                    bool isCaptain = icons.Contains("*");

                    if (isKeeper)
                    {
                        SetKeeper(batsmanId);
                    }
                    if (isCaptain)
                    {
                        SetCaptain(batsmanId);
                    }
                }
            }

            string runs = null;

            if (cells.Count >= 3)
            {
                runs = cells[2].InnerText.Replace("&nbsp;", "").Replace("-", "");
            }
            string balls = null;

            if (cells.Count >= 4)
            {
                balls = cells[3].InnerText.Replace("&nbsp;", "").Replace("-", "");
            }
            string mins = null;

            if (cells.Count >= 4)
            {
                mins = cells[4].InnerText.Replace("&nbsp;", "").Replace("-", "");
            }
            string fours = null;

            if (cells.Count >= 4)
            {
                fours = cells[5].InnerText.Replace("&nbsp;", "").Replace("-", "");
            }
            string sixes = null;

            if (cells.Count >= 4)
            {
                sixes = cells[6].InnerText.Replace("&nbsp;", "").Replace("-", "");
            }

            innings.NameOnScorecard = player.InnerText;
            innings.HowOutText      = cells[1].InnerText;

            if (!string.IsNullOrEmpty(runs) && !string.IsNullOrWhiteSpace(runs))
            {
                innings.Runs = int.Parse(runs);
            }
            if (!string.IsNullOrEmpty(balls) && !string.IsNullOrWhiteSpace(balls))
            {
                innings.Balls = int.Parse(balls);
            }
            if (!string.IsNullOrEmpty(mins) && !string.IsNullOrWhiteSpace(mins))
            {
                innings.Minutes = int.Parse(mins);
            }
            if (!string.IsNullOrEmpty(fours) && !string.IsNullOrWhiteSpace(fours))
            {
                innings.Fours = int.Parse(fours);
            }
            if (!string.IsNullOrEmpty(sixes) && !string.IsNullOrWhiteSpace(sixes))
            {
                innings.Sixes = int.Parse(sixes);
            }

            ProcessHowOut(cells[1], innings);

            return(innings);
        }
Exemplo n.º 4
0
        private static BattingRecord CreateBattingRecord(BatsmanInnings innings, bool firstInnings)
        {
            var record = new BattingRecord
            {
                PlayerId = innings.PlayerId,
                Team     = innings.Team,
                Runs     = innings.Runs,
                Minutes  = innings.Minutes,
                Balls    = innings.Balls,
                Fours    = innings.Fours,
                Sixes    = innings.Sixes,
                Matches  = firstInnings ? 1 : 0,
                Innings  = innings.IsInnings ? 1 : 0,
                NotOut   = innings.IsInnings && !innings.IsOut ? 1 : 0
            };

            switch (innings.HowOut)
            {
            case HowOutType.Absent:
            case HowOutType.AbsentHurt:
            case HowOutType.AbsentIll:
                record.Absent = 1;
                break;

            case HowOutType.Bowled:
                record.Bowled = 1;
                break;

            case HowOutType.Caught:
                record.Caught = 1;
                break;

            case HowOutType.LBW:
                record.Lbw = 1;
                break;

            case HowOutType.HitWicket:
                record.HitWicket = 1;
                break;

            case HowOutType.RunOut:
                record.RunOut = 1;
                break;

            case HowOutType.Stumped:
                record.Stumped = 1;
                break;

            case HowOutType.HitTheBallTwice:
            case HowOutType.ObstructingTheField:
            case HowOutType.Unknown:
                record.Other = 1;
                break;

            case HowOutType.RetiredHurt:
            case HowOutType.RetiredIll:
            case HowOutType.RetiredNotOut:
            case HowOutType.RetiredOut:
                record.Retired = 1;
                break;
            }


            return(record);
        }