Esempio n. 1
0
        public void TestLightIndicatorProtobufSerialization(string file)
        {
            var playerStatistic = DataServiceHelper.GetPlayerStatisticFromFile(file);
            var lightIndicators = new LightIndicators(playerStatistic);

            Assert.DoesNotThrow(() =>
            {
                using (var ms = new MemoryStream())
                {
                    Serializer.Serialize(ms, lightIndicators);
                }
            }, "LightIndicator must be serializable");
        }
Esempio n. 2
0
        public void TestLightIndicators(string file)
        {
            var playerStatistic = DataServiceHelper.GetPlayerStatisticFromFile(file);

            var indicators      = new TestIndicators(playerStatistic);
            var lightIndicators = new LightIndicators(playerStatistic);

            Assert.Multiple(() =>
            {
                Assert.That(lightIndicators.BB, Is.EqualTo(indicators.BB), nameof(HudLightIndicators.BB));
                Assert.That(lightIndicators.EVBB, Is.EqualTo(indicators.EVBB), nameof(HudLightIndicators.EVBB));
                Assert.That(lightIndicators.SessionStart, Is.EqualTo(indicators.SessionStart), nameof(HudLightIndicators.SessionStart));
                Assert.That(lightIndicators.SessionLength, Is.EqualTo(indicators.SessionLength), nameof(HudLightIndicators.SessionLength));
                Assert.That(lightIndicators.UO_PFR_EP, Is.EqualTo(indicators.UO_PFR_EP), nameof(HudLightIndicators.UO_PFR_EP));
                Assert.That(lightIndicators.UO_PFR_MP, Is.EqualTo(indicators.UO_PFR_MP), nameof(HudLightIndicators.UO_PFR_MP));
                Assert.That(lightIndicators.UO_PFR_CO, Is.EqualTo(indicators.UO_PFR_CO), nameof(HudLightIndicators.UO_PFR_CO));
                Assert.That(lightIndicators.UO_PFR_BN, Is.EqualTo(indicators.UO_PFR_BN), nameof(HudLightIndicators.UO_PFR_BN));
                Assert.That(lightIndicators.UO_PFR_SB, Is.EqualTo(indicators.UO_PFR_SB), nameof(HudLightIndicators.UO_PFR_SB));
                Assert.That(lightIndicators.UO_PFR_BB, Is.EqualTo(indicators.UO_PFR_BB), nameof(HudLightIndicators.UO_PFR_BB));
                Assert.That(lightIndicators.ThreeBet_BB, Is.EqualTo(indicators.ThreeBet_BB), nameof(HudLightIndicators.ThreeBet_BB));
                Assert.That(lightIndicators.ThreeBet_SB, Is.EqualTo(indicators.ThreeBet_SB), nameof(HudLightIndicators.ThreeBet_SB));
                Assert.That(lightIndicators.ThreeBet_EP, Is.EqualTo(indicators.ThreeBet_EP), nameof(HudLightIndicators.ThreeBet_EP));
                Assert.That(lightIndicators.ThreeBet_MP, Is.EqualTo(indicators.ThreeBet_MP), nameof(HudLightIndicators.ThreeBet_MP));
                Assert.That(lightIndicators.ThreeBet_CO, Is.EqualTo(indicators.ThreeBet_CO), nameof(HudLightIndicators.ThreeBet_CO));
                Assert.That(lightIndicators.ThreeBet_BN, Is.EqualTo(indicators.ThreeBet_BN), nameof(HudLightIndicators.ThreeBet_BN));
                Assert.That(lightIndicators.FoldToThreeBet, Is.EqualTo(indicators.FoldToThreeBet), nameof(HudLightIndicators.FoldToThreeBet));
                Assert.That(lightIndicators.FourBet, Is.EqualTo(indicators.FourBet), nameof(HudLightIndicators.FourBet));
                Assert.That(lightIndicators.FourBetInBB, Is.EqualTo(indicators.FourBetInBB), nameof(HudLightIndicators.FourBetInBB));
                Assert.That(lightIndicators.FourBetInSB, Is.EqualTo(indicators.FourBetInSB), nameof(HudLightIndicators.FourBetInSB));
                Assert.That(lightIndicators.FourBetInEP, Is.EqualTo(indicators.FourBetInEP), nameof(HudLightIndicators.FourBetInEP));
                Assert.That(lightIndicators.FourBetInMP, Is.EqualTo(indicators.FourBetInMP), nameof(HudLightIndicators.FourBetInMP));
                Assert.That(lightIndicators.FourBetInCO, Is.EqualTo(indicators.FourBetInCO), nameof(HudLightIndicators.FourBetInCO));
                Assert.That(lightIndicators.FourBetInBTN, Is.EqualTo(indicators.FourBetInBTN), nameof(HudLightIndicators.FourBetInBTN));
                Assert.That(lightIndicators.VPIP_BB, Is.EqualTo(indicators.VPIP_BB), nameof(HudLightIndicators.VPIP_BB));
                Assert.That(lightIndicators.VPIP_SB, Is.EqualTo(indicators.VPIP_SB), nameof(HudLightIndicators.VPIP_SB));
                Assert.That(lightIndicators.VPIP_EP, Is.EqualTo(indicators.VPIP_EP), nameof(HudLightIndicators.VPIP_EP));
                Assert.That(lightIndicators.VPIP_MP, Is.EqualTo(indicators.VPIP_MP), nameof(HudLightIndicators.VPIP_MP));
                Assert.That(lightIndicators.VPIP_CO, Is.EqualTo(indicators.VPIP_CO), nameof(HudLightIndicators.VPIP_CO));
                Assert.That(lightIndicators.VPIP_BN, Is.EqualTo(indicators.VPIP_BN), nameof(HudLightIndicators.VPIP_BN));
                Assert.That(lightIndicators.ColdCall_BB, Is.EqualTo(indicators.ColdCall_BB), nameof(HudLightIndicators.ColdCall_BB));
                Assert.That(lightIndicators.ColdCall_SB, Is.EqualTo(indicators.ColdCall_SB), nameof(HudLightIndicators.ColdCall_SB));
                Assert.That(lightIndicators.ColdCall_EP, Is.EqualTo(indicators.ColdCall_EP), nameof(HudLightIndicators.ColdCall_EP));
                Assert.That(lightIndicators.ColdCall_MP, Is.EqualTo(indicators.ColdCall_MP), nameof(HudLightIndicators.ColdCall_MP));
                Assert.That(lightIndicators.ColdCall_CO, Is.EqualTo(indicators.ColdCall_CO), nameof(HudLightIndicators.ColdCall_CO));
                Assert.That(lightIndicators.ColdCall_BN, Is.EqualTo(indicators.ColdCall_BN), nameof(HudLightIndicators.ColdCall_BN));

                Assert.That(lightIndicators.HourOfHand, Is.EqualTo(indicators.HourOfHand), nameof(HudLightIndicators.HourOfHand));
            });
        }
        /// <summary>
        /// Builds report data
        /// </summary>
        private void BuildReportData(CancellationToken cancellationToken)
        {
            LogProvider.Log.Info("Building population report.");

            lock (syncLock)
            {
                try
                {
                    var tableType = GetTableType();

                    var playerTypes = hudPlayerTypeService.CreateDefaultPlayerTypes(tableType);

                    var players = dataService.GetPlayersList();

                    var populationIndicators = playerTypes.Select(x => new PopulationReportIndicators
                    {
                        PlayerTypeName = x.Name,
                        PlayerType     = x
                    }).ToDictionary(x => x.PlayerTypeName);

                    var allPlayersType = CreateAllPlayersType();

                    var allPlayersIndicator = new PopulationReportIndicators
                    {
                        PlayerTypeName = allPlayersType.Name,
                        PlayerType     = allPlayersType,
                        CanAddHands    = true
                    };

                    var filterPredicate = storageModel.CashFilterPredicate.Compile();
                    var heroId          = storageModel.PlayerSelectedItem?.PlayerId ?? 0;

                    Parallel.ForEach(players, (player, loopState) =>
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            loopState.Break();
                        }

                        if (player.PlayerId == heroId)
                        {
                            return;
                        }

                        var playerIndicators = new LightIndicators();

                        playerStatisticRepository.GetPlayerStatistic(player.PlayerId)
                        .Where(x => !x.IsTourney && FilterStatistic(x) && filterPredicate(x))
                        .ForEach(x =>
                        {
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            playerIndicators.AddStatistic(x);

                            if (filterPredicate(x))
                            {
                                lock (allPlayersIndicator)
                                {
                                    allPlayersIndicator.AddStatistic(x);
                                }
                            }
                        }
                                 );

                        var playerType = hudPlayerTypeService.Match(playerIndicators, playerTypes, true);

                        if (playerType != null)
                        {
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            playerStatisticRepository.GetPlayerStatistic(player.PlayerId)
                            .Where(x => !x.IsTourney && FilterStatistic(x) && filterPredicate(x))
                            .ForEach(x =>
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                lock (populationIndicators[playerType.Name])
                                {
                                    populationIndicators[playerType.Name].AddStatistic(x);
                                }
                            }
                                     );
                        }
                    });

                    populationIndicators.Add(allPlayersIndicator.PlayerTypeName, allPlayersIndicator);

                    populationIndicators.Values.ForEach(x => x.PrepareHands());

                    populationData.Report = populationIndicators.Values.ToList();

                    if (cancellationToken.IsCancellationRequested)
                    {
                        LogProvider.Log.Info("Population report has been cancelled.");
                        populationData.Report = new List <PopulationReportIndicators>();
                        return;
                    }

                    SaveCachedData();

                    LogProvider.Log.Info("Population report has been built.");
                }
                catch (Exception e)
                {
                    LogProvider.Log.Error(this, "Could build population report data.", e);
                }
            }
        }