Merge branch 'master' of git://git.assembla.com/fpdboz

Conflicts:

	pyfpdb/Hand.py
This commit is contained in:
Matt Turnbull 2009-03-03 12:24:42 +00:00
commit 703fa40073
9 changed files with 137 additions and 66 deletions

View File

@ -28,8 +28,8 @@ class Everleaf(HandHistoryConverter):
# Static regexes # Static regexes
re_SplitHands = re.compile(r"\n\n+") re_SplitHands = re.compile(r"\n\n+")
re_GameInfo = re.compile(r".*Blinds \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (?P<LTYPE>(NL|PL)) (?P<GAME>(Hold\'em|Omaha|7 Card Stud))") re_GameInfo = re.compile(r"^(Blinds )?\$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) ((?P<LTYPE>NL|PL) )?(?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
re_HandInfo = re.compile(r".*#(?P<HID>[0-9]+)\n.*\nBlinds \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (?P<GAMETYPE>.*) - (?P<DATETIME>\d\d\d\d/\d\d/\d\d - \d\d:\d\d:\d\d)\nTable (?P<TABLE>[- a-zA-Z]+)") re_HandInfo = re.compile(r".*#(?P<HID>[0-9]+)\n.*\n(Blinds )?\$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (?P<GAMETYPE>.*) - (?P<DATETIME>\d\d\d\d/\d\d/\d\d - \d\d:\d\d:\d\d)\nTable (?P<TABLE>[- a-zA-Z]+)")
re_Button = re.compile(r"^Seat (?P<BUTTON>\d+) is the button", re.MULTILINE) re_Button = re.compile(r"^Seat (?P<BUTTON>\d+) is the button", re.MULTILINE)
re_PlayerInfo = re.compile(r"^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\s+(\$ (?P<CASH>[.0-9]+) USD|new player|All-in) \)", re.MULTILINE) re_PlayerInfo = re.compile(r"^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\s+(\$ (?P<CASH>[.0-9]+) USD|new player|All-in) \)", re.MULTILINE)
re_Board = re.compile(r"\[ (?P<CARDS>.+) \]") re_Board = re.compile(r"\[ (?P<CARDS>.+) \]")
@ -62,7 +62,8 @@ class Everleaf(HandHistoryConverter):
def readSupportedGames(self): def readSupportedGames(self):
return [["ring", "hold", "nl"], return [["ring", "hold", "nl"],
["ring", "hold", "pl"], ["ring", "hold", "pl"],
["ring", "omaha", "pl"] ["ring", "hold", "fl"],
["ring", "omahahi", "pl"]
] ]
def determineGameType(self): def determineGameType(self):
@ -221,7 +222,7 @@ class Everleaf(HandHistoryConverter):
if __name__ == "__main__": if __name__ == "__main__":
c = Configuration.Config() c = Configuration.Config()
if len(sys.argv) == 1: if len(sys.argv) == 1:
testfile = "regression-test-files/everleaf/Speed_Kuala_full.txt" testfile = "regression-test-files/everleaf/plo/Naos.txt"
else: else:
testfile = sys.argv[1] testfile = sys.argv[1]
e = Everleaf(c, testfile) e = Everleaf(c, testfile)

1
pyfpdb/Exceptions.py Normal file
View File

@ -0,0 +1 @@
class FpdbParseError(Exception): pass

View File

@ -181,7 +181,7 @@ class FullTilt(HandHistoryConverter):
# "2c, qh" -> set(["2c","qc"]) # "2c, qh" -> set(["2c","qc"])
# Also works with Omaha hands. # Also works with Omaha hands.
cards = m.group('CARDS') cards = m.group('CARDS')
cards = set(cards.split(' ')) cards = cards.split(' ')
hand.addHoleCards(cards, m.group('PNAME')) hand.addHoleCards(cards, m.group('PNAME'))
def readPlayerCards(self, hand, street): def readPlayerCards(self, hand, street):
@ -195,7 +195,7 @@ class FullTilt(HandHistoryConverter):
if player.group('NEWCARD') != None: if player.group('NEWCARD') != None:
print cards print cards
cards = cards + " " + player.group('NEWCARD') cards = cards + " " + player.group('NEWCARD')
cards = set(cards.split(' ')) cards = cards.split(' ')
hand.addPlayerCards(cards, player.group('PNAME')) hand.addPlayerCards(cards, player.group('PNAME'))
def readAction(self, hand, street): def readAction(self, hand, street):
@ -218,7 +218,7 @@ class FullTilt(HandHistoryConverter):
def readShowdownActions(self, hand): def readShowdownActions(self, hand):
for shows in self.re_ShowdownAction.finditer(hand.string): for shows in self.re_ShowdownAction.finditer(hand.string):
cards = shows.group('CARDS') cards = shows.group('CARDS')
cards = set(cards.split(' ')) cards = cards.split(' ')
hand.addShownCards(cards, shows.group('PNAME')) hand.addShownCards(cards, shows.group('PNAME'))
def readCollectPot(self,hand): def readCollectPot(self,hand):
@ -229,7 +229,7 @@ class FullTilt(HandHistoryConverter):
for m in self.re_ShownCards.finditer(hand.string): for m in self.re_ShownCards.finditer(hand.string):
if m.group('CARDS') is not None: if m.group('CARDS') is not None:
cards = m.group('CARDS') cards = m.group('CARDS')
cards = set(cards.split(' ')) cards = cards.split(' ')
hand.addShownCards(cards=cards, player=m.group('PNAME')) hand.addShownCards(cards=cards, player=m.group('PNAME'))

View File

@ -194,16 +194,10 @@ class GuiBulkImport():
self.load_button.show() self.load_button.show()
# see how many hands are in the db and adjust accordingly # see how many hands are in the db and adjust accordingly
db_parms = config.get_db_parameters('fpdb') tcursor = db.db.cursor()
db.connect(db_parms['db-backend'], tcursor.execute("Select max(id) from Hands;")
db_parms['db-host'], row = tcursor.fetchone()
db_parms['db-databaseName'], tcursor.close()
db_parms['db-user'],
db_parms['db-password'])
cursor = db.db.cursor()
cursor.execute("Select max(id) from Hands;")
row = cursor.fetchone()
db.disconnect() # that's all we need this for
self.n_hands_in_db = row[0] self.n_hands_in_db = row[0]
if self.n_hands_in_db == 0: if self.n_hands_in_db == 0:
self.cb.set_active(2) self.cb.set_active(2)

View File

@ -77,6 +77,13 @@ class HUD_main(object):
def destroy(*args): # call back for terminating the main eventloop def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit() gtk.main_quit()
def kill_hud(self, event, table):
# called by an event in the HUD, to kill this specific HUD
self.hud_dict[table].kill()
self.hud_dict[table].main_window.destroy()
self.vb.remove(self.hud_dict[table].tablehudlabel)
del(self.hud_dict[table])
def create_HUD(self, new_hand_id, table, table_name, max, poker_game, is_tournament, stat_dict, cards): def create_HUD(self, new_hand_id, table, table_name, max, poker_game, is_tournament, stat_dict, cards):
def idle_func(): def idle_func():
@ -117,18 +124,6 @@ class HUD_main(object):
gtk.gdk.threads_leave() gtk.gdk.threads_leave()
gobject.idle_add(idle_func) gobject.idle_add(idle_func)
def HUD_removed(self, tablename):
tablename = Tables.clean_title(tablename)
# TODO: There's a potential problem here somewhere, that this hacks around .. the table_name as being passed to HUD_create is cleaned,
# but the table.name as being passed here is not cleaned. I don't know why. -eric
if tablename in self.hud_dict and self.hud_dict[tablename].deleted:
self.vb.remove(self.hud_dict[tablename].tablehudlabel)
del self.hud_dict[tablename]
return False
return True
def read_stdin(self): # This is the thread function def read_stdin(self): # This is the thread function
"""Do all the non-gui heavy lifting for the HUD program.""" """Do all the non-gui heavy lifting for the HUD program."""

View File

@ -33,6 +33,11 @@ class Hand:
self.gametype = gametype self.gametype = gametype
self.string = string self.string = string
if gametype[1] == "hold" or self.gametype[1] == "omahahi":
self.streetList = ['PREFLOP','FLOP','TURN','RIVER'] # a list of the observed street names in order
elif self.gametype[1] == "razz" or self.gametype[1] == "stud" or self.gametype[1] == "stud8":
self.streetList = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] # a list of the observed street names in order
self.handid = 0 self.handid = 0
self.tablename = "Slartibartfast" self.tablename = "Slartibartfast"
@ -130,7 +135,7 @@ player (string) name of player
try: try:
self.checkPlayerExists(player) self.checkPlayerExists(player)
cards = set([self.card(c) for c in cards]) cards = set([self.card(c) for c in cards])
self.holecards[player].extend(cards) self.holecards[player].update(cards)
except FpdbParseError, e: except FpdbParseError, e:
print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) print "[ERROR] Tried to add holecards for unknown player: %s" % (player,)
@ -390,6 +395,24 @@ Map the tuple self.gametype onto the pokerstars string describing it
return string return string
def lookupLimitBetSize(self):
#Lookup table for limit games
betlist = {
"Everleaf" : { "0.10" : ("0.02", "0.05"),
"0.20" : ("0.05", "0.10"),
"0.50" : ("0.10", "0.25"),
"1.00" : ("0.25", "0.50")
},
"FullTilt" : { "0.10" : ("0.02", "0.05"),
"0.20" : ("0.05", "0.10"),
"1" : ("0.25", "0.50"),
"2" : ("0.50", "1"),
"4" : ("1", "2")
}
}
return betlist[self.sitename][self.bb]
def writeHand(self, fh=sys.__stdout__): def writeHand(self, fh=sys.__stdout__):
print >>fh, "Override me" print >>fh, "Override me"
@ -430,13 +453,19 @@ class HoldemOmahaHand(Hand):
#May be more than 1 bb posting #May be more than 1 bb posting
if self.gametype[2] == "fl":
(smallbet, bigbet) = self.lookupLimitBetSize()
else:
smallbet = self.sb
bigbet = self.bb
for a in self.posted: for a in self.posted:
if(a[1] == "small blind"): if(a[1] == "small blind"):
print >>fh, _("%s: posts small blind $%s" %(a[0], self.sb)) print >>fh, _("%s: posts small blind $%s" %(a[0], smallbet))
if(a[1] == "big blind"): if(a[1] == "big blind"):
print >>fh, _("%s: posts big blind $%s" %(a[0], self.bb)) print >>fh, _("%s: posts big blind $%s" %(a[0], bigbet))
if(a[1] == "both"): if(a[1] == "both"):
print >>fh, _("%s: posts small & big blinds $%.2f" %(a[0], (Decimal(self.sb) + Decimal(self.bb)))) print >>fh, _("%s: posts small & big blinds $%.2f" %(a[0], (Decimal(smallbet) + Decimal(bigbet))))
print >>fh, _("*** HOLE CARDS ***") print >>fh, _("*** HOLE CARDS ***")
if self.involved: if self.involved:

View File

@ -139,7 +139,7 @@ class HandHistoryConverter:
self.markStreets(hand) self.markStreets(hand)
# Different calls if stud or holdem like # Different calls if stud or holdem like
if self.gametype[1] == "hold" or self.gametype[1] == "omaha": if self.gametype[1] == "hold" or self.gametype[1] == "omahahi":
self.readBlinds(hand) self.readBlinds(hand)
self.readButton(hand) self.readButton(hand)
self.readHeroCards(hand) # want to generalise to draw games self.readHeroCards(hand) # want to generalise to draw games
@ -153,7 +153,7 @@ class HandHistoryConverter:
for street in hand.streetList: # go through them in order for street in hand.streetList: # go through them in order
print "DEBUG: ", street print "DEBUG: ", street
if hand.streets.group(street) is not None: if hand.streets.group(street) is not None:
if self.gametype[1] == "hold" or self.gametype[1] == "omaha": if self.gametype[1] == "hold" or self.gametype[1] == "omahahi":
self.readCommunityCards(hand, street) # read community cards self.readCommunityCards(hand, street) # read community cards
elif self.gametype[1] == "razz" or self.gametype[1] == "stud" or self.gametype[1] == "stud8": elif self.gametype[1] == "razz" or self.gametype[1] == "stud" or self.gametype[1] == "stud8":
self.readPlayerCards(hand, street) self.readPlayerCards(hand, street)

View File

@ -81,7 +81,7 @@ class Hud:
self.main_window = gtk.Window() self.main_window = gtk.Window()
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC) self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
self.main_window.set_title(self.table.name + " FPDBHUD") self.main_window.set_title(self.table.name + " FPDBHUD")
self.main_window.destroyhandler = self.main_window.connect("destroy", self.kill_hud) # self.main_window.destroyhandler = self.main_window.connect("destroy", self.kill_hud)
self.main_window.set_decorated(False) self.main_window.set_decorated(False)
self.main_window.set_opacity(self.colors["hudopacity"]) self.main_window.set_opacity(self.colors["hudopacity"])
@ -106,7 +106,7 @@ class Hud:
self.menu = gtk.Menu() self.menu = gtk.Menu()
self.item1 = gtk.MenuItem('Kill this HUD') self.item1 = gtk.MenuItem('Kill this HUD')
self.menu.append(self.item1) self.menu.append(self.item1)
self.item1.connect("activate", self.kill_hud_menu) self.item1.connect("activate", self.parent.kill_hud, self.table.name)
self.item1.show() self.item1.show()
self.item2 = gtk.MenuItem('Save Layout') self.item2 = gtk.MenuItem('Save Layout')
@ -142,7 +142,7 @@ class Hud:
def update_table_position(self): def update_table_position(self):
if os.name == 'nt': if os.name == 'nt':
if not win32gui.IsWindow(self.table.number): if not win32gui.IsWindow(self.table.number):
self.kill_hud() self.parent.kill_hud(self, self.table.name)
return False return False
# anyone know how to do this in unix, or better yet, trap the X11 error that is triggered when executing the get_origin() for a closed window? # anyone know how to do this in unix, or better yet, trap the X11 error that is triggered when executing the get_origin() for a closed window?
@ -168,23 +168,18 @@ class Hud:
return True return True
return False return False
def kill_hud(self, *args): def kill(self, *args):
if self.deleted: # kill all stat_windows, popups and aux_windows in this HUD
return # no killing self twice. # heap dead, burnt bodies, blood 'n guts, veins between my teeth
for k in self.stat_windows: for s in self.stat_windows.itervalues():
self.stat_windows[k].window.destroy() for p in s.popups:
s.kill_popup(p)
s.window.destroy()
self.stat_windows = {}
# also kill any aux windows # also kill any aux windows
for m in self.aux_windows: for m in self.aux_windows:
m.destroy() m.destroy()
self.aux_windows.remove(m) self.aux_windows = []
self.deleted = True
self.main_window.disconnect(self.main_window.destroyhandler) # so we don't potentially infiniteloop in here, right
self.main_window.destroy()
self.parent.HUD_removed(self.table.name)
def kill_hud_menu(self, *args):
self.main_window.destroy()
def reposition_windows(self, *args): def reposition_windows(self, *args):
for w in self.stat_windows: for w in self.stat_windows:
@ -285,6 +280,7 @@ class Hud:
def update(self, hand, config): def update(self, hand, config):
self.hand = hand # this is the last hand, so it is available later self.hand = hand # this is the last hand, so it is available later
if os.name == 'nt':
self.update_table_position() self.update_table_position()
for s in self.stat_dict: for s in self.stat_dict:
@ -303,7 +299,7 @@ class Hud:
if this_stat.hudcolor != "": if this_stat.hudcolor != "":
self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor'])) self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor']))
self.stat_windows[stat_dict[s]['seat']].label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(this_stat.hudcolor)) self.stat_windows[self.stat_dict[s]['seat']].label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(this_stat.hudcolor))
self.stat_windows[self.stat_dict[s]['seat']].label[r][c].set_text(statstring) self.stat_windows[self.stat_dict[s]['seat']].label[r][c].set_text(statstring)
if statstring != "xxx": # is there a way to tell if this particular stat window is visible already, or no? if statstring != "xxx": # is there a way to tell if this particular stat window is visible already, or no?
@ -345,7 +341,7 @@ class Stat_Window:
# and double-clicks. # and double-clicks.
if event.button == 3: # right button event if event.button == 3: # right button event
Popup_window(widget, self) self.popups.append(Popup_window(widget, self))
if event.button == 2: # middle button event if event.button == 2: # middle button event
self.window.hide() self.window.hide()
@ -357,6 +353,10 @@ class Stat_Window:
else: else:
self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time) self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
def kill_popup(self, popup):
popup.window.destroy()
self.popups.remove(popup)
def relocate(self, x, y): def relocate(self, x, y):
self.x = x + self.table.x self.x = x + self.table.x
self.y = y + self.table.y self.y = y + self.table.y
@ -372,6 +372,7 @@ class Stat_Window:
self.y = y + table.y # x and y are the location relative to table.x & y self.y = y + table.y # x and y are the location relative to table.x & y
self.player_id = player_id # looks like this isn't used ;) self.player_id = player_id # looks like this isn't used ;)
self.sb_click = 0 # used to figure out button clicks self.sb_click = 0 # used to figure out button clicks
self.popups = [] # list of open popups for this stat window
self.useframes = parent.config.get_frames(parent.site) self.useframes = parent.config.get_frames(parent.site)
self.window = gtk.Window() self.window = gtk.Window()
@ -431,6 +432,7 @@ def destroy(*args): # call back for terminating the main eventloop
class Popup_window: class Popup_window:
def __init__(self, parent, stat_window): def __init__(self, parent, stat_window):
self.sb_click = 0 self.sb_click = 0
self.stat_window = stat_window
# create the popup window # create the popup window
self.window = gtk.Window() self.window = gtk.Window()
@ -513,7 +515,8 @@ class Popup_window:
pass pass
if event.button == 3: # right button event if event.button == 3: # right button event
self.window.destroy() self.stat_window.kill_popup(self)
# self.window.destroy()
def toggle_decorated(self, widget): def toggle_decorated(self, widget):
top = widget.get_toplevel() top = widget.get_toplevel()

View File

@ -30,6 +30,7 @@ import fpdb_db
import fpdb_import import fpdb_import
import fpdb_simple import fpdb_simple
import FpdbSQLQueries import FpdbSQLQueries
import EverleafToFpdb
import Tables import Tables
import unittest import unittest
@ -52,6 +53,8 @@ class TestSequenceFunctions(unittest.TestCase):
self.mysqlimporter = fpdb_import.Importer(self, self.mysql_settings, self.c) self.mysqlimporter = fpdb_import.Importer(self, self.mysql_settings, self.c)
self.mysqlimporter.setCallHud(False) self.mysqlimporter.setCallHud(False)
self.everleaf = EverleafToFpdb.Everleaf(self.c, "Nofile")
# """Configure Postgres settings/database and establish connection""" # """Configure Postgres settings/database and establish connection"""
# self.pg_settings={ 'db-host':"localhost", 'db-backend':3, 'db-databaseName':"fpdbtest", 'db-user':"fpdb", 'db-password':"fpdb"} # self.pg_settings={ 'db-host':"localhost", 'db-backend':3, 'db-databaseName':"fpdbtest", 'db-user':"fpdb", 'db-password':"fpdb"}
# self.pg_db = fpdb_db.fpdb_db() # self.pg_db = fpdb_db.fpdb_db()
@ -110,12 +113,57 @@ class TestSequenceFunctions(unittest.TestCase):
self.failUnless(result == "French", "French (deep) parsed incorrectly. Expected 'French' got: " + str(result)) self.failUnless(result == "French", "French (deep) parsed incorrectly. Expected 'French' got: " + str(result))
# result = ("French (deep) - $0.25/$0.50 - No Limit Hold'em - Logged In As xxxx") # result = ("French (deep) - $0.25/$0.50 - No Limit Hold'em - Logged In As xxxx")
def testImportHandHistoryFiles(self): def testEverleafGameInfoRegex(self):
"""Test import of single HH file""" cash_nlhe = """Everleaf Gaming Game #55198191
self.mysqlimporter.addImportFile("regression-test-files/hand-histories/ps-lhe-ring-3hands.txt") ***** Hand history for game #55198191 *****
self.mysqlimporter.runImport() Blinds $0.50/$1 NL Hold'em - 2008/09/01 - 10:02:11
self.mysqlimporter.addImportDirectory("regression-test-files/hand-histories") Table Speed Kuala
self.mysqlimporter.runImport() Seat 8 is the button
Total number of players: 10"""
cash_plo = """Everleaf Gaming Game #65295370
***** Hand history for game #65295370 *****
Blinds $0.50/$1 PL Omaha - 2008/12/07 - 21:59:48
Table Guanajuato
Seat 5 is the button
Total number of players: 6"""
cash_flhe = """Everleaf Gaming Game #55809022
***** Hand history for game #55809022 *****
$1/$2 Hold'em - 2008/09/07 - 08:04:36
Table Jeonju
Seat 4 is the button
Total number of players: 5
"""
#NLHE
m = self.everleaf.re_GameInfo.search(cash_nlhe)
sb = m.group('SB')
bb = m.group('BB')
ltype = m.group('LTYPE')
game = m.group('GAME')
self.failUnless(sb == "0.50", "SB incorrect, expected: 0.50 got: '" + sb + "'")
self.failUnless(bb == "1", "BB incorrect, expected: 1 got: '" + bb + "'")
self.failUnless(ltype == "NL", "LTYPE incorrect, expected: NL got: '" + ltype + "'")
self.failUnless(game == "Hold\'em", "GAME incorrect, expected: Hold\'em got: '" + game + "'")
#FLHE
m = self.everleaf.re_GameInfo.search(cash_flhe)
sb = m.group('SB')
bb = m.group('BB')
ltype = m.group('LTYPE')
game = m.group('GAME')
print m.groups()
self.failUnless(sb == "1", "SB incorrect, expected: 1 got: '" + sb + "'")
self.failUnless(bb == "2", "BB incorrect, expected: 2 got: '" + bb + "'")
self.failUnless(ltype == None, "LTYPE incorrect, expected: NL got: '%s'" %(ltype))
self.failUnless(game == "Hold\'em", "GAME incorrect, expected: Hold\'em got: '" + game + "'")
# def testImportHandHistoryFiles(self):
# """Test import of single HH file"""
# self.mysqlimporter.addImportFile("regression-test-files/hand-histories/ps-lhe-ring-3hands.txt")
# self.mysqlimporter.runImport()
# self.mysqlimporter.addImportDirectory("regression-test-files/hand-histories")
# self.mysqlimporter.runImport()
# def testPostgresSQLRecreateTables(self): # def testPostgresSQLRecreateTables(self):
# """Test droping then recreating fpdb table schema""" # """Test droping then recreating fpdb table schema"""