FulltiltToFpdb handles canceled hands

Better exception handling during parsing
FpdbParseEcxeption takes an optional HID
Stripped pointless __init__s from *ToFpdb subclasses
Logging now has logging.conf config - default is to log only INFO to
file but easily changed to DEBUG for devel work
This commit is contained in:
Matt Turnbull
2009-08-09 15:19:43 +01:00
parent 56ea7c6eab
commit a32d4e053a
11 changed files with 164 additions and 171 deletions
+26 -25
View File
@@ -32,6 +32,8 @@ import pprint
import DerivedStats
import Card
log = logging.getLogger("parser")
class Hand(object):
###############################################################3
@@ -162,7 +164,7 @@ shown whether they were revealed at showdown
mucked whether they were mucked at showdown
dealt whether they were seen in a 'dealt to' line
"""
# logging.debug("addHoleCards %s %s" % (open + closed, player))
# log.debug("addHoleCards %s %s" % (open + closed, player))
try:
self.checkPlayerExists(player)
except FpdbParseError, e:
@@ -264,7 +266,7 @@ seat (int) indicating the seat
name (string) player name
chips (string) the chips the player has at the start of the hand (can be None)
If a player has None chips he won't be added."""
logging.debug("addPlayer: %s %s (%s)" % (seat, name, chips))
log.debug("addPlayer: %s %s (%s)" % (seat, name, chips))
if chips is not None:
chips = re.sub(u',', u'', chips) #some sites have commas
self.players.append([seat, name, chips])
@@ -280,9 +282,9 @@ If a player has None chips he won't be added."""
# go through m and initialise actions to empty list for each street.
if match:
self.streets.update(match.groupdict())
logging.debug("markStreets:\n"+ str(self.streets))
log.debug("markStreets:\n"+ str(self.streets))
else:
logging.error("markstreets didn't match")
log.error("markstreets didn't match")
def checkPlayerExists(self,player):
if player not in [p[1] for p in self.players]:
@@ -292,7 +294,7 @@ If a player has None chips he won't be added."""
def setCommunityCards(self, street, cards):
logging.debug("setCommunityCards %s %s" %(street, cards))
log.debug("setCommunityCards %s %s" %(street, cards))
self.board[street] = [self.card(c) for c in cards]
# print "DEBUG: self.board: %s" % self.board
@@ -303,7 +305,7 @@ If a player has None chips he won't be added."""
return c
def addAnte(self, player, ante):
logging.debug("%s %s antes %s" % ('ANTES', player, ante))
log.debug("%s %s antes %s" % ('ANTES', player, ante))
if player is not None:
ante = re.sub(u',', u'', ante) #some sites have commas
self.bets['ANTES'][player].append(Decimal(ante))
@@ -322,7 +324,7 @@ If a player has None chips he won't be added."""
# - this is a call of 1 sb and a raise to 1 bb
#
logging.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
if player is not None:
amount = re.sub(u',', u'', amount) #some sites have commas
self.bets['PREFLOP'][player].append(Decimal(amount))
@@ -344,7 +346,7 @@ If a player has None chips he won't be added."""
def addCall(self, street, player=None, amount=None):
if amount:
amount = re.sub(u',', u'', amount) #some sites have commas
logging.debug("%s %s calls %s" %(street, player, amount))
log.debug("%s %s calls %s" %(street, player, amount))
# Potentially calculate the amount of the call if not supplied
# corner cases include if player would be all in
if amount is not None:
@@ -414,7 +416,7 @@ Add a raise on [street] by [player] to [amountTo]
self._addRaise(street, player, C, Rb, Rt)
def _addRaise(self, street, player, C, Rb, Rt):
logging.debug("%s %s raise %s" %(street, player, Rt))
log.debug("%s %s raise %s" %(street, player, Rt))
self.bets[street][player].append(C + Rb)
self.stacks[player] -= (C + Rb)
act = (player, 'raises', Rb, Rt, C, self.stacks[player]==0)
@@ -425,7 +427,7 @@ Add a raise on [street] by [player] to [amountTo]
def addBet(self, street, player, amount):
logging.debug("%s %s bets %s" %(street, player, amount))
log.debug("%s %s bets %s" %(street, player, amount))
amount = re.sub(u',', u'', amount) #some sites have commas
self.checkPlayerExists(player)
self.bets[street][player].append(Decimal(amount))
@@ -444,7 +446,7 @@ Add a raise on [street] by [player] to [amountTo]
def addFold(self, street, player):
logging.debug("%s %s folds" % (street, player))
log.debug("%s %s folds" % (street, player))
self.checkPlayerExists(player)
self.folded.add(player)
self.pot.addFold(player)
@@ -458,7 +460,7 @@ Add a raise on [street] by [player] to [amountTo]
def addCollectPot(self,player, pot):
logging.debug("%s collected %s" % (player, pot))
log.debug("%s collected %s" % (player, pot))
self.checkPlayerExists(player)
self.collected = self.collected + [[player, pot]]
if player not in self.collectees:
@@ -472,7 +474,7 @@ Add a raise on [street] by [player] to [amountTo]
For when a player shows cards for any reason (for showdown or out of choice).
Card ranks will be uppercased
"""
logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard))
log.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard))
if cards is not None:
self.addHoleCards(cards,player,shown, mucked)
elif holeandboard is not None:
@@ -522,7 +524,7 @@ Map the tuple self.gametype onto the pokerstars string describing it
"cp" : "Cap Pot Limit"
}
logging.debug("gametype: %s" %(self.gametype))
log.debug("gametype: %s" %(self.gametype))
retstring = "%s %s" %(gs[self.gametype['category']], ls[self.gametype['limitType']])
return retstring
@@ -601,7 +603,7 @@ class HoldemOmahaHand(Hand):
def __init__(self, hhc, sitename, gametype, handText, builtFrom = "HHC", handid=None):
if gametype['base'] != 'hold':
pass # or indeed don't pass and complain instead
logging.debug("HoldemOmahaHand")
log.debug("HoldemOmahaHand")
self.allStreets = ['BLINDSANTES', 'PREFLOP','FLOP','TURN','RIVER']
self.holeStreets = ['PREFLOP']
self.communityStreets = ['FLOP', 'TURN', 'RIVER']
@@ -640,9 +642,9 @@ class HoldemOmahaHand(Hand):
if handid is not None:
self.select(handid) # Will need a handId
else:
logging.warning("HoldemOmahaHand.__init__:Can't assemble hand from db without a handid")
log.warning("HoldemOmahaHand.__init__:Can't assemble hand from db without a handid")
else:
logging.warning("HoldemOmahaHand.__init__:Neither HHC nor DB+handid provided")
log.warning("HoldemOmahaHand.__init__:Neither HHC nor DB+handid provided")
pass
@@ -754,7 +756,7 @@ class HoldemOmahaHand(Hand):
super(HoldemOmahaHand, self).writeHand(fh)
players_who_act_preflop = set(([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']]))
logging.debug(self.actions['PREFLOP'])
log.debug(self.actions['PREFLOP'])
for player in [x for x in self.players if x[1] in players_who_act_preflop]:
#Only print stacks of players who do something preflop
print >>fh, ("Seat %s: %s ($%s in chips) " %(player[0], player[1], player[2]))
@@ -897,7 +899,7 @@ class DrawHand(Hand):
# - this is a call of 1 sb and a raise to 1 bb
#
logging.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
if player is not None:
self.bets['DEAL'][player].append(Decimal(amount))
self.stacks[player] -= Decimal(amount)
@@ -924,7 +926,7 @@ class DrawHand(Hand):
def discardDrawHoleCards(self, cards, player, street):
logging.debug("discardDrawHoleCards '%s' '%s' '%s'" % (cards, player, street))
log.debug("discardDrawHoleCards '%s' '%s' '%s'" % (cards, player, street))
self.discards[street][player] = set([cards])
@@ -1042,8 +1044,7 @@ class StudHand(Hand):
for street in self.actionStreets:
if street == 'ANTES': continue # OMG--sometime someone folds in the ante round
if self.streets[street]:
logging.debug(street)
logging.debug(self.streets[street])
log.debug(street + self.streets[street])
hhc.readAction(self, street)
hhc.readCollectPot(self)
hhc.readShownCards(self) # not done yet
@@ -1075,7 +1076,7 @@ street (string) the street name (in streetList)
open list of card bigrams e.g. ['2h','Jc'], dealt face up
closed likewise, but known only to player
"""
logging.debug("addPlayerCards %s, o%s x%s" % (player, open, closed))
log.debug("addPlayerCards %s, o%s x%s" % (player, open, closed))
try:
self.checkPlayerExists(player)
self.holecards[street][player] = (open, closed)
@@ -1089,7 +1090,7 @@ closed likewise, but known only to player
"""\
Add a complete on [street] by [player] to [amountTo]
"""
logging.debug("%s %s completes %s" % (street, player, amountTo))
log.debug("%s %s completes %s" % (street, player, amountTo))
amountTo = re.sub(u',', u'', amountTo) #some sites have commas
self.checkPlayerExists(player)
Bp = self.lastBet['THIRD']
@@ -1107,7 +1108,7 @@ Add a complete on [street] by [player] to [amountTo]
def addBringIn(self, player, bringin):
if player is not None:
logging.debug("Bringin: %s, %s" % (player , bringin))
log.debug("Bringin: %s, %s" % (player , bringin))
self.bets['THIRD'][player].append(Decimal(bringin))
self.stacks[player] -= Decimal(bringin)
act = (player, 'bringin', bringin, self.stacks[player]==0)