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
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_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_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.*\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_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>.+) \]")
@ -62,7 +62,8 @@ class Everleaf(HandHistoryConverter):
def readSupportedGames(self):
return [["ring", "hold", "nl"],
["ring", "hold", "pl"],
["ring", "omaha", "pl"]
["ring", "hold", "fl"],
["ring", "omahahi", "pl"]
]
def determineGameType(self):
@ -221,7 +222,7 @@ class Everleaf(HandHistoryConverter):
if __name__ == "__main__":
c = Configuration.Config()
if len(sys.argv) == 1:
testfile = "regression-test-files/everleaf/Speed_Kuala_full.txt"
testfile = "regression-test-files/everleaf/plo/Naos.txt"
else:
testfile = sys.argv[1]
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"])
# Also works with Omaha hands.
cards = m.group('CARDS')
cards = set(cards.split(' '))
cards = cards.split(' ')
hand.addHoleCards(cards, m.group('PNAME'))
def readPlayerCards(self, hand, street):
@ -195,7 +195,7 @@ class FullTilt(HandHistoryConverter):
if player.group('NEWCARD') != None:
print cards
cards = cards + " " + player.group('NEWCARD')
cards = set(cards.split(' '))
cards = cards.split(' ')
hand.addPlayerCards(cards, player.group('PNAME'))
def readAction(self, hand, street):
@ -218,7 +218,7 @@ class FullTilt(HandHistoryConverter):
def readShowdownActions(self, hand):
for shows in self.re_ShowdownAction.finditer(hand.string):
cards = shows.group('CARDS')
cards = set(cards.split(' '))
cards = cards.split(' ')
hand.addShownCards(cards, shows.group('PNAME'))
def readCollectPot(self,hand):
@ -229,7 +229,7 @@ class FullTilt(HandHistoryConverter):
for m in self.re_ShownCards.finditer(hand.string):
if m.group('CARDS') is not None:
cards = m.group('CARDS')
cards = set(cards.split(' '))
cards = cards.split(' ')
hand.addShownCards(cards=cards, player=m.group('PNAME'))

View File

@ -194,16 +194,10 @@ class GuiBulkImport():
self.load_button.show()
# see how many hands are in the db and adjust accordingly
db_parms = config.get_db_parameters('fpdb')
db.connect(db_parms['db-backend'],
db_parms['db-host'],
db_parms['db-databaseName'],
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
tcursor = db.db.cursor()
tcursor.execute("Select max(id) from Hands;")
row = tcursor.fetchone()
tcursor.close()
self.n_hands_in_db = row[0]
if self.n_hands_in_db == 0:
self.cb.set_active(2)

View File

@ -76,7 +76,14 @@ class HUD_main(object):
def destroy(*args): # call back for terminating the main eventloop
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 idle_func():
@ -117,18 +124,6 @@ class HUD_main(object):
gtk.gdk.threads_leave()
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
"""Do all the non-gui heavy lifting for the HUD program."""

View File

@ -32,7 +32,12 @@ class Hand:
self.sitename = sitename
self.gametype = gametype
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.tablename = "Slartibartfast"
@ -130,7 +135,7 @@ player (string) name of player
try:
self.checkPlayerExists(player)
cards = set([self.card(c) for c in cards])
self.holecards[player].extend(cards)
self.holecards[player].update(cards)
except FpdbParseError, e:
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
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__):
print >>fh, "Override me"
@ -430,13 +453,19 @@ class HoldemOmahaHand(Hand):
#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:
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"):
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"):
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 ***")
if self.involved:

View File

@ -139,7 +139,7 @@ class HandHistoryConverter:
self.markStreets(hand)
# 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.readButton(hand)
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
print "DEBUG: ", street
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
elif self.gametype[1] == "razz" or self.gametype[1] == "stud" or self.gametype[1] == "stud8":
self.readPlayerCards(hand, street)

View File

@ -81,7 +81,7 @@ class Hud:
self.main_window = gtk.Window()
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
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_opacity(self.colors["hudopacity"])
@ -106,7 +106,7 @@ class Hud:
self.menu = gtk.Menu()
self.item1 = gtk.MenuItem('Kill this HUD')
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.item2 = gtk.MenuItem('Save Layout')
@ -142,7 +142,7 @@ class Hud:
def update_table_position(self):
if os.name == 'nt':
if not win32gui.IsWindow(self.table.number):
self.kill_hud()
self.parent.kill_hud(self, self.table.name)
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?
@ -168,23 +168,18 @@ class Hud:
return True
return False
def kill_hud(self, *args):
if self.deleted:
return # no killing self twice.
for k in self.stat_windows:
self.stat_windows[k].window.destroy()
def kill(self, *args):
# kill all stat_windows, popups and aux_windows in this HUD
# heap dead, burnt bodies, blood 'n guts, veins between my teeth
for s in self.stat_windows.itervalues():
for p in s.popups:
s.kill_popup(p)
s.window.destroy()
self.stat_windows = {}
# also kill any aux windows
for m in self.aux_windows:
m.destroy()
self.aux_windows.remove(m)
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()
self.aux_windows = []
def reposition_windows(self, *args):
for w in self.stat_windows:
@ -285,7 +280,8 @@ class Hud:
def update(self, hand, config):
self.hand = hand # this is the last hand, so it is available later
self.update_table_position()
if os.name == 'nt':
self.update_table_position()
for s in self.stat_dict:
try:
@ -303,7 +299,7 @@ class Hud:
if this_stat.hudcolor != "":
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)
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.
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
self.window.hide()
@ -356,7 +352,11 @@ class Stat_Window:
self.window.begin_resize_drag(gtk.gdk.WINDOW_EDGE_SOUTH_EAST, event.button, int(event.x_root), int(event.y_root), event.time)
else:
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):
self.x = x + self.table.x
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.player_id = player_id # looks like this isn't used ;)
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.window = gtk.Window()
@ -431,6 +432,7 @@ def destroy(*args): # call back for terminating the main eventloop
class Popup_window:
def __init__(self, parent, stat_window):
self.sb_click = 0
self.stat_window = stat_window
# create the popup window
self.window = gtk.Window()
@ -513,7 +515,8 @@ class Popup_window:
pass
if event.button == 3: # right button event
self.window.destroy()
self.stat_window.kill_popup(self)
# self.window.destroy()
def toggle_decorated(self, widget):
top = widget.get_toplevel()

View File

@ -30,6 +30,7 @@ import fpdb_db
import fpdb_import
import fpdb_simple
import FpdbSQLQueries
import EverleafToFpdb
import Tables
import unittest
@ -52,6 +53,8 @@ class TestSequenceFunctions(unittest.TestCase):
self.mysqlimporter = fpdb_import.Importer(self, self.mysql_settings, self.c)
self.mysqlimporter.setCallHud(False)
self.everleaf = EverleafToFpdb.Everleaf(self.c, "Nofile")
# """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_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))
# result = ("French (deep) - $0.25/$0.50 - No Limit Hold'em - Logged In As xxxx")
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 testEverleafGameInfoRegex(self):
cash_nlhe = """Everleaf Gaming Game #55198191
***** Hand history for game #55198191 *****
Blinds $0.50/$1 NL Hold'em - 2008/09/01 - 10:02:11
Table Speed Kuala
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):
# """Test droping then recreating fpdb table schema"""