Merge branch 'exp' of git://git.assembla.com/mctfpdb

This commit is contained in:
Worros 2008-12-04 18:47:42 +09:00
commit afea3315fc
2 changed files with 67 additions and 60 deletions

25
pyfpdb/EverleafToFpdb.py Normal file → Executable file
View File

@ -73,14 +73,14 @@ class Everleaf(HandHistoryConverter):
self.rexx.setPlayerInfoRegex('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \( \$ (?P<CASH>[.0-9]+) USD \)') self.rexx.setPlayerInfoRegex('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \( \$ (?P<CASH>[.0-9]+) USD \)')
self.rexx.setPostSbRegex('.*\n(?P<PNAME>.*): posts small blind \[') self.rexx.setPostSbRegex('.*\n(?P<PNAME>.*): posts small blind \[')
self.rexx.setPostBbRegex('.*\n(?P<PNAME>.*): posts big blind \[') self.rexx.setPostBbRegex('.*\n(?P<PNAME>.*): posts big blind \[')
self.rexx.setHeroCardsRegex('.*\nDealt\sto\s(?P<PNAME>.*)\s\[ (?P<HOLECARDS>.*) \]') self.rexx.setHeroCardsRegex('.*\nDealt\sto\s(?P<PNAME>.*)\s\[ (?P<HOLE1>\S\S), (?P<HOLE2>\S\S) \]')
self.rexx.setActionStepRegex('.*\n(?P<PNAME>.*) (?P<ATYPE>bets|checks|raises|calls|folds)(\s\[\$ (?P<BET>[.\d]+) USD\])?') self.rexx.setActionStepRegex('.*\n(?P<PNAME>.*) (?P<ATYPE>bets|checks|raises|calls|folds)(\s\[\$ (?P<BET>[.\d]+) USD\])?')
self.rexx.compileRegexes() self.rexx.compileRegexes()
def readSupportedGames(self): def readSupportedGames(self):
pass pass
def determineGameType(self): def determineGameType(self):
# Cheating with this regex, only support nlhe at the moment # Cheating with this regex, only support nlhe at the moment
gametype = ["ring", "hold", "nl"] gametype = ["ring", "hold", "nl"]
@ -110,7 +110,7 @@ class Everleaf(HandHistoryConverter):
int(m.group('HR')), int(m.group('MIN')), int(m.group('SEC'))) int(m.group('HR')), int(m.group('MIN')), int(m.group('SEC')))
hand.buttonpos = int(m.group('BUTTON')) hand.buttonpos = int(m.group('BUTTON'))
def readPlayerStacks(self, hand): def readPlayerStacks(self, hand):
m = self.rexx.player_info_re.finditer(hand.string) m = self.rexx.player_info_re.finditer(hand.string)
players = [] players = []
@ -121,12 +121,12 @@ class Everleaf(HandHistoryConverter):
def markStreets(self, hand): def markStreets(self, hand):
# PREFLOP = ** Dealing down cards ** # PREFLOP = ** Dealing down cards **
m = re.search('(\*\* Dealing down cards \*\*\n)(?P<PREFLOP>.*?\n\*\*)?( Dealing Flop \*\*)?(?P<FLOP>.*?\*\*)?( Dealing Turn \*\*)?(?P<TURN>.*?\*\*)?( Dealing River \*\*)?(?P<RIVER>.*)', hand.string,re.DOTALL) m = re.search('(\*\* Dealing down cards \*\*\n)(?P<PREFLOP>.*?\n\*\*)?( Dealing Flop \*\* \[ (?P<FLOP1>\S\S), (?P<FLOP2>\S\S), (?P<FLOP3>\S\S) \])?(?P<FLOP>.*?\*\*)?( Dealing Turn \*\* \[ (?P<TURN1>\S\S) \])?(?P<TURN>.*?\*\*)?( Dealing River \*\* \[ (?P<RIVER1>\S\S) \])?(?P<RIVER>.*)', hand.string,re.DOTALL)
# for street in m.groupdict(): # for street in m.groupdict():
# print "DEBUG: Street: %s\tspan: %s" %(street, str(m.span(street))) # print "DEBUG: Street: %s\tspan: %s" %(street, str(m.span(street)))
hand.streets = m hand.streets = m
def readBlinds(self, hand): def readBlinds(self, hand):
try: try:
m = self.rexx.small_blind_re.search(hand.string) m = self.rexx.small_blind_re.search(hand.string)
hand.posted = [m.group('PNAME')] hand.posted = [m.group('PNAME')]
@ -143,16 +143,9 @@ class Everleaf(HandHistoryConverter):
hand.involved = False hand.involved = False
else: else:
hand.hero = m.group('PNAME') hand.hero = m.group('PNAME')
hand.holecards = m.group('HOLECARDS') hand.addHoleCards(m.group('HOLE1'), m.group('HOLE2'))
hand.holecards = hand.holecards.replace(',','')
#Must be a better way to do the following tr akqjt AKQJT
hand.holecards = hand.holecards.replace('a','A')
hand.holecards = hand.holecards.replace('k','K')
hand.holecards = hand.holecards.replace('q','Q')
hand.holecards = hand.holecards.replace('j','J')
hand.holecards = hand.holecards.replace('t','T')
def readAction(self, hand, street): def readAction(self, hand, street):
m = self.rexx.action_re.finditer(hand.streets.group(street)) m = self.rexx.action_re.finditer(hand.streets.group(street))
hand.actions[street] = [] hand.actions[street] = []
for action in m: for action in m:
@ -165,7 +158,7 @@ class Everleaf(HandHistoryConverter):
if __name__ == "__main__": if __name__ == "__main__":
c = Configuration.Config() c = Configuration.Config()
e = Everleaf(c, "regression-test-files/everleaf/Speed_Kuala.txt") e = Everleaf(c, "Speed_Kuala.txt")
e.processFile() e.processFile()
print str(e) print str(e)

View File

@ -104,7 +104,7 @@ class HandHistoryConverter:
def readAction(self, hand, street): abstract def readAction(self, hand, street): abstract
def sanityCheck(self): def sanityCheck(self):
sane = False sane = True
base_w = False base_w = False
#Check if hhbase exists and is writable #Check if hhbase exists and is writable
#Note: Will not try to create the base HH directory #Note: Will not try to create the base HH directory
@ -175,7 +175,7 @@ class HandHistoryConverter:
print "XXXXXXXXX FIXME XXXXXXXX" print "XXXXXXXXX FIXME XXXXXXXX"
print "*** HOLE CARDS ***" print "*** HOLE CARDS ***"
print "Dealt to %s [%s]" %(hand.hero ,hand.holecards) print "Dealt to %s [%s %s]" %(hand.hero , hand.holecards[0], hand.holecards[1])
# #
## ACTION STUFF ## ACTION STUFF
# This is no limit only at the moment # This is no limit only at the moment
@ -184,17 +184,17 @@ class HandHistoryConverter:
self.printActionLine(act, 0) self.printActionLine(act, 0)
if 'FLOP' in hand.actions: if 'FLOP' in hand.actions:
print "*** FLOP *** [%s]" %("XXXXX Flop cards XXXXXX") print "*** FLOP *** [%s %s %s]" %(hand.streets.group("FLOP1"), hand.streets.group("FLOP2"), hand.streets.group("FLOP3"))
for act in hand.actions['FLOP']: for act in hand.actions['FLOP']:
self.printActionLine(act, 0) self.printActionLine(act, 0)
if 'TURN' in hand.actions: if 'TURN' in hand.actions:
print "*** TURN *** [%s] [%s]" %("XXXXX Flop cards XXXXXX", "XXXXX Turn Card XXXXX") print "*** TURN *** [%s %s %s] [%s]" %(hand.streets.group("FLOP1"), hand.streets.group("FLOP2"), hand.streets.group("FLOP3"), hand.streets.group("TURN1"))
for act in hand.actions['TURN']: for act in hand.actions['TURN']:
self.printActionLine(act, 0) self.printActionLine(act, 0)
if 'RIVER' in hand.actions: if 'RIVER' in hand.actions:
print "*** RIVER *** [%s %s] [%s]" %("XXXXX Flop cards XXXXXX", "XXXXX Turn Card XXXXX", "XXXXX River Card XXXXX") print "*** RIVER *** [%s %s %s %s] [%s]" %(hand.streets.group("FLOP1"), hand.streets.group("FLOP2"), hand.streets.group("FLOP3"), hand.streets.group("TURN1"), hand.streets.group("RIVER1"))
for act in hand.actions['RIVER']: for act in hand.actions['RIVER']:
self.printActionLine(act, 0) self.printActionLine(act, 0)
@ -232,45 +232,59 @@ class HandHistoryConverter:
class Hand: class Hand:
# def __init__(self, sitename, gametype, sb, bb, string): # def __init__(self, sitename, gametype, sb, bb, string):
def __init__(self, sitename, gametype, string):
self.sitename = sitename
self.gametype = gametype
self.string = string
self.streets = None # A MatchObject using a groupnames to identify streets. ups = {'a':'A', 't':'T', 'j':'J', 'q':'Q', 'k':'K'}
self.actions = {}
self.handid = 0 def __init__(self, sitename, gametype, string):
self.sb = gametype[3] self.sitename = sitename
self.bb = gametype[4] self.gametype = gametype
self.tablename = "Slartibartfast" self.string = string
self.maxseats = 10
self.counted_seats = 0 self.streets = None # A MatchObject using a groupnames to identify streets.
self.buttonpos = 0 self.actions = {}
self.seating = []
self.players = [] self.handid = 0
self.posted = [] self.sb = gametype[3]
self.involved = True self.bb = gametype[4]
self.hero = "Hiro" self.tablename = "Slartibartfast"
self.holecards = "Xx Xx" self.maxseats = 10
self.action = [] self.counted_seats = 0
self.totalpot = 0 self.buttonpos = 0
self.rake = 0 self.seating = []
self.players = []
self.posted = []
self.involved = True
self.hero = "Hiro"
self.holecards = "Xx Xx"
self.action = []
self.totalpot = 0
self.rake = 0
def printHand(self): def addHoleCards(self,h1,h2,seat=None): # generalise to add hole cards for a specific seat or player
print self.sitename self.holecards = [self.card(h1), self.card(h2)]
print self.gametype
print self.string
print self.handid def card(self,c):
print self.sb """upper case the ranks but not suits, 'atjqk' => 'ATJQK'"""
print self.bb # don't know how to make this 'static'
print self.tablename for k,v in self.ups.items():
print self.maxseats c = c.replace(k,v)
print self.counted_seats return c
print self.buttonpos
print self.seating def printHand(self):
print self.players print self.sitename
print self.posted print self.gametype
print self.action print self.string
print self.involved print self.handid
print self.hero print self.sb
print self.bb
print self.tablename
print self.maxseats
print self.counted_seats
print self.buttonpos
print self.seating
print self.players
print self.posted
print self.action
print self.involved
print self.hero