Add logging function from futz

This commit is contained in:
Worros 2009-03-05 01:46:01 +09:00
parent 87d9dbcf25
commit 50a1ec1ccf
4 changed files with 31 additions and 19 deletions

View File

@ -18,6 +18,7 @@
######################################################################## ########################################################################
import sys import sys
import logging
import Configuration import Configuration
from HandHistoryConverter import * from HandHistoryConverter import *
from time import strftime from time import strftime
@ -82,6 +83,7 @@ class Everleaf(HandHistoryConverter):
m = self.re_GameInfo.search(handText) m = self.re_GameInfo.search(handText)
if m == None: if m == None:
logging.debug("Gametype didn't match")
return None return None
if m.group('LTYPE') == "NL": if m.group('LTYPE') == "NL":
structure = "nl" structure = "nl"
@ -104,7 +106,10 @@ class Everleaf(HandHistoryConverter):
def readHandInfo(self, hand): def readHandInfo(self, hand):
m = self.re_HandInfo.search(hand.handText) m = self.re_HandInfo.search(hand.handText)
if(m == None): if(m == None):
print "DEBUG: re_HandInfo.search failed: '%s'" %(hand.handText) logging.info("Didn't match re_HandInfo")
logging.info(hand.handtext)
return None
logging.debug("HID %s, Table %s" % (m.group('HID'), m.group('TABLE')))
hand.handid = m.group('HID') hand.handid = m.group('HID')
hand.tablename = m.group('TABLE') hand.tablename = m.group('TABLE')
hand.maxseats = 6 # assume 6-max unless we have proof it's a larger/smaller game, since everleaf doesn't give seat max info hand.maxseats = 6 # assume 6-max unless we have proof it's a larger/smaller game, since everleaf doesn't give seat max info
@ -154,6 +159,7 @@ class Everleaf(HandHistoryConverter):
if m is not None: if m is not None:
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB')) hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
else: else:
logging.debug("No small blind")
hand.addBlind(None, None, None) hand.addBlind(None, None, None)
for a in self.re_PostBB.finditer(hand.handText): for a in self.re_PostBB.finditer(hand.handText):
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB')) hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
@ -177,6 +183,7 @@ class Everleaf(HandHistoryConverter):
hand.involved = False hand.involved = False
def readAction(self, hand, street): def readAction(self, hand, street):
logging.debug("readAction (%s)" % street)
m = self.re_Action.finditer(hand.streets.group(street)) m = self.re_Action.finditer(hand.streets.group(street))
for action in m: for action in m:
if action.group('ATYPE') == ' raises': if action.group('ATYPE') == ' raises':
@ -190,14 +197,16 @@ class Everleaf(HandHistoryConverter):
elif action.group('ATYPE') == ' checks': elif action.group('ATYPE') == ' checks':
hand.addCheck( street, action.group('PNAME')) hand.addCheck( street, action.group('PNAME'))
else: else:
print "DEBUG: unimplemented readAction: %s %s" %(action.group('PNAME'),action.group('ATYPE'),) logging.debug("Unimplemented readAction: %s %s" %(action.group('PNAME'),action.group('ATYPE'),))
def readShowdownActions(self, hand): def readShowdownActions(self, hand):
"""Reads lines where holecards are reported in a showdown""" """Reads lines where holecards are reported in a showdown"""
logging.debug("readShowdownActions")
for shows in self.re_ShowdownAction.finditer(hand.handText): for shows in self.re_ShowdownAction.finditer(hand.handText):
cards = shows.group('CARDS') cards = shows.group('CARDS')
cards = cards.split(', ') cards = cards.split(', ')
logging.debug("readShowdownActions %s %s" %(cards, shows.group('PNAME')))
hand.addShownCards(cards, shows.group('PNAME')) hand.addShownCards(cards, shows.group('PNAME'))
def readCollectPot(self,hand): def readCollectPot(self,hand):
@ -210,6 +219,8 @@ class Everleaf(HandHistoryConverter):
if m.group('CARDS') is not None: if m.group('CARDS') is not None:
cards = m.group('CARDS') cards = m.group('CARDS')
cards = cards.split(', ') cards = cards.split(', ')
player = m.group('PNAME')
logging.debug("readShownCards %s cards=%s" % (player, cards))
hand.addShownCards(cards=None, player=m.group('PNAME'), holeandboard=cards) hand.addShownCards(cards=None, player=m.group('PNAME'), holeandboard=cards)

View File

@ -17,6 +17,7 @@
######################################################################## ########################################################################
import sys import sys
import logging
import Configuration import Configuration
from HandHistoryConverter import * from HandHistoryConverter import *
@ -86,7 +87,7 @@ class FullTilt(HandHistoryConverter):
elif m.group('GAME') == "Razz": elif m.group('GAME') == "Razz":
game = "razz" game = "razz"
print m.groups() logging.debug("HandInfo: %s", m.groupdict())
gametype = ["ring", game, structure, m.group('SB'), m.group('BB')] gametype = ["ring", game, structure, m.group('SB'), m.group('BB')]
@ -156,17 +157,15 @@ class FullTilt(HandHistoryConverter):
hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB')) hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB'))
def readAntes(self, hand): def readAntes(self, hand):
print "DEBUG: reading antes" logging.debug("reading antes")
m = self.re_Antes.finditer(hand.handText) m = self.re_Antes.finditer(hand.handText)
for player in m: for player in m:
print "DEBUG: hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')) logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
hand.addAnte(player.group('PNAME'), player.group('ANTE')) hand.addAnte(player.group('PNAME'), player.group('ANTE'))
def readBringIn(self, hand): def readBringIn(self, hand):
print "DEBUG: reading bring in"
# print hand.string
m = self.re_BringIn.search(hand.handText,re.DOTALL) m = self.re_BringIn.search(hand.handText,re.DOTALL)
print "DEBUG: Player bringing in: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')) logging.debug("Player bringing in: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
hand.addBringIn(m.group('PNAME'), m.group('BRINGIN')) hand.addBringIn(m.group('PNAME'), m.group('BRINGIN'))
def readButton(self, hand): def readButton(self, hand):
@ -191,7 +190,7 @@ class FullTilt(HandHistoryConverter):
print "DEBUG: razz/stud readPlayerCards" print "DEBUG: razz/stud readPlayerCards"
print hand.streets.group(street) print hand.streets.group(street)
for player in m: for player in m:
print player.groups() logging.debug(player.groupdict())
cards = player.group('CARDS') cards = player.group('CARDS')
if player.group('NEWCARD') != None: if player.group('NEWCARD') != None:
print cards print cards

View File

@ -21,6 +21,7 @@ import Hand
import re import re
import sys import sys
import traceback import traceback
import logging
import os import os
import os.path import os.path
import xml.dom.minidom import xml.dom.minidom
@ -123,14 +124,13 @@ If a player has None chips he won't be added."""
def addStreets(self, match): def addStreets(self, match):
# go through m and initialise actions to empty list for each street. # go through m and initialise actions to empty list for each street.
if match is not None: if match:
self.streets = match self.streets = match
for street in match.groupdict(): for street in match.groupdict():
if match.group(street) is not None: if match.group(street) is not None:
self.actions[street] = [] self.actions[street] = []
else: else:
print "empty markStreets match" # better to raise exception and put process hand in a try block logging.error("markstreets didn't match")
def addHoleCards(self, cards, player): def addHoleCards(self, cards, player):
"""\ """\
@ -193,6 +193,7 @@ Card ranks will be uppercased
print "[ERROR] discardHoleCard tried to discard a card %s didn't have" % (player,) print "[ERROR] discardHoleCard tried to discard a card %s didn't have" % (player,)
def setCommunityCards(self, street, cards): def setCommunityCards(self, street, cards):
logging.debug("setCommunityCards %s %s" %(street, cards))
self.board[street] = [self.card(c) for c in cards] self.board[street] = [self.card(c) for c in cards]
def card(self,c): def card(self,c):
@ -216,12 +217,12 @@ Card ranks will be uppercased
# Player in small blind posts # Player in small blind posts
# - this is a bet of 1 sb, as yet uncalled. # - this is a bet of 1 sb, as yet uncalled.
# Player in the big blind posts # Player in the big blind posts
# - this is a bet of 1 bb and is the new uncalled # - this is a call of 1 bb and is the new uncalled
# #
# If a player posts a big & small blind # If a player posts a big & small blind
# - FIXME: We dont record this for later printing yet # - FIXME: We dont record this for later printing yet
#print "DEBUG addBlind: %s posts %s, %s" % (player, blindtype, amount) logging.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
if player is not None: if player is not None:
self.bets['PREFLOP'][player].append(Decimal(amount)) self.bets['PREFLOP'][player].append(Decimal(amount))
self.stacks[player] -= Decimal(amount) self.stacks[player] -= Decimal(amount)
@ -397,10 +398,10 @@ Map the tuple self.gametype onto the pokerstars string describing it
"cp" : "Cap Pot Limit" "cp" : "Cap Pot Limit"
} }
print "DEBUG: self.gametype: %s" %(self.gametype) logging.debug("gametype: %s" %(self.gametype))
string = "%s %s" %(gs[self.gametype[1]], ls[self.gametype[2]]) retstring = "%s %s" %(gs[self.gametype[1]], ls[self.gametype[2]])
return string return retstring
def lookupLimitBetSize(self): def lookupLimitBetSize(self):
#Lookup table for limit games #Lookup table for limit games

View File

@ -21,6 +21,7 @@ import Hand
import re import re
import sys import sys
import traceback import traceback
import logging
import os import os
import os.path import os.path
import xml.dom.minidom import xml.dom.minidom
@ -74,9 +75,9 @@ gettext.install('myapplication')
class HandHistoryConverter: class HandHistoryConverter:
# eval = PokerEval()
def __init__(self, config, file, sitename): def __init__(self, config, file, sitename):
print "HandHistory init called" logging.info("HandHistory init called")
self.c = config self.c = config
self.sitename = sitename self.sitename = sitename
self.obs = "" # One big string self.obs = "" # One big string