Ejemplo n.º 1
0
        private void AddBowling(HtmlNode bowlingNode, Innings innings)
        {
            HtmlNodeCollection rows = bowlingNode.SelectNodes(".//tr");

            if (rows == null)
            {
                return;
            }
            if (rows.Count < 2)
            {
                Log.WarnFormat("Only found {0} lines in the bowling HTML. Expected at least 2", rows.Count);
                return;
            }

            innings.Bowling = new List <BowlerInnings>();

            string team = ExtractWhoseBowling(rows[0]);

            for (int i = 1; i < rows.Count; i++)
            {
                BowlerInnings bowler = ParseBowlerInnings(rows[i]);
                bowler.Number = i;
                bowler.Team   = team;
                innings.Bowling.Add(bowler);
            }
        }
Ejemplo n.º 2
0
 private static BowlingRecord CreateBowlingRecord(BowlerInnings innings)
 {
     return(new BowlingRecord
     {
         PlayerId = innings.BowlerId,
         Team = innings.Team,
         BallsBowled = innings.BallsBowled.HasValue ? innings.BallsBowled.Value : 0,
         Maidens = innings.Maidens.HasValue ? innings.Maidens.Value : 0,
         Runs = innings.Runs.HasValue ? innings.Runs.Value : 0,
         Wickets = innings.Wickets.HasValue ? innings.Wickets.Value : 0,
         NoBalls = innings.NoBalls.HasValue ? innings.NoBalls.Value : 0,
         Wides = innings.Wides.HasValue ? innings.Wides.Value : 0
     });
 }
Ejemplo n.º 3
0
        private BowlerInnings ParseBowlerInnings(HtmlNode row)
        {
            HtmlNodeCollection cells   = row.SelectNodes("./td");
            BowlerInnings      innings = new BowlerInnings();

            HtmlNode playerNode = cells[0].FirstChild;

            if (playerNode.NodeType == HtmlNodeType.Element && playerNode.Name == "a")
            {
                innings.BowlerId = FindPlayerId(playerNode);
            }

            innings.NameOnScorecard = playerNode.InnerText;

            string oversText = GetTrimmedInnerText(cells[1]);

            if (oversText != "?" && oversText != "-")
            {
                string overs = oversText;
                string balls = null;
                int    dot   = oversText.LastIndexOf('.');
                if (dot >= 0)
                {
                    overs = oversText.Substring(0, dot);
                    balls = oversText.Substring(dot + 1);
                }
                int completedOvers = int.Parse(overs);
                int extraBalls     = string.IsNullOrEmpty(balls) ? 0 : int.Parse(balls);

                innings.Overs       = string.IsNullOrEmpty(balls) ? completedOvers.ToString() : string.Format("{0}.{1}", completedOvers, extraBalls);
                innings.BallsBowled = (completedOvers * _match.BallsPerOver) + extraBalls;
            }

            string maidensText = GetTrimmedInnerText(cells[2]);
            int    maidens;

            if (int.TryParse(maidensText, out maidens))
            {
                innings.Maidens = maidens;
            }

            string runsText = GetTrimmedInnerText(cells[3]);
            int    runs;

            if (int.TryParse(runsText, out runs))
            {
                innings.Runs = runs;
            }

            string wicketsText = GetTrimmedInnerText(cells[4]);
            int    wickets;

            if (int.TryParse(wicketsText, out wickets))
            {
                innings.Wickets = wickets;
            }

            string widesText = GetTrimmedInnerText(cells[5]);
            int    wides;

            if (int.TryParse(widesText, out wides))
            {
                innings.Wides = wides;
            }

            string noballsText = GetTrimmedInnerText(cells[6]);
            int    noballs;

            if (int.TryParse(noballsText, out noballs))
            {
                innings.NoBalls = noballs;
            }

            return(innings);
        }