Merge branch 'master' of git://github.com/grindi/fpdb-grindi
This commit is contained in:
commit
470d34c65c
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.pyc
|
||||
*~
|
|
@ -453,6 +453,7 @@ Add a raise on [street] by [player] to [amountTo]
|
|||
|
||||
def addCheck(self, street, player):
|
||||
#print "DEBUG: %s %s checked" % (street, player)
|
||||
logging.debug("%s %s checks" % (street, player))
|
||||
self.checkPlayerExists(player)
|
||||
self.actions[street].append((player, 'checks'))
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#Copyright 2008 Carl Gherardi
|
||||
#This program is free software: you can redistribute it and/or modify
|
||||
|
@ -95,9 +96,14 @@ Otherwise, finish at eof.
|
|||
else:
|
||||
handsList = self.allHandsAsList()
|
||||
logging.info("Parsing %d hands" % len(handsList))
|
||||
nBadHangs = 0
|
||||
for handText in handsList:
|
||||
self.processedHands.append(self.processHand(handText))
|
||||
numHands= len(handsList)
|
||||
try:
|
||||
self.processedHands.append(self.processHand(handText))
|
||||
except Exception, e: # TODO: it's better to replace it with s-t like HhcEception
|
||||
nBadHangs += 1
|
||||
logging.error("Caught exception while parsing hand: %s" % str(e))
|
||||
numHands = len(handsList) - nBadHangs
|
||||
endtime = time.time()
|
||||
print "read %d hands in %.3f seconds" % (numHands, endtime - starttime)
|
||||
if self.out_fh != sys.stdout:
|
||||
|
|
|
@ -70,25 +70,6 @@ class PartyPoker(HandHistoryConverter):
|
|||
(?P<DATETIME>.+)
|
||||
""", re.VERBOSE)
|
||||
re_Hid = re.compile("^Game \#(?P<HID>\d+) starts.")
|
||||
#re_GameInfo = re.compile("""
|
||||
#PartyPoker\sGame\s\#(?P<HID>[0-9]+):\s+
|
||||
#(Tournament\s\# # open paren of tournament info
|
||||
#(?P<TOURNO>\d+),\s
|
||||
#(?P<BUYIN>[%(LS)s\+\d\.]+ # here's how I plan to use LS
|
||||
#\s?(?P<TOUR_ISO>%(LEGAL_ISO)s)?
|
||||
#)\s)? # close paren of tournament info
|
||||
#(?P<MIXED>HORSE|8\-Game|HOSE)?\s?\(?
|
||||
#(?P<GAME>Hold\'em|Razz|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball)\s
|
||||
#(?P<LIMIT>No\sLimit|Limit|Pot\sLimit)\)?,?\s
|
||||
#(-\sLevel\s(?P<LEVEL>[IVXLC]+)\s)?
|
||||
#\(? # open paren of the stakes
|
||||
#(?P<CURRENCY>%(LS)s|)?
|
||||
#(?P<SB>[.0-9]+)/(%(LS)s)?
|
||||
#(?P<BB>[.0-9]+)
|
||||
#\s?(?P<ISO>%(LEGAL_ISO)s)?
|
||||
#\)\s-\s # close paren of the stakes
|
||||
#(?P<DATETIME>.*$)""" % substitutions,
|
||||
#re.MULTILINE|re.VERBOSE)
|
||||
|
||||
re_PlayerInfo = re.compile("""
|
||||
Seat\s(?P<SEAT>\d+):\s
|
||||
|
@ -96,11 +77,6 @@ class PartyPoker(HandHistoryConverter):
|
|||
\(\s*\$?(?P<CASH>[0-9,.]+)\s*(?:USD|)\s*\)
|
||||
""" ,
|
||||
re.VERBOSE)
|
||||
#re_PlayerInfo = re.compile("""
|
||||
#^Seat\s(?P<SEAT>[0-9]+):\s
|
||||
#(?P<PNAME>.*)\s
|
||||
#\((%(LS)s)?(?P<CASH>[.0-9]+)\sin\schips\)""" % substitutions,
|
||||
#re.MULTILINE|re.VERBOSE)
|
||||
|
||||
re_HandInfo = re.compile("""
|
||||
^Table\s+
|
||||
|
@ -111,12 +87,6 @@ class PartyPoker(HandHistoryConverter):
|
|||
Seat\s+(?P<BUTTON>\d+)\sis\sthe\sbutton
|
||||
""",
|
||||
re.MULTILINE|re.VERBOSE)
|
||||
#re_HandInfo = re.compile("""
|
||||
#^Table\s\'(?P<TABLE>[-\ a-zA-Z\d]+)\'\s
|
||||
#((?P<MAX>\d+)-max\s)?
|
||||
#(?P<PLAY>\(Play\sMoney\)\s)?
|
||||
#(Seat\s\#(?P<BUTTON>\d+)\sis\sthe\sbutton)?""",
|
||||
#re.MULTILINE|re.VERBOSE)
|
||||
|
||||
re_SplitHands = re.compile('\x00+')
|
||||
re_TailSplitHands = re.compile('(\x00+)')
|
||||
|
@ -124,7 +94,6 @@ class PartyPoker(HandHistoryConverter):
|
|||
re_Button = re.compile('Seat (?P<BUTTON>\d+) is the button', re.MULTILINE)
|
||||
re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
|
||||
re_NoSmallBlind = re.compile('^There is no Small Blind in this hand as the Big Blind of the previous hand left the table')
|
||||
# self.re_setHandInfoRegex('.*#(?P<HID>[0-9]+): Table (?P<TABLE>[ a-zA-Z]+) - \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) - (?P<GAMETYPE>.*) - (?P<HR>[0-9]+):(?P<MIN>[0-9]+) ET - (?P<YEAR>[0-9]+)/(?P<MON>[0-9]+)/(?P<DAY>[0-9]+)Table (?P<TABLE>[ a-zA-Z]+)\nSeat (?P<BUTTON>[0-9]+)')
|
||||
|
||||
|
||||
def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, index=0):
|
||||
|
@ -148,14 +117,12 @@ follow : whether to tail -f the input"""
|
|||
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<PNAME>" + "|".join(map(re.escape, players)) + ")"
|
||||
subst = {'PLYR': player_re, 'CUR_SYM': hand.SYMBOL[hand.gametype['currency']],
|
||||
'CUR': hand.gametype['currency'] if hand.gametype['currency']!='T$' else ''}
|
||||
for key in ('CUR_SYM', 'CUR'):
|
||||
subst[key] = re.escape(subst[key])
|
||||
logging.debug("player_re: " + subst['PLYR'])
|
||||
logging.debug("CUR_SYM: " + subst['CUR_SYM'])
|
||||
logging.debug("CUR: " + subst['CUR'])
|
||||
|
@ -168,12 +135,6 @@ follow : whether to tail -f the input"""
|
|||
self.re_Antes = re.compile(
|
||||
r"^%(PLYR)s posts ante \[%(CUR_SYM)s(?P<ANTE>[.0-9]+) ?%(CUR)s\]\." % subst,
|
||||
re.MULTILINE)
|
||||
#self.re_BringIn = re.compile(
|
||||
#r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P<BRINGIN>[.0-9]+)" % subst,
|
||||
#re.MULTILINE)
|
||||
#self.re_PostBoth = re.compile(
|
||||
#r"^%(PLYR)s: posts small \& big blinds \[%(CUR)s (?P<SBBB>[.0-9]+)" % subst,
|
||||
#re.MULTILINE)
|
||||
self.re_HeroCards = re.compile(
|
||||
r"^Dealt to %(PLYR)s \[\s*(?P<NEWCARDS>.+)\s*\]" % subst,
|
||||
re.MULTILINE)
|
||||
|
@ -190,11 +151,6 @@ follow : whether to tail -f the input"""
|
|||
r""""^%(PLYR)s \s+ wins \s+
|
||||
%(CUR_SYM)s(?P<POT>[.\d]+)\s*%(CUR)s""" % subst,
|
||||
re.MULTILINE|re.VERBOSE)
|
||||
#self.re_sitsOut = re.compile("^%s sits out" % player_re, re.MULTILINE)
|
||||
#self.re_ShownCards = re.compile(
|
||||
#"^Seat (?P<SEAT>[0-9]+): %s (\(.*\) )?
|
||||
#(?P<SHOWED>showed|mucked) \[(?P<CARDS>.*)\].*" % player_re,
|
||||
#re.MULTILINE)
|
||||
|
||||
def readSupportedGames(self):
|
||||
return [["ring", "hold", "nl"],
|
||||
|
@ -211,8 +167,6 @@ follow : whether to tail -f the input"""
|
|||
# let's determine whether hand is trny
|
||||
# and whether 5-th line contains head line
|
||||
headLine = handText.split(self.lineSplitter)[4]
|
||||
#print headLine
|
||||
#sys.exit(1)
|
||||
for headLineContainer in headLine, handText:
|
||||
for regexp in self.re_GameInfoTrny, self.re_GameInfoRing:
|
||||
m = regexp.search(headLineContainer)
|
||||
|
@ -222,18 +176,18 @@ follow : whether to tail -f the input"""
|
|||
return self._gameType
|
||||
|
||||
def determineGameType(self, handText):
|
||||
# inspect the handText and return the gametype dict
|
||||
# gametype dict is:
|
||||
# {'limitType': xxx, 'base': xxx, 'category': xxx}
|
||||
"""inspect the handText and return the gametype dict
|
||||
|
||||
print self.ParsingException().wrapHh( handText )
|
||||
gametype dict is:
|
||||
{'limitType': xxx, 'base': xxx, 'category': xxx}"""
|
||||
|
||||
logging.debug(self.ParsingException().wrapHh( handText ))
|
||||
|
||||
info = {}
|
||||
m = self._getGameType(handText)
|
||||
if m is None:
|
||||
return None
|
||||
|
||||
|
||||
mg = m.groupdict()
|
||||
# translations from captured groups to fpdb info strings
|
||||
limits = { 'NL':'nl',
|
||||
|
@ -273,13 +227,12 @@ follow : whether to tail -f the input"""
|
|||
if info['type'] == 'ring':
|
||||
info['sb'], info['bb'] = ringBlinds(mg['RINGLIMIT'])
|
||||
# FIXME: there are only $ and play money availible for cash
|
||||
info['currency'] = currencies(mg['CURRENCY'])
|
||||
info['currency'] = currencies[mg['CURRENCY']]
|
||||
else:
|
||||
info['sb'] = renderTrnyMoney(mg['SB'])
|
||||
info['bb'] = renderTrnyMoney(mg['BB'])
|
||||
info['currency'] = 'T$'
|
||||
|
||||
|
||||
# NB: SB, BB must be interpreted as blinds or bets depending on limit type.
|
||||
return info
|
||||
|
||||
|
@ -297,10 +250,9 @@ follow : whether to tail -f the input"""
|
|||
if m: info.update(m.groupdict())
|
||||
|
||||
# FIXME: it's a hack cause party doesn't supply hand.maxseats info
|
||||
#hand.maxseats = '9'
|
||||
#hand.maxseats = ???
|
||||
hand.mixed = None
|
||||
|
||||
# TODO : I rather like the idea of just having this dict as hand.info
|
||||
logging.debug("readHandInfo: %s" % info)
|
||||
for key in info:
|
||||
if key == 'DATETIME':
|
||||
|
@ -313,6 +265,7 @@ follow : whether to tail -f the input"""
|
|||
month = months.index(m2.group('M')) + 1
|
||||
datetimestr = "%s/%s/%s %s:%s:%s" % (m2.group('Y'), month,m2.group('D'),m2.group('H'),m2.group('MIN'),m2.group('S'))
|
||||
hand.starttime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
|
||||
# FIXME: some timezone correction required
|
||||
#tzShift = defaultdict(lambda:0, {'EDT': -5, 'EST': -6, 'MSKS': 3})
|
||||
#hand.starttime -= datetime.timedelta(hours=tzShift[m2.group('TZ')])
|
||||
|
||||
|
@ -373,13 +326,11 @@ follow : whether to tail -f the input"""
|
|||
logging.debug("reading antes")
|
||||
m = self.re_Antes.finditer(hand.handText)
|
||||
for player in m:
|
||||
#~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
|
||||
hand.addAnte(player.group('PNAME'), player.group('ANTE'))
|
||||
|
||||
def readBringIn(self, hand):
|
||||
m = self.re_BringIn.search(hand.handText,re.DOTALL)
|
||||
if m:
|
||||
#~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
|
||||
hand.addBringIn(m.group('PNAME'), m.group('BRINGIN'))
|
||||
|
||||
def readBlinds(self, hand):
|
||||
|
@ -426,15 +377,11 @@ follow : whether to tail -f the input"""
|
|||
|
||||
|
||||
def readHeroCards(self, hand):
|
||||
# streets PREFLOP, PREDRAW, and THIRD are special cases beacause
|
||||
# we need to grab hero's cards
|
||||
# we need to grab hero's cards
|
||||
for street in ('PREFLOP',):
|
||||
if street in hand.streets.keys():
|
||||
m = self.re_HeroCards.finditer(hand.streets[street])
|
||||
for found in m:
|
||||
# if m == None:
|
||||
# hand.involved = False
|
||||
# else:
|
||||
hand.hero = found.group('PNAME')
|
||||
newcards = renderCards(found.group('NEWCARDS'))
|
||||
hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
|
||||
|
@ -445,13 +392,9 @@ follow : whether to tail -f the input"""
|
|||
for action in m:
|
||||
acts = action.groupdict()
|
||||
if action.group('ATYPE') in ('raises','is all-In'):
|
||||
#print action.groupdict()
|
||||
#sys.exit(1)
|
||||
hand.addRaiseBy( street, action.group('PNAME'), action.group('BET') )
|
||||
elif action.group('ATYPE') == 'calls':
|
||||
hand.addCall( street, action.group('PNAME'), action.group('BET') )
|
||||
#print action.groupdict()
|
||||
#sys.exit(1)
|
||||
elif action.group('ATYPE') == 'bets':
|
||||
hand.addBet( street, action.group('PNAME'), action.group('BET') )
|
||||
elif action.group('ATYPE') == 'folds':
|
||||
|
@ -465,10 +408,6 @@ follow : whether to tail -f the input"""
|
|||
def readShowdownActions(self, hand):
|
||||
# all action in readShownCards
|
||||
pass
|
||||
## TODO: pick up mucks also??
|
||||
#for shows in self.re_ShowdownAction.finditer(hand.handText):
|
||||
#cards = shows.group('CARDS').split(' ')
|
||||
#hand.addShownCards(cards, shows.group('PNAME'))
|
||||
|
||||
def readCollectPot(self,hand):
|
||||
for m in self.re_CollectPot.finditer(hand.handText):
|
||||
|
@ -503,7 +442,7 @@ def renderCards(string):
|
|||
|
||||
if __name__ == "__main__":
|
||||
parser = OptionParser()
|
||||
parser.add_option("-i", "--input", dest="ipath", help="parse input hand history", default="regression-test-files/stars/horse/HH20090226 Natalie V - $0.10-$0.20 - HORSE.txt")
|
||||
parser.add_option("-i", "--input", dest="ipath", help="parse input hand history")
|
||||
parser.add_option("-o", "--output", dest="opath", help="output translation to", default="-")
|
||||
parser.add_option("-f", "--follow", dest="follow", help="follow (tail -f) the input", action="store_true", default=False)
|
||||
parser.add_option("-q", "--quiet",
|
||||
|
|
Loading…
Reference in New Issue
Block a user