예제 #1
0
            public bool Equals(PlayerPokerSiteKey obj)
            {
                if (obj == null)
                {
                    return(false);
                }

                return(PlayerId == obj.PlayerId && PokerSite == obj.PokerSite && PlayerName == obj.PlayerName);
            }
예제 #2
0
        private ParsingResult ParseHandHistory(Handhistory handHistory)
        {
            if (string.IsNullOrEmpty(handHistory.HandhistoryVal))
            {
                LogProvider.Log.Warn(CustomModulesNames.PlayerXRay, $"Hand #{handHistory.Gamenumber} has been skipped, because it has no history.");
                return(null);
            }

            var pokerSite = (EnumPokerSites)handHistory.PokersiteId;

            var pokerSiteNetwork = EntityUtils.GetSiteNetwork(pokerSite);

            var handHistoryParser = pokerSite == EnumPokerSites.Unknown || pokerSiteNetwork == EnumPokerNetworks.WPN ?
                                    handHistoryParserFactory.GetFullHandHistoryParser(handHistory.HandhistoryVal) :
                                    handHistoryParserFactory.GetFullHandHistoryParser(pokerSite);

            var parsedHand = handHistoryParser.ParseFullHandHistory(handHistory.HandhistoryVal, true);

            var gameType = new Gametypes
            {
                Anteincents       = Utils.ConvertToCents(parsedHand.GameDescription.Limit.Ante),
                Bigblindincents   = Utils.ConvertToCents(parsedHand.GameDescription.Limit.BigBlind),
                CurrencytypeId    = (short)parsedHand.GameDescription.Limit.Currency,
                Istourney         = parsedHand.GameDescription.IsTournament,
                PokergametypeId   = (short)(parsedHand.GameDescription.GameType),
                Smallblindincents = Utils.ConvertToCents(parsedHand.GameDescription.Limit.SmallBlind),
                Tablesize         = (short)parsedHand.GameDescription.SeatType.MaxPlayers
            };

            var players = parsedHand.Players.Select(player =>
            {
                var playerPokerSiteKey = new PlayerPokerSiteKey(player.PlayerName, (int)pokerSite);

                if (playersDictionary.ContainsKey(playerPokerSiteKey))
                {
                    return(playersDictionary[playerPokerSiteKey]);
                }

                return(new Players
                {
                    Playername = player.PlayerName,
                    PokersiteId = (short)pokerSite
                });
            }).ToList();

            var parsingResult = new ParsingResult
            {
                HandHistory = handHistory,
                Players     = players,
                GameType    = gameType,
                Source      = parsedHand
            };

            return(parsingResult);
        }
예제 #3
0
        /// <summary>
        /// Builds players dictionary
        /// </summary>
        private void BuildPlayersDictonary(IStatelessSession session)
        {
            playersDictionary = new Dictionary <PlayerPokerSiteKey, Players>();

            var players = session.Query <Players>().ToArray();

            players.ForEach(player =>
            {
                var playerPokerSiteKey = new PlayerPokerSiteKey(player.Playername, player.PokersiteId);

                if (!playersDictionary.ContainsKey(playerPokerSiteKey))
                {
                    playersDictionary.Add(playerPokerSiteKey, player);
                }
            });
        }
        /// <summary>
        /// Builds players dictionary
        /// </summary>
        private void BuildPlayersDictonary()
        {
            playersDictionary = new Dictionary <PlayerPokerSiteKey, Players>();

            using (var session = ModelEntities.OpenStatelessSession())
            {
                var players = session.Query <Players>().ToArray();

                players.ForEach(player =>
                {
                    var playerPokerSiteKey = new PlayerPokerSiteKey(player.Playername, player.PokersiteId);

                    if (!playersDictionary.ContainsKey(playerPokerSiteKey))
                    {
                        playersDictionary.Add(playerPokerSiteKey, player);
                    }
                });
            }
        }
예제 #5
0
        public void ProcessNotes(IEnumerable <NoteObject> notes, CancellationTokenSource cancellationTokenSource)
        {
            try
            {
                if (!licenseService.IsRegistered || (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested))
                {
                    return;
                }

                var currentPlayerIds = new HashSet <int>(storageModel.PlayerSelectedItem.PlayerIds);

                var noteService = ServiceLocator.Current.GetInstance <IPlayerNotesService>() as IPlayerXRayNoteService;

                var sinceDate = noteService.CurrentNotesAppSettings.IsNoteCreationSinceDate ?
                                noteService.CurrentNotesAppSettings.NoteCreationSinceDate : (DateTime?)null;

                var isAdvancedLogEnabled = noteService.CurrentNotesAppSettings.IsAdvancedLogEnabled;

                var takesNotesOnHero = noteService.CurrentNotesAppSettings.TakesNotesOnHero;

                using (var session = ModelEntities.OpenStatelessSession())
                {
                    BuildPlayersDictonary(session);
                    BuildPlayersNotesDictonary(session);

                    var entitiesCount = sinceDate != null?
                                        session.Query <Handhistory>().Count(x => x.Handtimestamp >= sinceDate.Value) :
                                            session.Query <Handhistory>().Count();

                    var progressCounter = 0;
                    var progress        = 0;

                    var numOfQueries = (int)Math.Ceiling((double)entitiesCount / handHistoryRowsPerQuery);

                    LogProvider.Log.Info(CustomModulesNames.PlayerXRay, $"Processing notes [{notes.Count()}] for {entitiesCount} hands.");

                    for (var i = 0; i < numOfQueries; i++)
                    {
                        if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
                        {
                            LogProvider.Log.Info(CustomModulesNames.PlayerXRay, $"The note processing has been canceled [{i}/{numOfQueries}].");
                            break;
                        }

                        using (var pf = new PerformanceMonitor($"Proccesing notes [{i}/{numOfQueries} iteration].", isAdvancedLogEnabled, CustomModulesNames.PlayerXRay))
                        {
                            var numOfRowToStartQuery = i * handHistoryRowsPerQuery;

                            var handHistories = sinceDate != null?
                                                session.Query <Handhistory>()
                                                .Where(x => x.Handtimestamp >= sinceDate.Value)
                                                .Skip(numOfRowToStartQuery)
                                                .Take(handHistoryRowsPerQuery)
                                                .ToArray() :
                                                    session.Query <Handhistory>()
                                                    .Skip(numOfRowToStartQuery)
                                                    .Take(handHistoryRowsPerQuery)
                                                    .ToArray();

                            var notesToInsert = new ConcurrentBag <Playernotes>();

                            Parallel.ForEach(handHistories, handHistory =>
                            {
                                try
                                {
                                    var parsingResult = ParseHandHistory(handHistory);

                                    if (parsingResult != null)
                                    {
                                        var matchInfo = new GameMatchInfo
                                        {
                                            GameType  = parsingResult.Source.GameDescription.GameType,
                                            CashBuyIn = !parsingResult.Source.GameDescription.IsTournament ?
                                                        Utils.ConvertToCents(parsingResult.Source.GameDescription.Limit.BigBlind) : 0,
                                            TournamentBuyIn = parsingResult.Source.GameDescription.IsTournament ?
                                                              parsingResult.Source.GameDescription.Tournament.BuyIn.PrizePoolValue : 0
                                        };

                                        if (!Limit.IsMatch(matchInfo))
                                        {
                                            return;
                                        }

                                        var playerStatisticCreationInfo = new PlayerStatisticCreationInfo
                                        {
                                            ParsingResult = parsingResult
                                        };

                                        foreach (var player in parsingResult.Players)
                                        {
                                            // skip notes for current player (need to check setting)
                                            if (!takesNotesOnHero && currentPlayerIds.Contains(player.PlayerId))
                                            {
                                                continue;
                                            }

                                            var calculatedEquity = new Dictionary <string, Dictionary <Street, decimal> >();

                                            if (player.PlayerId != 0)
                                            {
                                                var playerNoteKey = new PlayerPokerSiteKey(player.PlayerId, player.PokersiteId);

                                                playerStatisticCreationInfo.Player = player;

                                                var playerStatistic = BuildPlayerStatistic(playerStatisticCreationInfo);

                                                var playerNotes = ProcessHand(notes, playerStatistic, parsingResult.Source);

                                                if (playerNotes.Count() == 0)
                                                {
                                                    continue;
                                                }

                                                // if player has no notes, then just save all new notes
                                                if (!playersNotesDictionary.ContainsKey(playerNoteKey) ||
                                                    (playersNotesDictionary.ContainsKey(playerNoteKey) &&
                                                     !playersNotesDictionary[playerNoteKey].ContainsKey(handHistory.Gamenumber)))
                                                {
                                                    playerNotes.ForEach(note => notesToInsert.Add(note));
                                                    continue;
                                                }

                                                var existingNotes = playersNotesDictionary[playerNoteKey][handHistory.Gamenumber];

                                                var notesToAdd = (from playerNote in playerNotes
                                                                  join existingNote in existingNotes on playerNote.Note equals existingNote.Note into gj
                                                                  from note in gj.DefaultIfEmpty()
                                                                  where note == null
                                                                  select playerNote).ToArray();

                                                notesToAdd.ForEach(note => notesToInsert.Add(note));
                                            }
                                        }
                                        ;
                                    }
                                }
                                catch (Exception hhEx)
                                {
                                    LogProvider.Log.Error(CustomModulesNames.PlayerXRay, $"Hand history {handHistory.Gamenumber} has not been processed", hhEx);
                                }

                                // reporting progress
                                progressCounter++;

                                var currentProgress = progressCounter * 100 / entitiesCount;

                                if (progress < currentProgress)
                                {
                                    progress = currentProgress;
                                    ProgressChanged?.Invoke(this, new NoteProcessingServiceProgressChangedEventArgs(progress));
                                }
                            });

                            using (var transaction = session.BeginTransaction())
                            {
                                notesToInsert.ForEach(x => session.Insert(x));
                                transaction.Commit();
                            }
                        }
                    }

                    LogProvider.Log.Info(CustomModulesNames.PlayerXRay, $"Notes have been processed.");
                }
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Notes have not been processed.", e);
            }
        }