From 25799d01f209b03f21904eb79f78affc63dfee15 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 25 Feb 2011 04:19:00 -0500 Subject: [PATCH] Don't bother recompiling regexs for every hand when parsing Stars HHs. --- pyfpdb/PokerStarsToFpdb.py | 41 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 67d8c433..4096ca92 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -131,34 +131,29 @@ class PokerStars(HandHistoryConverter): # revised re including timezone (not currently used): #re_DateTime = re.compile("""(?P[0-9]{4})\/(?P[0-9]{2})\/(?P[0-9]{2})[\- ]+(?P[0-9]+):(?P[0-9]+):(?P[0-9]+) \(?(?P[A-Z0-9]+)""", re.MULTILINE) - def compilePlayerRegexs(self, hand): - players = set([player[1] for player in hand.players]) - if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' - # we need to recompile the player regexs. -# TODO: should probably rename re_HeroCards and corresponding method, -# since they are used to find all cards on lines starting with "Dealt to:" -# They still identify the hero. - self.compiledPlayers = players - player_re = "(?P" + "|".join(map(re.escape, players)) + ")" - subst = {'PLYR': player_re, 'CUR': self.sym[hand.gametype['currency']]} - log.debug("player_re: " + player_re) - self.re_PostSB = re.compile(r"^%(PLYR)s: posts small blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_PostBB = re.compile(r"^%(PLYR)s: posts big blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_PostBoth = re.compile(r"^%(PLYR)s: posts small \& big blinds %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_HeroCards = re.compile(r"^Dealt to %(PLYR)s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % subst, re.MULTILINE) - self.re_Action = re.compile(r""" + # These used to be compiled per player, but regression tests say + # we don't have to, and it makes life faster. + short_subst = {'PLYR': r'(?P.+?)', 'CUR': '\$?'} + re_PostSB = re.compile(r"^%(PLYR)s: posts small blind %(CUR)s(?P[.0-9]+)" % short_subst, re.MULTILINE) + re_PostBB = re.compile(r"^%(PLYR)s: posts big blind %(CUR)s(?P[.0-9]+)" % short_subst, re.MULTILINE) + re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % short_subst, re.MULTILINE) + re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P[.0-9]+)" % short_subst, re.MULTILINE) + re_PostBoth = re.compile(r"^%(PLYR)s: posts small \& big blinds %(CUR)s(?P[.0-9]+)" % short_subst, re.MULTILINE) + re_HeroCards = re.compile(r"^Dealt to %(PLYR)s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % short_subst, re.MULTILINE) + re_Action = re.compile(r""" ^%(PLYR)s:(?P\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat) (\s(%(CUR)s)?(?P[.\d]+))?(\sto\s%(CUR)s(?P[.\d]+))? # the number discarded goes in \s*(and\sis\sall.in)? (and\shas\sreached\sthe\s[%(CUR)s\d\.]+\scap)? (\scards?(\s\[(?P.+?)\])?)?\s*$""" - % subst, re.MULTILINE|re.VERBOSE) - self.re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % player_re, re.MULTILINE) - self.re_CollectPot = re.compile(r"Seat (?P[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P[.\d]+)\)(, mucked| with.*|)" % subst, re.MULTILINE) - self.re_sitsOut = re.compile("^%s sits out" % player_re, re.MULTILINE) - self.re_ShownCards = re.compile("^Seat (?P[0-9]+): %s (\(.*\) )?(?Pshowed|mucked) \[(?P.*)\].*" % player_re, re.MULTILINE) + % short_subst, re.MULTILINE|re.VERBOSE) + re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % short_subst['PLYR'], re.MULTILINE) + re_sitsOut = re.compile("^%s sits out" % short_subst['PLYR'], re.MULTILINE) + re_ShownCards = re.compile("^Seat (?P[0-9]+): %s (\(.*\) )?(?Pshowed|mucked) \[(?P.*)\].*" % short_subst['PLYR'], re.MULTILINE) + re_CollectPot = re.compile(r"Seat (?P[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P[.\d]+)\)(, mucked| with.*|)" % short_subst, re.MULTILINE) + + def compilePlayerRegexs(self, hand): + pass def readSupportedGames(self): return [["ring", "hold", "nl"],