Ejemplo n.º 1
0
        private static void ParseScorecard(FileStore dataStore, ScorecardDetails md)
        {
            CricketMatch m = dataStore.Load <CricketMatch>(CricketMatch.GenerateId(md.Season, md.MatchCode));

            if (m != null)
            {
                Log.InfoFormat("Match {0} ({1}) has already been imported", md.MatchCode, m);
                return;
            }

            Log.InfoFormat("Parsing scorecard for {0}", md);

            string scorecard = dataStore.LoadText(md.GenerateScorecardKey(), "html");

            if (string.IsNullOrEmpty(scorecard))
            {
                return;
            }

            DependencyFinder finder = new DependencyFinder(dataStore);
            ScorecardParser  parser = new ScorecardParser(md, finder);

            parser.Parse(scorecard);

            CricketMatch match = parser.Match;

            dataStore.Save(match, match.Id);

            Log.Info(match.ToLongString());
        }
Ejemplo n.º 2
0
 public ScorecardParser(ScorecardDetails details, DependencyFinder finder)
 {
     _finder = finder;
     _match  = new CricketMatch
     {
         Id        = CricketMatch.GenerateId(details.Season, details.MatchCode),
         MatchCode = details.MatchCode,
         HomeTeam  = details.HomeTeam,
         AwayTeam  = details.AwayTeam,
         Season    = details.Season,
         StartDate = details.Date,
         Players   = "11 per side",
         Innings   = new List <Innings>()
     };
 }
Ejemplo n.º 3
0
        private void RunMapFunctions(FileStore dataStore, Season season)
        {
            CrawlResults crawlResults = GetCrawlResultsForSeason(dataStore, season);

            if (crawlResults == null)
            {
                Log.WarnFormat("Season {0} has not been crawled yet.", season.Name);
                return;
            }

            Log.InfoFormat("Map started at {0} for season {1}", DateTime.Now.ToShortTimeString(), crawlResults.Season);

            var matchRecords = crawlResults.Classifications.SelectMany(m => m.Scorecards);

            if (matchRecords.Count() == 0)
            {
                Log.InfoFormat("No match records found for {0}", season.Name);
                return;
            }


            var battingTasks  = new Queue <Task <List <BattingRecord> > >();
            var bowlingTasks  = new Queue <Task <List <BowlingRecord> > >();
            var fieldingTasks = new Queue <Task <List <FieldingRecord> > >();

            foreach (ScorecardDetails details in matchRecords)
            {
                string       id    = CricketMatch.GenerateId(details.Season, details.MatchCode);
                CricketMatch match = dataStore.Load <CricketMatch>(id);
                if (match != null)
                {
                    battingTasks.Enqueue(Task <List <BattingRecord> > .Factory.StartNew(() => IndividualBattingMap.Run(match)));
                    bowlingTasks.Enqueue(Task <List <BowlingRecord> > .Factory.StartNew(() => IndividualBowlingMap.Run(match)));
                    fieldingTasks.Enqueue(Task <List <FieldingRecord> > .Factory.StartNew(() => IndividualFieldingMap.Run(match)));
                }
            }

            List <BattingRecord>  battingRecords  = new List <BattingRecord>();
            List <BowlingRecord>  bowlingRecords  = new List <BowlingRecord>();
            List <FieldingRecord> fieldingRecords = new List <FieldingRecord>();

            Task[] continuations = new[] {
                Task.Factory.ContinueWhenAll(battingTasks.ToArray(),
                                             completedTasks =>
                {
                    foreach (var task in completedTasks)
                    {
                        if (task.Exception == null)
                        {
                            battingRecords.AddRange(task.Result);
                        }
                        else
                        {
                            Log.Error("Unexpected exception", task.Exception);
                        }
                    }
                }),
                Task.Factory.ContinueWhenAll(bowlingTasks.ToArray(),
                                             completedTasks =>
                {
                    foreach (var task in completedTasks)
                    {
                        if (task.Exception == null)
                        {
                            bowlingRecords.AddRange(task.Result);
                        }
                        else
                        {
                            Log.Error("Unexpected exception", task.Exception);
                        }
                    }
                }),
                Task.Factory.ContinueWhenAll(fieldingTasks.ToArray(),
                                             completedTasks =>
                {
                    foreach (var task in completedTasks)
                    {
                        if (task.Exception == null)
                        {
                            fieldingRecords.AddRange(task.Result);
                        }
                        else
                        {
                            Log.Error("Unexpected exception", task.Exception);
                        }
                    }
                })
            };

            Task.WaitAll(continuations);



            dataStore.Save(battingRecords, IndividualBattingMap.GenerateId(season.Name));
            dataStore.Save(bowlingRecords, IndividualBowlingMap.GenerateId(season.Name));
            dataStore.Save(fieldingRecords, IndividualFieldingMap.GenerateId(season.Name));

            Log.InfoFormat("Scorecard parsing finished at {0} for season {1}", DateTime.Now.ToShortTimeString(), season.Name);
        }