private void StorePlayerStatistic(Playerstatistic statistic) { try { var serializedStatistic = string.Empty; using (var ms = new MemoryStream()) { Serializer.Serialize(ms, statistic); serializedStatistic = Convert.ToBase64String(ms.ToArray()).Trim(); } var streamWriter = GetOrCreatePlayestatisticStreamWriter(statistic); lock (streamWriter) { streamWriter.WriteLine(serializedStatistic); } } catch { LogProvider.Log.Error(this, "Could not store statistic."); throw; } }
public void TestTiltMeterValueIsIncreasedWhenFivePFRInRow(bool usePlusOperator) { var playerstatistic1 = new Playerstatistic(); for (var i = 0; i < 5; i++) { var playerstatistic2 = new Playerstatistic { Pfrhands = 1 }; if (usePlusOperator) { playerstatistic1 += playerstatistic2; } else { playerstatistic1.Add(playerstatistic2); } } var tiltMeter = playerstatistic1.TiltMeterTemporaryHistory.Last(); Assert.That(tiltMeter, Is.EqualTo(2)); }
private EnumMRatio GetMRatio(Playerstatistic stat) { var mRatioValue = PlayerStatisticCalculator.CalculateMRatio(stat); EnumMRatio mRatio; if (mRatioValue <= 5) { mRatio = EnumMRatio.RedZone; } else if (mRatioValue < 10) { mRatio = EnumMRatio.OrangeZone; } else if (mRatioValue < 20) { mRatio = EnumMRatio.YellowZone; } else if (mRatioValue < 40) { mRatio = EnumMRatio.GreenZone; } else if (mRatioValue < 60) { mRatio = EnumMRatio.BlueZone; } else { mRatio = EnumMRatio.PurpleZone; } return(mRatio); }
public override void AddStatistic(Playerstatistic statistic) { base.AddStatistic(statistic); foreach (var stat in heatMaps.Keys) { if (stat.CreateStatDto == null) { continue; } var statDto = stat.CreateStatDto(statistic); var cardsRange = ParserUtils.ConvertToCardRange(statistic.Cards); if (string.IsNullOrEmpty(cardsRange)) { continue; } if (!heatMaps[stat].OccuredByCardRange.ContainsKey(cardsRange)) { heatMaps[stat].OccuredByCardRange.Add(cardsRange, 0); } heatMaps[stat].OccuredByCardRange[cardsRange] += statDto.Occurred; } }
protected virtual void AssertThatIndicatorIsCalculated(Expression <Func <HudLightIndicators, StatDto> > expression, string fileName, EnumPokerSites pokerSite, string playerName, decimal expected, int occurredExpected, int couldOccurredExpected, [CallerMemberName] string method = "UnknownMethod") { using (var perfScope = new PerformanceMonitor(method)) { var indicator = new HudLightIndicators(); Playerstatistic playerstatistic = null; var playerStatisticRepository = ServiceLocator.Current.GetInstance <IPlayerStatisticRepository>(); playerStatisticRepository.Store(Arg.Is <Playerstatistic>(x => GetSinglePlayerstatisticFromStoreCall(ref playerstatistic, x, playerName))); FillDatabaseFromSingleFile(fileName, pokerSite); Assert.IsNotNull(playerstatistic, $"Player '{playerName}' has not been found"); indicator.AddStatistic(playerstatistic); var getStat = expression.Compile(); var actualStatDto = getStat(indicator); var expectedStatDto = new StatDto { Value = expected, Occurred = occurredExpected, CouldOccurred = couldOccurredExpected }; AssertionUtils.AssertStatDto(actualStatDto, expectedStatDto); } }
protected override void AddReportHand(Playerstatistic statistic) { if (!CanAddHands) { return; } if (processedHands.Contains(statistic.GameNumber)) { return; } processedHands.Add(statistic.GameNumber); if (reportHands.Count >= handsToStore) { reportHands.Remove(reportHands.Keys.First()); } var reportHandKey = new ReportHandKey { GameNumber = statistic.GameNumber, Time = statistic.Time }; reportHands.Add(reportHandKey, new ReportHandViewModel(statistic)); }
public override void AddStatistic(Playerstatistic statistic) { Source += statistic; var unopened = statistic.IsUnopened ? 1 : 0; positionUnoppened?.Add(statistic.Position, unopened); if (gameNumberMax < statistic.GameNumber) { gameNumberMax = statistic.GameNumber; } statisticCount++; netWon += statistic.NetWon; bigBlind += statistic.BigBlind; netWonByBigBlind += GetDivisionResult(statistic.NetWon, statistic.BigBlind); evInBB += GetDivisionResult(statistic.NetWon + statistic.EVDiff, statistic.BigBlind); if (sessionStartTime > statistic.Time) { sessionStartTime = statistic.Time; } if (sessionEndTime < statistic.Time) { sessionEndTime = statistic.Time; } didDoubleBarrel += statistic.DidDoubleBarrel; couldDoubleBarrel += statistic.CouldDoubleBarrel; faced3Bet += statistic.FacedthreebetpreflopVirtual; foldedTo3Bet += statistic.FoldedtothreebetpreflopVirtual; }
public virtual void Process(Playerstatistic statistic) { if (statistic == null || statistic.IsTourney || string.IsNullOrEmpty(statistic.Cards)) { return; } if (dataPoints == null) { dataPoints = new Dictionary <string, GraphSerieDataPoint>(); } var cardsRange = ParserUtils.ConvertToCardRange(statistic.Cards); if (string.IsNullOrEmpty(cardsRange)) { return; } if (!dataPoints.ContainsKey(cardsRange)) { dataPoints.Add(cardsRange, new GraphSerieDataPoint()); } dataPoints[cardsRange].Value += statistic.NetWon; }
public void PlayerstatisticPositionFieldCanBeSerializedAndDeserialized(EnumPosition position) { var playerStatistic = new Playerstatistic { FirstRaiserPosition = position, ThreeBettorPosition = position, FourBettorPosition = position, }; byte[] bytes = null; using (var memoryStream = new MemoryStream()) { Serializer.Serialize(memoryStream, playerStatistic); bytes = memoryStream.ToArray(); } var actualStat = SerializationHelper.Deserialize <Playerstatistic>(bytes); Assert.Multiple(() => { Assert.That(actualStat.ThreeBettorPosition, Is.EqualTo(playerStatistic.ThreeBettorPosition)); Assert.That(actualStat.FirstRaiserPosition, Is.EqualTo(playerStatistic.FirstRaiserPosition)); Assert.That(actualStat.FourBettorPosition, Is.EqualTo(playerStatistic.FourBettorPosition)); }); }
private bool TryParsePlayerStatistic(string line, string file, out Playerstatistic stat) { stat = null; try { if (string.IsNullOrWhiteSpace(line)) { LogProvider.Log.Warn(this, $"Empty line in {file}"); return(false); } /* replace '-' and '_' characters in order to convert back from Modified Base64 (https://en.wikipedia.org/wiki/Base64#Implementations_and_history) */ byte[] byteAfter64 = Convert.FromBase64String(line.Replace('-', '+').Replace('_', '/').Trim()); using (var ms = new MemoryStream(byteAfter64)) { stat = Serializer.Deserialize <Playerstatistic>(ms); return(true); } } catch (Exception ex) { LogProvider.Log.Error($@"Could not process the file: {file}{Environment.NewLine}Error at line: {line}{Environment.NewLine}", ex); } return(false); }
public bool Apply(Playerstatistic playerstatistic) { var result = (DataFreshness == 0 || (DateTime.Now - playerstatistic.Time).Days <= DataFreshness) && (TableTypes == null || !TableTypes.Any() || TableTypes.Contains(playerstatistic.MaxPlayers)); return(result); }
public void TestTiltMeterValueIsIncreasedWhenPotWasBetween50and100BBPlayerLost(bool usePlusOperator) { var playerstatistic1 = new Playerstatistic(); var playerstatistic2 = new Playerstatistic { Pot = 1000, BigBlind = 20, PlayerFolded = true, Wonhand = 0 }; if (usePlusOperator) { playerstatistic1 += playerstatistic2; } else { playerstatistic1.Add(playerstatistic2); } var tiltMeter = playerstatistic1.TiltMeterTemporaryHistory.Dequeue(); Assert.That(tiltMeter, Is.EqualTo(1)); }
public override void AddStatistic(Playerstatistic statistic) { Source += statistic; statisticCount++; netWon += statistic.NetWon; netWonByBigBlind += GetDivisionResult(statistic.NetWon, statistic.BigBlind); }
public virtual IEnumerable <Playerstatistic> GetPlayerStatisticFromFiles(IEnumerable <string> files) { if (files == null) { throw new ArgumentNullException(nameof(files)); } foreach (var file in files) { var rwLock = GetLock(file); rwLock.EnterUpgradeableReadLock(); try { RestoreBackupFile(file, rwLock); using (var sr = new StreamReaderWrapper(file)) { string line = null; while (sr != null && ((line = sr.ReadLine()) != null)) { Playerstatistic stat = null; try { if (string.IsNullOrWhiteSpace(line)) { LogProvider.Log.Warn(this, $"Empty line in {file}"); } /* replace '-' and '_' characters in order to convert back from Modified Base64 (https://en.wikipedia.org/wiki/Base64#Implementations_and_history) */ byte[] byteAfter64 = Convert.FromBase64String(line.Replace('-', '+').Replace('_', '/').Trim()); using (var ms = new MemoryStream(byteAfter64)) { stat = Serializer.Deserialize <Playerstatistic>(ms); } } catch (Exception ex) { LogProvider.Log.Error($@"Could not process the file: {file}{Environment.NewLine}Error at line: {line}{Environment.NewLine}", ex); } if (stat != null) { yield return(stat); } } } } finally { rwLock.ExitUpgradeableReadLock(); } } }
/// <summary> /// Gets player statistic from the <see cref="IDataService.Store(Playerstatistic)"/> call for the specified player /// </summary> protected virtual bool GetSinglePlayerstatisticFromStoreCall(ref Playerstatistic playerstatistic, Playerstatistic p, string playerName) { if (p.PlayerName.Equals(playerName)) { playerstatistic = p; } return(true); }
public virtual void DeletePlayerStatisticFromFile(Playerstatistic statistic) { var files = GetPlayerFiles(statistic.PlayerId); if (files == null || !files.Any()) { return; } string convertedStatistic = string.Empty; using (var msTestString = new MemoryStream()) { Serializer.Serialize(msTestString, statistic); convertedStatistic = Convert.ToBase64String(msTestString.ToArray()); } try { foreach (var file in files) { var rwLock = GetLock(file); try { string[] allLines = null; allLines = File.ReadAllLines(file); if (allLines.Any(x => x.Equals(convertedStatistic, StringComparison.Ordinal))) { var newLines = new List <string>(allLines.Count()); foreach (var line in allLines) { if (!line.Equals(convertedStatistic, StringComparison.Ordinal)) { newLines.Add(line); } } File.WriteAllLines(file, newLines); return; } } finally { rwLock.ExitWriteLock(); } } } catch (Exception e) { LogProvider.Log.Error(this, $"Failed to delete playerstatistic for {statistic.PlayerId} {statistic.PlayerName} {statistic.Time}", e); } }
public override void AddStatistic(Playerstatistic statistic) { AddStatValue(ref vpiphands, statistic.Vpiphands); AddStatValue(ref pfrhands, statistic.Pfrhands); AddStatValue(ref numberOfWalks, statistic.NumberOfWalks); AddStatValue(ref totalHands, statistic.Totalhands); AddStatValue(ref didThreeBet, statistic.Didthreebet); AddStatValue(ref couldThreeBet, statistic.Couldthreebet); AddStatValue(ref totalbets, statistic.Totalbets); AddStatValue(ref totalpostflopstreetsplayed, statistic.Totalpostflopstreetsplayed); }
public static string ToAllin(HandHistory hand, Playerstatistic stat) { var wasAllinAction = hand.HandActions.FirstOrDefault(x => x.IsAllIn || x.IsAllInAction); if (wasAllinAction == null) { return(string.Empty); } return(wasAllinAction.Street.ToString()); }
public override void ProcessStatistic(Playerstatistic playerstatistic) { double totalWinning = 0; double netWon = 0; do { netWon = this.netWon; totalWinning = netWon + (double)playerstatistic.NetWon; }while (netWon != Interlocked.CompareExchange(ref this.netWon, totalWinning, netWon)); }
private StreamWriter GetOrCreatePlayestatisticStreamWriter(Playerstatistic statistic) { var playerDirectory = Path.Combine(playerStatisticTempDataFolder, statistic.PlayerId.ToString()); var fileName = Path.Combine(playerDirectory, statistic.Playedyearandmonth.ToString()) + ".stat"; var playestatisticStreamWriter = playerStatisticStreamWriters.GetOrAdd(fileName, key => new Lazy <StreamWriter>(() => CreatePlayerstatisticStreamWriter(playerDirectory, key))); return(playestatisticStreamWriter.Value); }
public IEnumerable <Playernotes> ProcessHand(IEnumerable <NoteObject> notes, Playerstatistic stats, HandHistory handHistory) { if (!licenseService.IsRegistered) { return(null); } var matchInfo = new GameMatchInfo { GameType = handHistory.GameDescription.GameType, CashBuyIn = !handHistory.GameDescription.IsTournament ? Utils.ConvertToCents(handHistory.GameDescription.Limit.BigBlind) : 0, TournamentBuyIn = handHistory.GameDescription.IsTournament ? handHistory.GameDescription.Tournament.BuyIn.PrizePoolValue : 0 }; if (!Limit.IsMatch(matchInfo)) { return(null); } var playernotes = new List <Playernotes>(); foreach (var note in notes) { var playerstatistic = new PlayerstatisticExtended { Playerstatistic = stats, HandHistory = handHistory }; if (NoteManager.IsMatch(note, playerstatistic)) { var playerCardsText = string.IsNullOrEmpty(playerstatistic.Playerstatistic.Cards) ? string.Empty : $"[{playerstatistic.Playerstatistic.Cards}]"; var playerNote = new Playernotes { PlayerId = stats.PlayerId, PokersiteId = (short)stats.PokersiteId, Note = $"=[{note.ParentStageType}]= {note.DisplayedNote}", CardRange = note.Settings.IncludeBoard && !string.IsNullOrEmpty(playerCardsText) && !string.IsNullOrEmpty(playerstatistic.Playerstatistic.Board) ? $"{playerCardsText}({playerstatistic.Playerstatistic.Board})" : playerCardsText, IsAutoNote = true, GameNumber = handHistory.HandId, Timestamp = handHistory.DateOfHandUtc }; playernotes.Add(playerNote); } } return(playernotes); }
public ReplayerDataModel(Playerstatistic statistic) { this.Statistic = statistic; this.GameNumber = statistic.GameNumber; this.GameType = statistic.GameType; this.Time = statistic.Time; this.Cards = statistic.Cards; this.Pot = statistic.Pot; this.NetWon = statistic.NetWon; this.PokersiteId = (short)statistic.PokersiteId; }
public void Process(Playerstatistic statistic) { if (providers == null) { return; } foreach (var provider in providers.Values) { provider.Process(statistic); } }
private void InitSessionStatCollections(HudLightIndicators playerData, Playerstatistic stats) { if (playerData.StatsSessionCollection == null) { playerData.StatsSessionCollection = new Dictionary <Stat, IList <decimal> >(); playerData.AddStatsToSession(stats); } if (playerData.RecentAggList == null) { playerData.RecentAggList = new Common.Utils.FixedSizeList <Tuple <int, int> >(10); playerData.RecentAggList.Add(new Tuple <int, int>(stats.Totalbets, stats.Totalpostflopstreetsplayed)); } }
public static string ToAction(Playerstatistic stat) { if (stat.Vpiphands > 0) { return("VPIP"); } if (stat.Pfrhands > 0) { return("PFR"); } return(string.Empty); }
/// <summary> /// Serializes <see cref="Playerstatistic"/>, then appends the serialized data to the specified file /// </summary> /// <param name="file">File to append serialized <see cref="Playerstatistic"/></param> /// <param name="statistic"><see cref="Playerstatistic"/> to store in the specified file</param> private void StorePlayerStatistic(StreamWriter streamWriter, Playerstatistic statistic) { var data = string.Empty; using (var memoryStream = new MemoryStream()) { Serializer.Serialize(memoryStream, statistic); data = Convert.ToBase64String(memoryStream.ToArray()).Trim(); } if (!string.IsNullOrEmpty(data)) { streamWriter.WriteLine(data); } }
protected override ChartItemDateKey BuildGroupKey(Playerstatistic statistic) { if (statistic == null) { return(null); } var time = Converter.ToLocalizedDateTime(statistic.Time); var groupKey = new ChartItemDateKey { Year = time.Year, }; return(groupKey); }
/// <summary> /// Update <see cref="Playerstatistic.MaxPlayers"/> in the specified <see cref="Playerstatistic"/>, then save it to the specified file /// </summary> /// <param name="file">File to save updated player statistic</param> /// <param name="stat"><see cref="Playerstatistic"/> to update</param> private void ProcessPlayerStatistic(StreamWriter streamWriter, Playerstatistic stat) { var handNumberPokerSiteKey = new HandNumberPokerSiteKey(stat.GameNumber, stat.PokersiteId); if (!handHistoryNumberTableSize.ContainsKey(handNumberPokerSiteKey)) { LogProvider.Log.Warn(this, $"Hand hasn't been found in db. It will be saved as is. Hand={stat.GameNumber}, PokerSite={(EnumPokerSites)stat.PokersiteId}"); return; } var tableSize = handHistoryNumberTableSize[handNumberPokerSiteKey]; stat.MaxPlayers = tableSize; StorePlayerStatistic(streamWriter, stat); }
public void PlayerStatisticIsCalculated(EnumPokerSites pokerSite, string playerName) { using (var perfScope = new PerformanceMonitor("PlayerStatisticIsCalculated")) { Playerstatistic playerstatistic = null; var playerStatisticRepository = ServiceLocator.Current.GetInstance <IPlayerStatisticRepository>(); playerStatisticRepository.Store(Arg.Is <Playerstatistic>(x => GetCombinedPlayerstatisticFromStoreCall(ref playerstatistic, x, playerName))); var testDataDirectory = new DirectoryInfo(TestDataFolder); Assert.True(testDataDirectory.Exists, $"Directory '{TestDataFolder}' has not been found"); foreach (var file in testDataDirectory.GetFiles()) { FillDatabaseFromSingleFile(file.Name, pokerSite); } Assert.IsNotNull(playerstatistic, $"Player '{playerName}' has not been found"); Assert.That(playerstatistic.LimpCalled, Is.EqualTo(3), nameof(playerstatistic.LimpCalled)); Assert.That(playerstatistic.LimpSb, Is.EqualTo(1), nameof(playerstatistic.LimpSb)); Assert.That(playerstatistic.LimpEp, Is.EqualTo(3), nameof(playerstatistic.LimpEp)); Assert.That(playerstatistic.LimpMp, Is.EqualTo(1), nameof(playerstatistic.LimpMp)); Assert.That(playerstatistic.LimpCo, Is.EqualTo(1), nameof(playerstatistic.LimpCo)); Assert.That(playerstatistic.LimpBtn, Is.EqualTo(0), nameof(playerstatistic.LimpBtn)); Assert.That(playerstatistic.LimpPossible, Is.EqualTo(11), nameof(playerstatistic.LimpPossible)); Assert.That(playerstatistic.DidColdCallInSb, Is.EqualTo(0), nameof(playerstatistic.DidColdCallInSb)); Assert.That(playerstatistic.DidColdCallInBb, Is.EqualTo(0), nameof(playerstatistic.DidColdCallInBb)); Assert.That(playerstatistic.DidColdCallInEp, Is.EqualTo(3), nameof(playerstatistic.DidColdCallInEp)); Assert.That(playerstatistic.DidColdCallInMp, Is.EqualTo(1), nameof(playerstatistic.DidColdCallInMp)); Assert.That(playerstatistic.DidColdCallInCo, Is.EqualTo(0), nameof(playerstatistic.DidColdCallInCo)); Assert.That(playerstatistic.DidColdCallInBtn, Is.EqualTo(1), nameof(playerstatistic.DidColdCallInBtn)); Assert.That(playerstatistic.Couldcoldcall, Is.EqualTo(13), nameof(playerstatistic.Couldcoldcall)); Assert.That(playerstatistic.DidColdCallThreeBet, Is.EqualTo(0), nameof(playerstatistic.DidColdCallThreeBet)); Assert.That(playerstatistic.DidColdCallFourBet, Is.EqualTo(0), nameof(playerstatistic.DidColdCallFourBet)); Assert.That(playerstatistic.DidColdCallVsOpenRaiseSb, Is.EqualTo(0), nameof(playerstatistic.DidColdCallVsOpenRaiseSb)); Assert.That(playerstatistic.DidColdCallVsOpenRaiseCo, Is.EqualTo(0), nameof(playerstatistic.DidColdCallVsOpenRaiseCo)); Assert.That(playerstatistic.DidColdCallVsOpenRaiseBtn, Is.EqualTo(0), nameof(playerstatistic.DidColdCallVsOpenRaiseBtn)); } }
public void Process(Playerstatistic statistic) { if (statistic == null || statistic.IsTourney) { return; } if (showDownDataPoints == null) { showDownDataPoints = new Dictionary <ChartItemDateKey, GraphSerieDataPoint>(); } if (nonShowDownDataPoints == null) { nonShowDownDataPoints = new Dictionary <ChartItemDateKey, GraphSerieDataPoint>(); } var groupKey = BuildGroupKey(statistic); if (!nonShowDownDataPoints.ContainsKey(groupKey)) { nonShowDownDataPoints.Add(groupKey, new GraphSerieDataPoint { Category = GetDateTimeFromGroupKey(groupKey) }); } if (!showDownDataPoints.ContainsKey(groupKey)) { showDownDataPoints.Add(groupKey, new GraphSerieDataPoint { Category = GetDateTimeFromGroupKey(groupKey) }); } if (statistic.Sawshowdown == 0) { nonShowDownDataPoints[groupKey].Value += statistic.NetWon; } else { showDownDataPoints[groupKey].Value += statistic.NetWon; } }