private void buttonParse_Click(object sender, EventArgs e) { if (listBoxSite.SelectedIndex == -1) { MessageBox.Show(this, "Please pick a site"); return; } IHandHistoryParserFactory factory = new HandHistoryParserFactoryImpl(); var handParser = factory.GetFullHandHistoryParser((SiteName)listBoxSite.SelectedItem); try { var hands = handParser.SplitUpMultipleHands(richTextBoxHandText.Text).ToList(); foreach (var hand in hands) { var parsedHand = handParser.ParseFullHandHistory(hand, true); } MessageBox.Show(this, "Parsed " + hands.Count + " hands."); } catch (Exception ex) { MessageBox.Show(this, ex.Message + "\r\n" + ex.StackTrace, "Error"); } }
private List <string> ParseHands(SiteName site, string handText, ref int parsedHands, ref int thrownOutHands) { List <string> messages = new List <string>(); // Each poker site has its own parser so we use a factory to get the right parser. IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. IHandHistoryParser handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser(site); try { List <string> hands = new List <string>(); hands = handHistoryParser.SplitUpMultipleHands(handText).ToList(); db.Configuration.AutoDetectChangesEnabled = false; foreach (string hand in hands) { try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. HandHistory handHistory = handHistoryParser.ParseFullHandHistory(hand, true); //handhistory can now be broken down to be put into the database // Add to player table Dictionary <string, player> playerDict = addPlayersToDB(handHistory); // Add to table table table dbTable = addTableToDB(handHistory); db.SaveChanges(); //Add to hand table hand dbHand = addHandToDB(handHistory, dbTable); // Add to hand_action table addHandActionToDB(handHistory, dbHand, playerDict); // Add to plays table addPlaysToDB(handHistory, playerDict); db.SaveChanges(); parsedHands++; } catch (Exception ex) { messages.Add("Parsing Error: " + ex.Message); thrownOutHands++; } } } catch (Exception ex) // Catch hand-parsing exceptions { messages.Add("Parsing Error: " + ex.Message); } db.Configuration.AutoDetectChangesEnabled = true; return(messages); }
public void ParsingDoesNotThrowExceptions(string culture) { var cultureInfo = new CultureInfo(culture); Thread.CurrentThread.CurrentCulture = cultureInfo; var testDataDirectoryInfo = new DirectoryInfo(TestDataFolder); var handHistoryFiles = testDataDirectoryInfo.GetFiles("*.txt", SearchOption.AllDirectories); var succeded = 0; var total = 0; foreach (var handHistoryFile in handHistoryFiles) { if (handHistoryFile.FullName.Contains("Tournaments") || handHistoryFile.FullName.Contains("WithInvalid")) { continue; } var handHistory = File.ReadAllText(handHistoryFile.FullName); var parserFactory = new HandHistoryParserFactoryImpl(); var parser = parserFactory.GetFullHandHistoryParser(handHistory); var hands = parser.SplitUpMultipleHands(handHistory).ToArray(); total += hands.Length; var hash = new HashSet <string>(); foreach (var hand in hands) { try { parser.ParseFullHandHistory(hand, true); succeded++; } catch (Exception e) { if (!hash.Contains(handHistoryFile.FullName)) { Debug.WriteLine(handHistoryFile.FullName); } Assert.Fail(e.ToString()); } } } Assert.AreEqual(total, succeded); Debug.WriteLine("Processed hands: {0}/{1}", succeded, total); }
public void GetFullHandHistoryParserReturnsExpectedParser(string fileName, EnumPokerSites expectedSite) { var file = Path.Combine(testFolder, fileName); if (!File.Exists(file)) { throw new Exception(string.Format("Test file '{0}' doesn't exist", file)); } var handText = File.ReadAllText(file); var handHistoryParserFactory = new HandHistoryParserFactoryImpl(); var parser = handHistoryParserFactory.GetFullHandHistoryParser(handText); Assert.That(parser.SiteName, Is.EqualTo(expectedSite)); }
private HandHistories.Objects.Hand.HandHistory ReadHandHistory(string file) { file = Path.Combine("UnitTests\\TestData\\EquitySolverData", file); FileAssert.Exists(file); var handHistoryText = File.ReadAllText(file); Assert.IsNotEmpty(handHistoryText); var parserFactory = new HandHistoryParserFactoryImpl(); var parser = parserFactory.GetFullHandHistoryParser(handHistoryText); var handHistory = parser.ParseFullHandHistory(handHistoryText); Assert.IsNotNull(handHistory); return(handHistory); }
private HandHistories.Objects.Hand.HandHistory ParseHand(string fileName) { fileName = Path.Combine(commonHandsFolder, fileName); if (parsedHandHistories.TryGetValue(fileName, out HandHistories.Objects.Hand.HandHistory hand)) { return(hand); } var handText = File.ReadAllText(fileName); var factory = new HandHistoryParserFactoryImpl(); var parser = factory.GetFullHandHistoryParser(handText); hand = parser.ParseFullHandHistory(handText); parsedHandHistories[fileName] = hand; return(hand); }
public void HandHistoryIsConvertedIntoForumFormatV2(string sourceFileName, string expectedResultFileName, EnumExportType exportType, EnumPokerSites site, TestIndicators[] testIndicators) { var pr = Process.GetProcesses(); var playerStatisticRepository = ServiceLocator.Current.GetInstance <IPlayerStatisticRepository>(); playerStatisticRepository .GetPlayersIndicators <ExportIndicators>(Arg.Any <string[]>(), Arg.Any <short?>()) .Returns(testIndicators?.ToDictionary(x => x.PlayerName, x => (ExportIndicators)x)); var sourceFile = Path.Combine(testFolder, sourceFileName); var expectedResultFile = Path.Combine(testFolder, expectedResultFileName); if (!File.Exists(sourceFile)) { throw new Exception(string.Format("Test file '{0}' doesn't exist", sourceFile)); } if (!File.Exists(expectedResultFile)) { throw new Exception(string.Format("Test file '{0}' doesn't exist", expectedResultFile)); } var handHistoryText = File.ReadAllText(sourceFile); var factory = new HandHistoryParserFactoryImpl(); var parser = factory.GetFullHandHistoryParser(site); var handHistory = parser.ParseFullHandHistory(handHistoryText); var actualHandHistoryForumText = ExportFunctions.ConvertHHToForumFormat(handHistory, exportType, true); actualHandHistoryForumText = ReplaceHeader(actualHandHistoryForumText); var expectedHandHistoryForumText = File.ReadAllText(expectedResultFile); Assert.That(actualHandHistoryForumText, Is.EqualTo(expectedHandHistoryForumText)); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. IHandHistoryParser handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser(HandHistories.Objects.GameDescription.SiteName.PokerStars); var handText = System.IO.File.ReadAllText("input.txt"); try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. HandHistory handHistory = handHistoryParser.ParseFullHandHistory(handText, true); } catch (Exception ex) // Catch hand-parsing exceptions { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. } }
private void buttonParse_Click(object sender, EventArgs e) { if (listBoxSite.SelectedIndex == -1) { MessageBox.Show(this, "Please pick a site"); return; } IHandHistoryParserFactory factory = new HandHistoryParserFactoryImpl(); var handParser = factory.GetFullHandHistoryParser((SiteName) listBoxSite.SelectedItem); try { string text = richTextBoxHandText.Text; int parsedHands = 0; Stopwatch SW = new Stopwatch(); SW.Start(); HandHistoryParserFastImpl fastParser = handParser as HandHistoryParserFastImpl; var hands = fastParser.SplitUpMultipleHandsToLines(text); foreach (var hand in hands) { var parsedHand = fastParser.ParseFullHandHistory(hand, true); parsedHands++; } SW.Stop(); MessageBox.Show(this, "Parsed " + parsedHands + " hands." + Math.Round(SW.Elapsed.TotalMilliseconds, 2) + "ms"); } catch (Exception ex) { MessageBox.Show(this, ex.Message + "\r\n" + ex.StackTrace, "Error"); } }
public HandHistory ParseHand(SiteName site, string handText, ref int parsedHands, ref int thrownOutHands) { // Each poker site has its own parser so we use a factory to get the right parser. IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. IHandHistoryParser handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser(site); try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. List <string> hands = new List <string>(); hands = handHistoryParser.SplitUpMultipleHands(handText).ToList(); foreach (string hand in hands) { try { HandHistory handHistory = handHistoryParser.ParseFullHandHistory(hand, true); Console.WriteLine(handHistory.HandId); parsedHands++; } catch (Exception ex) { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. thrownOutHands++; } } return(null); } catch (Exception ex) // Catch hand-parsing exceptions { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. return(null); } }
static void Main(string[] args) {// takes a full path to a directory that contains raw *.txt poker history files from 888 poker. IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. var handHistoryParser = new Poker888FastParserImpl(); HandHistoryParserFastImpl fastParser = handHistoryParser as HandHistoryParserFastImpl; try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. string[] files = Directory.GetFiles(args[0], "*.txt", SearchOption.AllDirectories); int fileCount = files.Length; foreach (string file in files) { Console.WriteLine("number of files left {0} out of {1}", fileCount--, files.Length); string fileText = new StreamReader(file).ReadToEnd(); var hands = fastParser.SplitUpMultipleHandsToLines(fileText); var outputFile = new StreamWriter(file + ".csv"); outputFile.WriteLine("DateOfHandUtc,HandId,DealerButtonPosition,TableName,GameDescription,NumPlayersActive,NumPlayersSeated,Rake,ComumnityCards,TotalPot,PlayerName,HoleCards,StartingStack,SeatNumber,ActionNumber,Amount,HandActionType,Outs,CardOuts,CurrentHandRank,currentPostSize,Street,IsAggressiveAction,IsAllIn,IsAllInAction,IsBlinds,IsGameAction,IsPreFlopRaise,IsRaise,IsWinningsAction"); foreach (var hand in hands) { var parsedHand = fastParser.ParseFullHandHistory(hand, true); // probably not the best way to do this. This should be added to the ParseHandActions function or something. decimal currentPotSize = 0; int actionNumber = 0; foreach (var action in parsedHand.HandActions) { // I tried to do this (this = 'actionNumber++') rtdfgcvdrt properly via the ParseHandActions function in Poker888FastParserImpl.cs file to be 1-1 with the raw handlines, however // I was getting some un-expected behavior when the action was all in and the winning action the handline index would be 0 so you would end up with // actions sequences like 1,2,3,4,5,6,0,8,9,10. actionNumber++; if (action.HandActionType == HandHistories.Objects.Actions.HandActionType.ANTE || action.HandActionType == HandHistories.Objects.Actions.HandActionType.BET || action.HandActionType == HandHistories.Objects.Actions.HandActionType.SMALL_BLIND || action.HandActionType == HandHistories.Objects.Actions.HandActionType.RAISE || action.HandActionType == HandHistories.Objects.Actions.HandActionType.BIG_BLIND || action.HandActionType == HandHistories.Objects.Actions.HandActionType.CALL || action.HandActionType == HandHistories.Objects.Actions.HandActionType.ALL_IN) { currentPotSize += action.Amount; } // Don't judge me.... this code is just chaos...but it's works. string handRank; HandEvaluator.HandEvaluator he = new HandEvaluator.HandEvaluator(); string handstring = String.Format("{0}{1}", parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).HoleCards, parsedHand.ComumnityCards); string flopstring; string turnstring; string riverstring; string currenthandstring; Hand h = new Hand(); // holecards Hand hc = new Hand(); Dictionary <Hand, int> handOuts = new Dictionary <Hand, int>(); Dictionary <Hand, List <Card> > cardouts; int outs = 0; double hr = 0.0; string couts = ""; if (handstring.Length >= 14) { currenthandstring = ""; flopstring = handstring.Substring(4, 6); turnstring = handstring.Substring(10, 2); riverstring = handstring.Substring(12, 2); // build the hand play-by-play so we can get current hand ranking and also build in hand outs. switch (action.Street) { case HandHistories.Objects.Cards.Street.Flop: currenthandstring = handstring.Substring(0, 4) + flopstring; h = new Hand(currenthandstring, 7, 5); hc = new Hand(handstring.Substring(0, 4), 7, 5); hr = he.RankHand(h, out handRank); handOuts = he.ComputeOuts(h, hc.HAND, new Hand(flopstring, 7, 5).HAND, out cardouts); outs = handOuts[h]; couts = new Hand(cardouts[h], 52, 5).HandToString(); break; case HandHistories.Objects.Cards.Street.Turn: currenthandstring = handstring.Substring(0, 4) + flopstring + turnstring; h = new Hand(currenthandstring, 7, 5); hc = new Hand(handstring.Substring(0, 4), 7, 5); hr = he.RankHand(h, out handRank); handOuts = he.ComputeOuts(h, hc.HAND, new Hand(flopstring + turnstring, 7, 5).HAND, out cardouts); outs = handOuts[h]; couts = new Hand(cardouts[h], 52, 5).HandToString(); break; case HandHistories.Objects.Cards.Street.River: currenthandstring = handstring.Substring(0, 4) + flopstring + turnstring + riverstring; h = new Hand(currenthandstring, 7, currenthandstring.Length / 2); hc = new Hand(handstring.Substring(0, 4), 7, 5); hr = he.RankHand(h, out handRank); outs = 0; // No need to compute outs on the river. No more cards to come. break; default: hr = 0.0; outs = 0; break; } } else { hr = 0.0; outs = 0; } outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29}", parsedHand.DateOfHandUtc , parsedHand.HandId , parsedHand.DealerButtonPosition , parsedHand.TableName , parsedHand.GameDescription , parsedHand.NumPlayersActive , parsedHand.NumPlayersSeated , parsedHand.Rake , parsedHand.ComumnityCards , parsedHand.TotalPot , action.PlayerName , parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).HoleCards , parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).StartingStack , parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).SeatNumber , actionNumber , action.Amount , action.HandActionType , outs.ToString() , couts , hr.ToString() , currentPotSize , action.Street , action.IsAggressiveAction , action.IsAllIn , action.IsAllInAction , action.IsBlinds , action.IsGameAction , action.IsPreFlopRaise , action.IsRaise , action.IsWinningsAction ); } } outputFile.Close(); } } catch (Exception ex) // Catch hand-parsing exceptions { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. Console.ReadLine(); } }