Exemplo n.º 1
0
        /// <summary>
        /// Store stickers-related statistics in cache
        /// </summary>
        /// <param name="session">Session</param>
        /// <param name="player">Player name</param>
        /// <param name="stickersStats">Dictionary of statistic accessed by sticker name</param>
        public void AddOrUpdatePlayerStickerStats(IEnumerable <PlayerStickersCacheData> playersStickersCacheData, string session)
        {
            if (!isStarted || playersStickersCacheData == null || !playersStickersCacheData.Any())
            {
                return;
            }

            cacheLock.EnterWriteLock();

            try
            {
                var sessionData = GetSessionData(session);

                if (sessionData == null)
                {
                    return;
                }

                var playersStickersCacheDataInfo = PreparePlayerStickersCacheDataInfo(playersStickersCacheData, sessionData);

                playersStickersCacheDataInfo.Where(x => !x.ReloadRequired).ForEach(x => AddStatToSticker(x.PlayerStickersCacheData.Statistic.Copy(),
                                                                                                         x.PlayerStickersCacheData, x.PlayerStickersDictionary));

                var tasksToReloadStickersData = new List <Task>();

                playersStickersCacheDataInfo.Where(x => x.ReloadRequired).ForEach(x =>
                {
                    var playerStickersCacheData = x.PlayerStickersCacheData;

                    var sessionHands = sessionData.StatisticByPlayer.ContainsKey(playerStickersCacheData.Player) ?
                                       sessionData.StatisticByPlayer[x.PlayerStickersCacheData.Player].SessionHands :
                                       new HashSet <long>();

                    var task = Task.Run(() =>
                                        playerStatisticRepository
                                        .GetPlayerStatistic(playerStickersCacheData.Player.PlayerId)
                                        .Where(stat => (stat.PokersiteId == (short)playerStickersCacheData.Player.PokerSite) &&
                                               stat.IsTourney == playerStickersCacheData.Statistic.IsTourney &&
                                               ((playerStickersCacheData.IsHero && sessionHands.Contains(stat.GameNumber)) || !playerStickersCacheData.IsHero) &&
                                               GameTypeUtils.CompareGameType((GameType)stat.PokergametypeId, (GameType)playerStickersCacheData.Statistic.PokergametypeId))
                                        .ForEach(stat =>
                    {
                        AddStatToSticker(stat, playerStickersCacheData, x.PlayerStickersDictionary);
                    })
                                        );

                    tasksToReloadStickersData.Add(task);
                });

                Task.WhenAll(tasksToReloadStickersData).Wait();
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Could not add stickers stat to cache.", e);
            }
            finally
            {
                cacheLock.ExitWriteLock();
            }
        }
        private void LoadIndicators(int seats, ReplayerViewModel viewModel, IEnumerable <Stat> heatMapStats)
        {
            var tasksToLoad = new List <Task>();

            var selectedPlayer = storageModel.PlayerSelectedItem;

            var players = viewModel.PlayersCollection.Select(x => x.Name).ToArray();

            for (var i = 0; i < seats; i++)
            {
                var player = players[i];

                if (playerIndicators.ContainsKey(player))
                {
                    continue;
                }

                var playerData = new HudIndicators(heatMapStats);

                // read data from statistic
                var taskToReadPlayerStats = Task.Run(() =>
                {
                    if (selectedPlayer != null &&
                        player == selectedPlayer.Name &&
                        (short?)selectedPlayer.PokerSite == viewModel.CurrentHand.PokersiteId)
                    {
                        storageModel
                        .GetStatisticCollection()
                        .Where(stat => (stat.PokersiteId == (short)viewModel.CurrentGame.GameDescription.Site) &&
                               stat.IsTourney == viewModel.CurrentGame.GameDescription.IsTournament &&
                               GameTypeUtils.CompareGameType((GameType)stat.PokergametypeId, viewModel.CurrentGame.GameDescription.GameType))
                        .ForEach(stat => playerData.AddStatistic(stat));

                        playerIndicators.AddOrUpdate(player, playerData, (key, old) => playerData);
                        return;
                    }

                    playerStatisticRepository
                    .GetPlayerStatistic(player, (short)viewModel.CurrentGame.GameDescription.Site)
                    .Where(stat => (stat.PokersiteId == (short)viewModel.CurrentGame.GameDescription.Site) &&
                           stat.IsTourney == viewModel.CurrentGame.GameDescription.IsTournament &&
                           GameTypeUtils.CompareGameType((GameType)stat.PokergametypeId, viewModel.CurrentGame.GameDescription.GameType))
                    .ForEach(stat => playerData.AddStatistic(stat));

                    playerIndicators.AddOrUpdate(player, playerData, (key, old) => playerData);
                });

                tasksToLoad.Add(taskToReadPlayerStats);
            }

            Task.WhenAll(tasksToLoad).Wait();
        }
Exemplo n.º 3
0
        private void InitContextMenu()
        {
            handsGridContextMenu       = new RadContextMenu();
            tournamentsGridContextMenu = new RadContextMenu();
            reportsGridContextMenu     = new RadContextMenu();

            /* Calculate equity item */
            RadMenuItem calculateEquityItem = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.CalculateEquityResourceString), false,
                                                                EquityCalcMenuItem_Click);

            Binding equityEnabledBinding = new Binding(nameof(ReportGadgetViewModel.IsEquityCalculatorEnabled))
            {
                Source = this.reportGadgetViewModel
            };

            calculateEquityItem.SetBinding(RadMenuItem.IsEnabledProperty, equityEnabledBinding);

            handsGridContextMenu.Opening += (s, e) =>
            {
                var item = handsGridContextMenu.GetClickedElement <GridViewRow>();

                if (item != null && item.DataContext != null &&
                    item.DataContext is ReportHandViewModel hand &&
                    (GameTypeUtils.CompareGameType((GameType)hand.PokerGameTypeId, GameType.NoLimitOmaha) ||
                     GameTypeUtils.CompareGameType((GameType)hand.PokerGameTypeId, GameType.NoLimitOmahaHiLo)))
                {
                    calculateEquityItem.Visibility = Visibility.Collapsed;
                    return;
                }

                calculateEquityItem.Visibility = Visibility.Visible;
            };

            /* Export items */
            RadMenuItem exportHandItem     = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ExportHandResourceString), false, null);
            RadMenuItem twoPlustTwoItem    = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.TwoPlustTwoResourceString), false, GeneralExportItem_Click, EnumExportType.TwoPlusTwo);
            RadMenuItem cardsChatItem      = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.CardsChatResourceString), false, GeneralExportItem_Click, EnumExportType.CardsChat);
            RadMenuItem pokerStrategyItem  = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.PokerStrategyString), false, GeneralExportItem_Click, EnumExportType.PokerStrategy);
            RadMenuItem icmizerHistoryItem = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ICMizerHandHistory), false,
                                                               RawExportItem_Click, extraAction: item =>
            {
                var binding = new Binding(nameof(ReportGadgetViewModel.IsShowTournamentData))
                {
                    Source    = reportGadgetViewModel,
                    Converter = new BoolToVisibilityConverter()
                };

                item.SetBinding(VisibilityProperty, binding);
            });

            RadMenuItem exportTo3rdPartyItem = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ExportGridHandsResourceString), false, null,
                                                                 command: nameof(ReportGadgetViewModel.ExportSelectedHandsTo3rdPartyCommand));

            RadMenuItem rawHistoryItem           = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.RawHandHistoryString), false, RawExportItem_Click);
            RadMenuItem plainTextHandHistoryItem = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.PlainTextHandHistoryString), false, PlainExportItem_Click);


            exportHandItem.Items.Add(twoPlustTwoItem);
            exportHandItem.Items.Add(cardsChatItem);
            exportHandItem.Items.Add(pokerStrategyItem);
            exportHandItem.Items.Add(icmizerHistoryItem);
            exportHandItem.Items.Add(rawHistoryItem);
            exportHandItem.Items.Add(plainTextHandHistoryItem);
            exportHandItem.Items.Add(exportTo3rdPartyItem);

            /* Replay hand */
            RadMenuItem replayHand = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ReplayHandResourceString), false, ReplayHand);
            /* Tag Hand */
            RadMenuItem tagHandItem   = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.TagHand), false, null);
            RadMenuItem forReviewItem = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.HandTagForReview), false, TagHand, EnumHandTag.ForReview);
            RadMenuItem bluffItem     = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.HandTagBluff), false, TagHand, EnumHandTag.Bluff);
            RadMenuItem heroCallitem  = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.HandTagHeroCall), false, TagHand, EnumHandTag.HeroCall);
            RadMenuItem bigFold       = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.HandTagBigFold), false, TagHand, EnumHandTag.BigFold);
            RadMenuItem removeTag     = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.HandTagNone), false, TagHand, EnumHandTag.None);

            tagHandItem.Items.Add(forReviewItem);
            tagHandItem.Items.Add(bluffItem);
            tagHandItem.Items.Add(heroCallitem);
            tagHandItem.Items.Add(bigFold);
            tagHandItem.Items.Add(removeTag);

            var makeNoteItem         = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.MakeNote), false, MakeNote);
            var editTournamentItem   = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.EditTournamentResourceString), false, EditTournament);
            var deleteHandItem       = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.DeleteHandResourceString), false, null, command: nameof(ReportGadgetViewModel.DeleteHandCommand));
            var deleteTournamentItem = CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.DeleteTournamentResourceString), false, DeleteTournament);

            handsGridContextMenu.Items.Add(calculateEquityItem);
            handsGridContextMenu.Items.Add(exportHandItem);
            handsGridContextMenu.Items.Add(replayHand);
            handsGridContextMenu.Items.Add(tagHandItem);
            handsGridContextMenu.Items.Add(makeNoteItem);
            handsGridContextMenu.Items.Add(deleteHandItem);

            tournamentsGridContextMenu.Items.Add(editTournamentItem);
            tournamentsGridContextMenu.Items.Add(deleteTournamentItem);
            tournamentsGridContextMenu.Items.Add(CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.RefreshReportResourceString), false, RefreshReport));
            tournamentsGridContextMenu.Items.Add(CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ExportToExcelReportResourceString), false, ExportReport));
            tournamentsGridContextMenu.Items.Add(CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ExportHandsResourceString), false, null,
                                                                   command: nameof(ReportGadgetViewModel.ExportSelectedReportsTo3rdPartyCommand)));

            reportsGridContextMenu.Items.Add(CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.RefreshReportResourceString), false, RefreshReport));
            reportsGridContextMenu.Items.Add(CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ExportToExcelReportResourceString), false, ExportReport));
            reportsGridContextMenu.Items.Add(CreateRadMenuItem(CommonResourceManager.Instance.GetResourceString(ResourceStrings.ExportHandsResourceString), false, null,
                                                               command: nameof(ReportGadgetViewModel.ExportSelectedReportsTo3rdPartyCommand)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets player session cache data using existing data or loading from DB
        /// </summary>
        /// <param name="cacheInfos"></param>
        /// <param name="sessionData"></param>
        /// <returns></returns>
        private Dictionary <PlayerStatsSessionCacheInfo, SessionCacheStatistic> GetSessionCacheStatistic(IEnumerable <PlayerStatsSessionCacheInfo> cacheInfos,
                                                                                                         SessionCacheData sessionData)
        {
            var playerSessionCacheStatistic = new Dictionary <PlayerStatsSessionCacheInfo, SessionCacheStatistic>();

            var playerSessionCacheStatisticTasks = new List <Task>();

            foreach (var cacheInfo in cacheInfos)
            {
                if (playerSessionCacheStatistic.ContainsKey(cacheInfo))
                {
                    continue;
                }

                SessionCacheStatistic sessionCacheStatistic = null;

                var isNewSessionCacheStatistic = true;

                // existing statistic
                if (sessionData.StatisticByPlayer.ContainsKey(cacheInfo.Player))
                {
                    sessionCacheStatistic      = sessionData.StatisticByPlayer[cacheInfo.Player];
                    isNewSessionCacheStatistic = false;
                }
                // hero starts empty session
                else if (cacheInfo.IsHero)
                {
                    sessionCacheStatistic = new SessionCacheStatistic
                    {
                        IsHero     = true,
                        GameFormat = cacheInfo.GameFormat
                    };

                    sessionCacheStatistic.PlayerData.InitializeHeatMaps(sessionData.HeatMapStats);
                }
                // try to check existing sessions for this player
                else
                {
                    var similarPlayerSession = cachedData.Values.FirstOrDefault(x => x.PokerSiteId == sessionData.PokerSiteId &&
                                                                                x.IsTourney == sessionData.IsTourney &&
                                                                                GameTypeUtils.CompareGameType((GameType)x.PokerGameTypeId, (GameType)sessionData.PokerGameTypeId) &&
                                                                                ((x.Filter == null && sessionData.Filter == null) || x.Filter.Equals(sessionData.Filter)) &&
                                                                                x.StatisticByPlayer.ContainsKey(cacheInfo.Player));

                    if (similarPlayerSession != null &&
                        similarPlayerSession.StatisticByPlayer[cacheInfo.Player].PlayerData.TotalHands >= TotalHandsToUseExistingSession)
                    {
                        sessionCacheStatistic = similarPlayerSession.StatisticByPlayer[cacheInfo.Player].Clone();
                    }
                }

                var needToReadStatistic = sessionCacheStatistic == null;

                if (needToReadStatistic)
                {
                    sessionCacheStatistic = new SessionCacheStatistic
                    {
                        GameFormat = cacheInfo.GameFormat
                    };
                }

                playerSessionCacheStatistic.Add(cacheInfo, sessionCacheStatistic);

                if (isNewSessionCacheStatistic)
                {
                    sessionData.StatisticByPlayer.Add(cacheInfo.Player, sessionCacheStatistic);
                }

                if (!needToReadStatistic)
                {
                    continue;
                }

                sessionCacheStatistic.PlayerData.InitializeHeatMaps(sessionData.HeatMapStats);

                // read data from statistic
                var taskToReadPlayerStats = Task.Run(() =>
                                                     playerStatisticRepository
                                                     .GetPlayerStatistic(cacheInfo.Player.PlayerId)
                                                     .Where(stat => (stat.PokersiteId == (short)cacheInfo.Player.PokerSite) &&
                                                            stat.IsTourney == cacheInfo.Stats.IsTourney &&
                                                            GameTypeUtils.CompareGameType((GameType)stat.PokergametypeId, (GameType)cacheInfo.Stats.PokergametypeId) &&
                                                            (sessionData.Filter == null || sessionData.Filter.Apply(stat)) &&
                                                            stat.GameNumber != cacheInfo.Stats.GameNumber)
                                                     .ForEach(stat => sessionCacheStatistic.PlayerData.AddStatistic(stat))
                                                     );

                playerSessionCacheStatisticTasks.Add(taskToReadPlayerStats);
            }

            Task.WhenAll(playerSessionCacheStatisticTasks).Wait();

            return(playerSessionCacheStatistic);
        }