Impoved cards parsing

This commit is contained in:
grindi 2009-08-06 00:09:52 +04:00
parent ebe652d49e
commit aa62dc47c9

View File

@ -193,15 +193,11 @@ follow : whether to tail -f the input"""
#["ring", "hold", "pl"], #["ring", "hold", "pl"],
#["ring", "hold", "fl"], #["ring", "hold", "fl"],
#["ring", "stud", "fl"],
#["ring", "draw", "fl"],
["tour", "hold", "nl"], ["tour", "hold", "nl"],
#["tour", "hold", "pl"], #["tour", "hold", "pl"],
#["tour", "hold", "fl"], #["tour", "hold", "fl"],
#["tour", "stud", "fl"],
] ]
def _getGameType(self, handText): def _getGameType(self, handText):
@ -223,7 +219,13 @@ follow : whether to tail -f the input"""
# inspect the handText and return the gametype dict # inspect the handText and return the gametype dict
# gametype dict is: # gametype dict is:
# {'limitType': xxx, 'base': xxx, 'category': xxx} # {'limitType': xxx, 'base': xxx, 'category': xxx}
#print
#print
#print '#'*70
#print handText
#print '#'*70
#print
#print
info = {} info = {}
m = self._getGameType(handText) m = self._getGameType(handText)
@ -290,8 +292,8 @@ follow : whether to tail -f the input"""
m = self.re_Hid.search(hand.handText) m = self.re_Hid.search(hand.handText)
if m: info.update(m.groupdict()) if m: info.update(m.groupdict())
# FIXME: it's a hack couse party doesn't supply hand.maxseats info # FIXME: it's a hack cause party doesn't supply hand.maxseats info
hand.maxseats = '9' #hand.maxseats = '9'
hand.mixed = None hand.mixed = None
# TODO : I rather like the idea of just having this dict as hand.info # TODO : I rather like the idea of just having this dict as hand.info
@ -301,11 +303,14 @@ follow : whether to tail -f the input"""
#Saturday, July 25, 07:53:52 EDT 2009 #Saturday, July 25, 07:53:52 EDT 2009
#Thursday, July 30, 21:40:41 MSKS 2009 #Thursday, July 30, 21:40:41 MSKS 2009
m2 = re.search("\w+, (?P<M>\w+) (?P<D>\d+), (?P<H>\d+):(?P<MIN>\d+):(?P<S>\d+) (?P<TZ>[A-Z]+) (?P<Y>\d+)", info[key]) m2 = re.search("\w+, (?P<M>\w+) (?P<D>\d+), (?P<H>\d+):(?P<MIN>\d+):(?P<S>\d+) (?P<TZ>[A-Z]+) (?P<Y>\d+)", info[key])
datetimestr = "%s/%s/%s %s:%s:%s" % (m2.group('Y'), m2.group('M'),m2.group('D'),m2.group('H'),m2.group('MIN'),m2.group('S')) # we cant use '%B' due to locale problems
hand.starttime = datetime.datetime.strptime(datetimestr, "%Y/%B/%d %H:%M:%S") months = ['January', 'February', 'March', 'April','May', 'June',
#FIXME: it's hack 'July','August','September','October','November','December']
tzShift = defaultdict(lambda:0, {'EDT': -5, 'EST': -6, 'MSKS': 3}) month = months.index(m2.group('M')) + 1
hand.starttime -= datetime.timedelta(hours=tzShift[m2.group('TZ')]) 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")
#tzShift = defaultdict(lambda:0, {'EDT': -5, 'EST': -6, 'MSKS': 3})
#hand.starttime -= datetime.timedelta(hours=tzShift[m2.group('TZ')])
if key == 'HID': if key == 'HID':
hand.handid = info[key] hand.handid = info[key]
@ -363,7 +368,7 @@ follow : whether to tail -f the input"""
if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP) if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
#print "DEBUG readCommunityCards:", street, hand.streets.group(street) #print "DEBUG readCommunityCards:", street, hand.streets.group(street)
m = self.re_Board.search(hand.streets[street]) m = self.re_Board.search(hand.streets[street])
hand.setCommunityCards(street, m.group('CARDS').strip().split(' ')) hand.setCommunityCards(street, renderCards(m.group('CARDS')))
def readAntes(self, hand): def readAntes(self, hand):
logging.debug("reading antes") logging.debug("reading antes")
@ -432,7 +437,7 @@ follow : whether to tail -f the input"""
# hand.involved = False # hand.involved = False
# else: # else:
hand.hero = found.group('PNAME') hand.hero = found.group('PNAME')
newcards = found.group('NEWCARDS').split(' ') newcards = renderCards(found.group('NEWCARDS'))
hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True) hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
@ -471,8 +476,7 @@ follow : whether to tail -f the input"""
def readShownCards(self,hand): def readShownCards(self,hand):
for m in self.re_ShownCards.finditer(hand.handText): for m in self.re_ShownCards.finditer(hand.handText):
if m.group('CARDS') is not None: if m.group('CARDS') is not None:
cards = m.group('CARDS') cards = renderCards(m.group('CARDS'))
cards = cards.split(' ') # needs to be a list, not a set--stud needs the order
(shown, mucked) = (False, False) (shown, mucked) = (False, False)
if m.group('SHOWED') == "show": shown = True if m.group('SHOWED') == "show": shown = True
@ -484,12 +488,18 @@ def ringBlinds(ringLimit):
"Returns blinds for current limit" "Returns blinds for current limit"
ringLimit = float(ringLimit) ringLimit = float(ringLimit)
if ringLimit == 5.: ringLimit = 4. if ringLimit == 5.: ringLimit = 4.
return ('%f' % (ringLimit/200.), '%f' % (ringLimit/100.) ) return ('%.2f' % (ringLimit/200.), '%.2f' % (ringLimit/100.) )
def renderTrnyMoney(money): def renderTrnyMoney(money):
"renders 'numbers' like '1 200' and '2,000'" "renders 'numbers' like '1 200' and '2,000'"
return money.replace(' ', '').replace(',', '') return money.replace(' ', '').replace(',', '')
def renderCards(string):
"splits strings like ' Js, 4d '"
cards = string.strip().split(' ')
return filter(len, map(lambda x: x.strip(' ,'), cards))
if __name__ == "__main__": if __name__ == "__main__":
parser = OptionParser() 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", default="regression-test-files/stars/horse/HH20090226 Natalie V - $0.10-$0.20 - HORSE.txt")