Example #1
0
        /// <summary>
        /// Clones indicator without session data
        /// </summary>
        /// <returns></returns>
        public SessionCacheStatistic Clone()
        {
            var clonePlayerData = new HudIndicators();

            clonePlayerData.AddIndicator(PlayerData);

            // clone heat map
            foreach (var heatMapKeyValue in clonePlayerData.HeatMaps)
            {
                if (!PlayerData.HeatMaps.ContainsKey(heatMapKeyValue.Key))
                {
                    continue;
                }

                var heatMapDto = PlayerData.HeatMaps[heatMapKeyValue.Key];

                heatMapKeyValue.Value.OccuredByCardRange = new Dictionary <string, int>(heatMapDto.OccuredByCardRange);
            }

            var clone = new SessionCacheStatistic
            {
                IsHero     = IsHero,
                GameFormat = GameFormat,
                PlayerData = clonePlayerData
            };

            return(clone);
        }
Example #2
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);
        }