/// <summary> /// Parses summary hand /// </summary> /// <param name="handLines">Lines to parse</param> /// <param name="handHistory">Handhistory to update</param> /// <returns>Handhistory with summary data</returns> protected override HandHistory ParseSummaryHand(string[] handLines, HandHistory handHistory) { var tournament = new TournamentDescriptor { Summary = string.Join(Environment.NewLine, handLines) }; var gameType = GameType.Unknown; foreach (var handLine in handLines) { if (handLine.ContainsIgnoreCase("Tournament summary")) { var tournamentName = handLine.TakeBetween(" : ", "("); var tournamentId = handLine.TakeBetween("(", ")", true); if (string.IsNullOrEmpty(tournamentId)) { throw new TournamentIdException(handLine, "Couldn't parse tournament id"); } tournament.TournamentId = tournamentId; tournament.TournamentName = tournamentName; } else if (handLine.StartsWith("Player :", StringComparison.OrdinalIgnoreCase)) { var playerName = handLine.TakeBetween(" : ", string.Empty); handHistory.Hero = new Player(playerName, 0, 0); } else if (handLine.StartsWith("Buy-In :", StringComparison.OrdinalIgnoreCase)) { var prizePoolText = handLine.TakeBetween(": ", " +"); var entryFeeText = handLine.TakeBetween(" + ", string.Empty); if (!ParserUtils.TryParseMoney(prizePoolText, out decimal prizePoolValue)) { throw new BuyinException(handLines[0], "Could not parse buyin."); } if (!ParserUtils.TryParseMoney(entryFeeText, out decimal entryFee)) { throw new BuyinException(handLines[0], "Could not parse entry fee."); } tournament.BuyIn = Buyin.FromBuyinRake(prizePoolValue, entryFee, DefaultCurrency); } else if (handLine.StartsWith("Registered players :", StringComparison.OrdinalIgnoreCase)) { var totalPlayersText = handLine.TakeBetween(" : ", string.Empty); if (int.TryParse(totalPlayersText, out int totalPlayers)) { tournament.TotalPlayers = totalPlayers; } } else if (handLine.StartsWith("Speed : ", StringComparison.OrdinalIgnoreCase)) { var speedText = handLine.TakeBetween(": ", string.Empty); tournament.Speed = speedText.Equals("turbo", StringComparison.OrdinalIgnoreCase) ? TournamentSpeed.Turbo : TournamentSpeed.Regular; } else if (handLine.StartsWith("Levels :", StringComparison.OrdinalIgnoreCase)) { var levelLine = handLine.Replace('-', ' '); try { gameType = ParseGameType(new[] { levelLine }); } catch { // do nothing, type will be set in importer } } else if (handLine.StartsWith("Tournament started", StringComparison.OrdinalIgnoreCase)) { var dateText = handLine.TakeBetween("started ", string.Empty); try { tournament.StartDate = ParseDateFromText(dateText); } catch { // do nothing, date will be set in importer } } else if (handLine.StartsWith("You finished in", StringComparison.OrdinalIgnoreCase)) { var finishedPositionText = handLine .TakeBetween("finished in ", " place") .Replace("th", string.Empty) .Replace("st", string.Empty) .Replace("nd", string.Empty) .Replace("rd", string.Empty); if (int.TryParse(finishedPositionText, out int finishPosition)) { tournament.FinishPosition = finishPosition; } } else if (handLine.StartsWith("You won", StringComparison.OrdinalIgnoreCase)) { var wonText = handLine.TakeBetween("You won ", string.Empty); if (ParserUtils.TryParseMoney(wonText, out decimal won)) { tournament.Winning = won; } } else if (handLine.StartsWith("Your rebuys", StringComparison.OrdinalIgnoreCase)) { var rebuysText = handLine.TakeBetween(":", string.Empty); if (ParserUtils.TryParseMoney(rebuysText, out decimal rebuy)) { tournament.Rebuy = rebuy; } } else if (handLine.StartsWith("Your addons", StringComparison.OrdinalIgnoreCase)) { var addonsText = handLine.TakeBetween(":", string.Empty); if (ParserUtils.TryParseMoney(addonsText, out decimal addon)) { tournament.Addon = addon; } } } handHistory.GameDescription = new GameDescriptor(SiteName, gameType, null, TableType.FromTableTypeDescriptions(), SeatType.AllSeatType(), tournament); return(handHistory); }
protected override HandHistory ParseSummaryHand(string[] handLines, HandHistory handHistory) { var tournament = new TournamentDescriptor { Summary = string.Join(Environment.NewLine, handLines) }; foreach (var handLine in handLines) { // parse tournament id if (handLine.StartsWith("Tournament ID", StringComparison.InvariantCultureIgnoreCase)) { var indexOfColon = handLine.IndexOf(":"); tournament.TournamentId = handLine.Substring(indexOfColon + 1).Trim(); } else if (handLine.StartsWith("Buy-In", StringComparison.InvariantCultureIgnoreCase)) { var buyInText = ParseTournamentSummaryMoneyLine(handLine); var buyInSplit = buyInText.Split('+'); decimal buyIn = 0; decimal rake = 0; Currency currency = Currency.USD; if (ParserUtils.TryParseMoney(buyInSplit[0], out buyIn, out currency)) { if (buyInSplit.Length > 1) { ParserUtils.TryParseMoney(buyInSplit[1], out rake, out currency); } } tournament.BuyIn = Buyin.FromBuyinRake(buyIn, rake, currency); } else if (handLine.StartsWith("Rebuy", StringComparison.InvariantCultureIgnoreCase)) { var rebuyText = ParseTournamentSummaryMoneyLine(handLine); decimal rebuy = 0; Currency currency = Currency.USD; if (ParserUtils.TryParseMoney(rebuyText, out rebuy, out currency)) { tournament.Rebuy = rebuy; } } else if (handLine.StartsWith("Add-On", StringComparison.InvariantCultureIgnoreCase)) { var addonText = ParseTournamentSummaryMoneyLine(handLine); decimal addon = 0; Currency currency = Currency.USD; if (ParserUtils.TryParseMoney(addonText, out addon, out currency)) { tournament.Addon = addon; } } else if (handLine.Contains("finished")) { var match = SummaryFinishedRegex.Match(handLine); if (!match.Success) { LogProvider.Log.Error(string.Format("'{0}' wasn't parsed", handLine)); continue; } var playerName = match.Groups["player"].Value; var positionText = match.Groups["position"].Value; var totalPlayersText = match.Groups["total"].Value; var wonText = match.Groups["won"] != null ? match.Groups["won"].Value.Replace(",", ".").Trim() : string.Empty; handHistory.Hero = new Player(playerName, 0, 0); short position = 0; short totalPlayers = 0; decimal won = 0; Currency wonCurrency = Currency.USD; if (!short.TryParse(positionText, out position)) { LogProvider.Log.Error(string.Format("'{0}' position wasn't parsed", handLine)); continue; } if (!short.TryParse(totalPlayersText, out totalPlayers)) { LogProvider.Log.Error(string.Format("'{0}' total players weren't parsed", handLine)); continue; } if (!string.IsNullOrWhiteSpace(wonText) && !ParserUtils.TryParseMoney(wonText, out won, out wonCurrency)) { LogProvider.Log.Error(string.Format("'{0}' won data wasn't parsed", handLine)); continue; } tournament.FinishPosition = position; tournament.TotalPlayers = totalPlayers; tournament.Winning = won; } } handHistory.GameDescription = new GameDescriptor(EnumPokerSites.Poker888, GameType.Unknown, null, TableType.FromTableTypeDescriptions(), SeatType.AllSeatType(), tournament); return(handHistory); }