private void setupTournamentHands(TreeNode parentNode, PokerFormat format)
        {
            DatabaseHandler databaseHandler = DatabaseHandler.getInstance();
            IAggregateFluent <TournamentSummary> tournaments = databaseHandler.GetAllTournaments()
                                                               .Aggregate().Match(Builders <TournamentSummary> .Filter.Where(h => h.SitAndGo == (format == PokerFormat.SitAndGo)));
            IAggregateFluent <HandHistory> allHands = databaseHandler.GetAllHands().Aggregate()
                                                      .Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.PokerFormat == format));
            IEnumerable <AggregateResult <Buyin> > allBuyins =
                tournaments.Group(h => h.Buyin, h => new AggregateResult <Buyin> {
                result = h.Key
            })
                .Sort(Builders <AggregateResult <Buyin> > .Sort.Ascending(b => b.result))
                .ToEnumerable();

            decimal lastBuyin = -0.01m;

            foreach (dynamic buyinObj in allBuyins)
            {
                Buyin buyin = buyinObj.result;

                if (buyin.Total == lastBuyin)
                {
                    continue;
                }
                lastBuyin = buyin.Total;
                IAggregateFluent <HandHistory> hands =
                    allHands.Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.TournamentSummary.Buyin.Total == buyin.Total));
                GroupHandTreeNode buyinNode =
                    new GroupHandTreeNode(string.Format("{0}{1} {2}", buyin.GetCurrencySymbol(),
                                                        buyin.Total,
                                                        HandCount(hands)),
                                          hands);
                dynamic allIds = hands.Group(h => h.GameDescription.TournamentId, h => new { name = h.Key }).ToEnumerable();

                foreach (dynamic idObj in allIds)
                {
                    string id = idObj.name;

                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        IEnumerable <TournamentSummary> summaries = tournaments.Match(t => t.Id == id).ToEnumerable();

                        if (summaries.Count() > 0)
                        {
                            TournamentSummary summary = summaries.First();

                            IAggregateFluent <HandHistory> tournyHands =
                                allHands.Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.TournamentId == summary.Id));
                            buyinNode.Nodes.Add(new HandsTreeNode(summary.ToString(), tournyHands));
                        }
                    }
                }

                if (buyinNode.Nodes.Count > 0)
                {
                    parentNode.Nodes.Add(buyinNode);
                }
            }
        }
示例#2
0
        public override TournamentSummary ParseTournamentSummary(string handHistoryFile)
        {
            TournamentSummary summary   = base.ParseTournamentSummary(handHistoryFile);
            Match             stepMatch = StepTournaments.Match(GetTournamentFile(handHistoryFile));

            if (stepMatch.Success)
            {
                HandHistory lastHand =
                    HandHistoryParser.ParseFullHandHistory(
                        ((HandHistoryParserFast)HandHistoryParser).SplitUpMultipleHands(File.ReadAllText(handHistoryFile)).Last());

                if (lastHand.Hero.StartingStack > -lastHand.HandActions.Where(a => a.PlayerName.Equals(lastHand.Hero.PlayerName))
                    .Sum(a => a.Amount))
                {
                    summary.Winnings = StepPrizes[int.Parse(stepMatch.Groups[0].Value) - 1];
                }
            }

            return(summary);
        }
示例#3
0
 public void Add(TournamentSummary tournament)
 {
     database.GetCollection <TournamentSummary>(Collections.tournaments).InsertOne(tournament);
 }
        private void parsingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Dictionary <HandHistoryParserFactory, IEnumerable <FileInfo> > factories =
                new Dictionary <HandHistoryParserFactory, IEnumerable <FileInfo> >();
            int totalFiles = 0;

            foreach (string siteDetailsString in Settings.Default.Sites)
            {
                SiteDetails details = new SiteDetails(siteDetailsString);
                HandHistoryParserFactory parserFactory = HandHistoryParserFactory.GetHandHistoryParserFactory(details);
                DirectoryInfo            info          = new DirectoryInfo(details.HandsLocation);
                IEnumerable <FileInfo>   files         = info.GetFiles().Where(fi => parserFactory.IsHandHistoryFile(fi) &&
                                                                               fi.LastWriteTime > lastUpdate);
                totalFiles += files.Count();
                factories.Add(parserFactory, files);
            }

            handsFound       = 0;
            tournamentsFound = 0;

            float fileProgressInc = 100.0f / totalFiles;
            int   filesProcessed  = 0;

            foreach (HandHistoryParserFactory factory in factories.Keys)
            {
                factory.HandHistoryParser.AmountsAsBigBlindMultiples = true;
                foreach (FileInfo file in factories[factory])
                {
                    int         byteCount  = 0;
                    HandHistory parsedHand = null;

                    TournamentSummary tournamentSummary = null;

                    if (factory.HasTournamentSummaryParser() && File.Exists(factory.GetTournamentFile(file.FullName)))
                    {
                        tournamentSummary = factory.ParseTournamentSummary(file.FullName);
                        DatabaseHandler.Add(tournamentSummary);
                        ++tournamentsFound;
                    }
                    IEnumerable <HandHistory> hands = factory.ParseHandHistories(file.FullName);
                    float totalHands = (float)hands.Count();
                    int   fileHands  = 0;

                    foreach (HandHistory hand in hands)
                    {
                        if (parsingWorker.CancellationPending)
                        {
                            break;
                        }

                        try
                        {
                            parsedHand = hand;
                            string tournamentId = parsedHand.GameDescription.TournamentId;

                            if (tournamentSummary != null)
                            {
                                parsedHand.GameDescription.TournamentSummary = tournamentSummary;
                            }
                            DatabaseHandler.Add(parsedHand);
                            byteCount += parsedHand.FullHandHistoryText.Length;
                            ++handsFound;
                            ++fileHands;
                            float progress = (int)((filesProcessed + fileHands / totalHands) * fileProgressInc);
                            parsingWorker.ReportProgress((int)progress);
                        }
                        catch (MongoWriteException ex)
                        {
                            Console.Write("Failed");
                        }
                        catch (HandParseException ex)
                        {
                            Console.Write("Parsing failed for: " + string.Concat(ex.HandText) + "\n");
                        }
                    }
                    if (parsingWorker.CancellationPending)
                    {
                        break;
                    }

                    ++filesProcessed;
                    parsingWorker.ReportProgress((int)(filesProcessed * fileProgressInc));
                }
            }

            parsingWorker.ReportProgress(100);
        }