Merge branch 'master' into siteneutral

Conflicts:

	pyfpdb/fpdb_import.py
	pyfpdb/fpdb_save_to_db.py
	pyfpdb/fpdb_simple.py
This commit is contained in:
Worros 2009-03-24 21:46:18 +09:00
commit c673897fa3
9 changed files with 92 additions and 104 deletions

View File

@ -599,37 +599,6 @@ class FpdbSQLQueries:
################################ ################################
# Returns all cash game handIds and the money won(winnings is the final pot)
# by the playerId for a single site.
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getRingWinningsAllGamesPlayerIdSite'] = """SELECT handId, winnings FROM HandsPlayers
INNER JOIN Players ON HandsPlayers.playerId = Players.id
INNER JOIN Hands ON Hands.id = HandsPlayers.handId
WHERE Players.name = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)
ORDER BY handStart"""
elif(self.dbname == 'SQLite'):
#Probably doesn't work.
self.query['getRingWinningsAllGamesPlayerIdSite'] = """SELECT handId, winnings FROM HandsPlayers
INNER JOIN Players ON HandsPlayers.playerId = Players.id
INNER JOIN Hands ON Hands.id = HandsPlayers.handId
WHERE Players.name = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)
ORDER BY handStart"""
# Returns the profit for a given ring game handId, Total pot - money invested by playerId
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getRingProfitFromHandId'] = """SELECT SUM(amount) FROM HandsActions
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
INNER JOIN Players ON HandsPlayers.playerId = Players.id
WHERE Players.name = %s AND HandsPlayers.handId = %s
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
elif(self.dbname == 'SQLite'):
#Probably doesn't work.
self.query['getRingProfitFromHandId'] = """SELECT SUM(amount) FROM HandsActions
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
INNER JOIN Players ON HandsPlayers.playerId = Players.id
WHERE Players.name = %s AND HandsPlayers.handId = %s
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'): if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getPlayerId'] = """SELECT id from Players where name = %s""" self.query['getPlayerId'] = """SELECT id from Players where name = %s"""
elif(self.dbname == 'SQLite'): elif(self.dbname == 'SQLite'):

View File

@ -124,8 +124,8 @@ follow : whether to tail -f the input"""
hand.starttime = time.strptime(m.group('DATETIME'), "%H:%M:%S ET - %Y/%m/%d") hand.starttime = time.strptime(m.group('DATETIME'), "%H:%M:%S ET - %Y/%m/%d")
hand.maxseats = 8 # assume 8-max until we see otherwise hand.maxseats = 8 # assume 8-max until we see otherwise
if m.group('TABLEATTRIBUTES'): if m.group('TABLEATTRIBUTES'):
m2 = re.search("(\d+) max", m.group('TABLEATTRIBUTES')) m2 = re.search("(deep )?(\d+)( max)?", m.group('TABLEATTRIBUTES'))
hand.maxseats = int(m2.group(1)) hand.maxseats = int(m2.group(2))
# These work, but the info is already in the Hand class - should be used for tourneys though. # These work, but the info is already in the Hand class - should be used for tourneys though.
# m.group('SB') # m.group('SB')
# m.group('BB') # m.group('BB')

View File

@ -176,7 +176,10 @@ class GuiBulkImport():
# ComboBox - filter # ComboBox - filter
self.cbfilter = gtk.combo_box_new_text() self.cbfilter = gtk.combo_box_new_text()
self.cbfilter.append_text("passthrough") self.cbfilter.append_text("passthrough")
self.cbfilter.append_text("Everleaf") self.cbfilter.append_text("BetfairToFpdb")
self.cbfilter.append_text("EverleafToFpdb")
self.cbfilter.append_text("FulltiltToFpdb")
self.cbfilter.append_text("PokerStarsToFpdb")
self.cbfilter.set_active(0) self.cbfilter.set_active(0)
self.table.attach(self.cbfilter, 3, 4, 2, 3, xpadding = 10, ypadding = 0, yoptions=gtk.SHRINK) self.table.attach(self.cbfilter, 3, 4, 2, 3, xpadding = 10, ypadding = 0, yoptions=gtk.SHRINK)
self.cbfilter.show() self.cbfilter.show()
@ -194,8 +197,8 @@ 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
tcursor = db.db.cursor() tcursor = self.importer.fdb.db.cursor()
tcursor.execute("Select count(1) from Hands;") tcursor.execute("Select count(1) from Hands")
row = tcursor.fetchone() row = tcursor.fetchone()
tcursor.close() tcursor.close()
self.n_hands_in_db = row[0] self.n_hands_in_db = row[0]
@ -207,11 +210,9 @@ class GuiBulkImport():
def main(argv=None): def main(argv=None):
"""main can also be called in the python interpreter, by supplying the command line as the argument. """main can also be called in the python interpreter, by supplying the command line as the argument.
>>>import GuiBulkImport >>>import GuiBulkImport
>>>GuiBulkImport.main("-f ~/data/hands")""" >>>GuiBulkImport.main(['-f'.'~/data/hands'])"""
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]
else:
argv = argv.split(" ")
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()
@ -230,8 +231,8 @@ def main(argv=None):
(options, sys.argv) = parser.parse_args(args = argv) (options, sys.argv) = parser.parse_args(args = argv)
config = Configuration.Config() config = Configuration.Config()
db = fpdb_db.fpdb_db() db = None
settings = {} settings = {}
settings['minPrint'] = options.minPrint settings['minPrint'] = options.minPrint
if os.name == 'nt': settings['os'] = 'windows' if os.name == 'nt': settings['os'] = 'windows'

View File

@ -82,7 +82,7 @@ class Hud:
font = "Sans" font = "Sans"
if font_size == None: if font_size == None:
font_size = "8" font_size = "8"
self.font = pango.FontDescription(font + " " + font_size) self.font = pango.FontDescription("%s %s" % (font, font_size))
# do we need to add some sort of condition here for dealing with a request for a font that doesn't exist? # do we need to add some sort of condition here for dealing with a request for a font that doesn't exist?
game_params = config.get_game_parameters(self.poker_game) game_params = config.get_game_parameters(self.poker_game)
@ -102,6 +102,7 @@ class Hud:
self.main_window.set_title("%s FPDBHUD" % (self.table.name)) self.main_window.set_title("%s FPDBHUD" % (self.table.name))
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"])
self.main_window.set_focus_on_map(False)
self.ebox = gtk.EventBox() self.ebox = gtk.EventBox()
self.label = gtk.Label("FPDB Menu (Right Click)\nLeft-drag to move") self.label = gtk.Label("FPDB Menu (Right Click)\nLeft-drag to move")
@ -173,10 +174,11 @@ class Hud:
self.main_window.move(x, y) self.main_window.move(x, y)
adj = self.adj_seats(self.hand, self.config) adj = self.adj_seats(self.hand, self.config)
loc = self.config.get_locations(self.table.site, self.max) loc = self.config.get_locations(self.table.site, self.max)
for i in xrange(1, self.max + 1): for i, w in enumerate(self.stat_windows):
(x, y) = loc[adj[i]] if not type(w) == int: # how do we get pure ints in this list??
if i in self.stat_windows: (x, y) = loc[adj[i]]
self.stat_windows[i].relocate(x, y) w.relocate(x, y)
return True return True
def on_button_press(self, widget, event): def on_button_press(self, widget, event):
@ -196,12 +198,12 @@ class Hud:
s.window.destroy() s.window.destroy()
self.stat_windows = {} self.stat_windows = {}
# also kill any aux windows # also kill any aux windows
[aux.destroy() for aux in self.aux_windows] (aux.destroy() for aux in self.aux_windows)
self.aux_windows = [] self.aux_windows = []
def reposition_windows(self, *args): def reposition_windows(self, *args):
if self.stat_windows != {} and len(self.stat_windows) > 0: if self.stat_windows != {} and len(self.stat_windows) > 0:
map(lambda x: x.window.move(x.x, x.y), self.stat_windows.itervalues()) (x.window.move(x.x, x.y) for x in self.stat_windows.itervalues() if type(x) != int)
return True return True
def debug_stat_windows(self, *args): def debug_stat_windows(self, *args):
@ -217,7 +219,7 @@ class Hud:
new_layout[self.stat_windows[sw].adj - 1] = new_loc new_layout[self.stat_windows[sw].adj - 1] = new_loc
self.config.edit_layout(self.table.site, self.max, locations = new_layout) self.config.edit_layout(self.table.site, self.max, locations = new_layout)
# ask each aux to save its layout back to the config object # ask each aux to save its layout back to the config object
[aux.save_layout() for aux in self.aux_windows] (aux.save_layout() for aux in self.aux_windows)
# save the config object back to the file # save the config object back to the file
print "saving new xml file" print "saving new xml file"
self.config.save() self.config.save()
@ -227,9 +229,9 @@ class Hud:
# Need range here, not xrange -> need the actual list # Need range here, not xrange -> need the actual list
adj = range(0, self.max + 1) # default seat adjustments = no adjustment adj = range(0, self.max + 1) # default seat adjustments = no adjustment
# does the user have a fav_seat? # does the user have a fav_seat?
try: if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0:
sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat)) try:
if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0: sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat))
fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
sys.stderr.write("found fav seat = %d\n" % fav_seat) sys.stderr.write("found fav seat = %d\n" % fav_seat)
# actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name) # actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
@ -237,12 +239,14 @@ class Hud:
sys.stderr.write("found actual seat = %d\n" % actual_seat) sys.stderr.write("found actual seat = %d\n" % actual_seat)
for i in xrange(0, self.max + 1): for i in xrange(0, self.max + 1):
j = actual_seat + i j = actual_seat + i
if j > self.max: j = j - self.max if j > self.max:
j = j - self.max
adj[j] = fav_seat + i adj[j] = fav_seat + i
if adj[j] > self.max: adj[j] = adj[j] - self.max if adj[j] > self.max:
except Exception, inst: adj[j] = adj[j] - self.max
sys.stderr.write("exception in adj!!!\n\n") except Exception, inst:
sys.stderr.write("error is %s" % inst) # __str__ allows args to printed directly sys.stderr.write("exception in adj!!!\n\n")
sys.stderr.write("error is %s" % inst) # __str__ allows args to printed directly
return adj return adj
def get_actual_seat(self, name): def get_actual_seat(self, name):
@ -286,10 +290,12 @@ class Hud:
font = self.font) font = self.font)
self.stats = [] self.stats = []
for i in xrange(0, config.supported_games[self.poker_game].rows + 1): game = config.supported_games[self.poker_game]
row_list = [''] * config.supported_games[self.poker_game].cols
for i in xrange(0, game.rows + 1):
row_list = [''] * game.cols
self.stats.append(row_list) self.stats.append(row_list)
for stat in config.supported_games[self.poker_game].stats: for stat in game.stats:
self.stats[config.supported_games[self.poker_game].stats[stat].row] \ self.stats[config.supported_games[self.poker_game].stats[stat].row] \
[config.supported_games[self.poker_game].stats[stat].col] = \ [config.supported_games[self.poker_game].stats[stat].col] = \
config.supported_games[self.poker_game].stats[stat].stat_name config.supported_games[self.poker_game].stats[stat].stat_name
@ -303,30 +309,30 @@ class Hud:
self.update_table_position() self.update_table_position()
for s in self.stat_dict: for s in self.stat_dict:
statd = self.stat_dict[s]
try: try:
self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id'] self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id']
except: # omg, we have more seats than stat windows .. damn poker sites with incorrect max seating info .. let's force 10 here except: # omg, we have more seats than stat windows .. damn poker sites with incorrect max seating info .. let's force 10 here
self.max = 10 self.max = 10
self.create(hand, config, self.stat_dict, self.cards) self.create(hand, config, self.stat_dict, self.cards)
self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id'] self.stat_windows[statd['seat']].player_id = statd['player_id']
for r in xrange(0, config.supported_games[self.poker_game].rows): for r in xrange(0, config.supported_games[self.poker_game].rows):
for c in xrange(0, config.supported_games[self.poker_game].cols): for c in xrange(0, config.supported_games[self.poker_game].cols):
this_stat = config.supported_games[self.poker_game].stats[self.stats[r][c]] this_stat = config.supported_games[self.poker_game].stats[self.stats[r][c]]
number = Stats.do_stat(self.stat_dict, player = self.stat_dict[s]['player_id'], stat = self.stats[r][c]) number = Stats.do_stat(self.stat_dict, player = statd['player_id'], stat = self.stats[r][c])
statstring = this_stat.hudprefix + str(number[1]) + this_stat.hudsuffix statstring = "%s%s%s" % (this_stat.hudprefix, str(number[1]), this_stat.hudsuffix)
window = self.stat_windows[statd['seat']]
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[self.stat_dict[s]['seat']].label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(this_stat.hudcolor)) window.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) window.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?
self.stat_windows[self.stat_dict[s]['seat']].window.show_all() window.window.show_all()
# self.reposition_windows() tip = "%s\n%s\n%s, %s" % (statd['screen_name'], number[5], number[3], number[4])
tip = self.stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \ Stats.do_tip(window.e_box[r][c], tip)
number[3] + ", " + number[4]
Stats.do_tip(self.stat_windows[self.stat_dict[s]['seat']].e_box[r][c], tip)
def topify_window(self, window): def topify_window(self, window):
"""Set the specified gtk window to stayontop in MS Windows.""" """Set the specified gtk window to stayontop in MS Windows."""
@ -407,8 +413,9 @@ class Stat_Window:
self.window.set_title("%s" % seat) self.window.set_title("%s" % seat)
self.window.set_property("skip-taskbar-hint", True) self.window.set_property("skip-taskbar-hint", True)
self.window.set_transient_for(parent.main_window) self.window.set_transient_for(parent.main_window)
self.window.set_focus_on_map(False)
self.grid = gtk.Table(rows = self.game.rows, columns = self.game.cols, homogeneous = False) self.grid = gtk.Table(rows = game.rows, columns = game.cols, homogeneous = False)
self.window.add(self.grid) self.window.add(self.grid)
self.window.modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) self.window.modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
@ -418,12 +425,12 @@ class Stat_Window:
usegtkframes = self.useframes usegtkframes = self.useframes
e_box = self.e_box e_box = self.e_box
label = self.label label = self.label
for r in xrange(self.game.rows): for r in xrange(game.rows):
if usegtkframes: if usegtkframes:
self.frame.append([]) self.frame.append([])
e_box.append([]) e_box.append([])
label.append([]) label.append([])
for c in xrange(self.game.cols): for c in xrange(game.cols):
if usegtkframes: if usegtkframes:
self.frame[r].append( gtk.Frame() ) self.frame[r].append( gtk.Frame() )
e_box[r].append( gtk.EventBox() ) e_box[r].append( gtk.EventBox() )

View File

@ -54,7 +54,10 @@ class Aux_Window:
pass pass
def destroy(self): def destroy(self):
self.container.destroy() try:
self.container.destroy()
except:
pass
############################################################################ ############################################################################
# Some utility routines useful for Aux_Windows # Some utility routines useful for Aux_Windows
@ -342,11 +345,12 @@ class Flop_Mucked(Aux_Window):
self.m_windows[i].set_focus_on_map(False) self.m_windows[i].set_focus_on_map(False)
self.eb[i] = gtk.EventBox() self.eb[i] = gtk.EventBox()
self.eb[i].connect("button_press_event", self.button_press_cb) self.eb[i].connect("button_press_event", self.button_press_cb)
self.m_windows[i].connect("configure_event", self.configure_event_cb, i)
self.m_windows[i].add(self.eb[i]) self.m_windows[i].add(self.eb[i])
self.seen_cards[i] = gtk.image_new_from_pixbuf(self.card_images[('B', 'H')]) self.seen_cards[i] = gtk.image_new_from_pixbuf(self.card_images[('B', 'H')])
self.eb[i].add(self.seen_cards[i]) self.eb[i].add(self.seen_cards[i])
self.m_windows[i].move(int(x) + self.hud.table.x, int(y) + self.hud.table.y)
self.positions[i] = (int(x) + self.hud.table.x, int(y) + self.hud.table.y) self.positions[i] = (int(x) + self.hud.table.x, int(y) + self.hud.table.y)
self.m_windows[i].move(self.positions[i][0], self.positions[i][1])
self.m_windows[i].set_opacity(float(self.params['opacity'])) self.m_windows[i].set_opacity(float(self.params['opacity']))
self.m_windows[i].show_all() self.m_windows[i].show_all()
self.m_windows[i].hide() self.m_windows[i].hide()
@ -372,7 +376,7 @@ class Flop_Mucked(Aux_Window):
self.seen_cards[i].set_from_pixbuf(scratch) self.seen_cards[i].set_from_pixbuf(scratch)
# self.m_windows[i].show_all() # self.m_windows[i].show_all()
self.m_windows[i].resize(1,1) self.m_windows[i].resize(1,1)
self.m_windows[i].present() self.m_windows[i].show()
self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back
self.displayed_cards = True self.displayed_cards = True
@ -402,9 +406,8 @@ class Flop_Mucked(Aux_Window):
def hide_mucked_cards(self): def hide_mucked_cards(self):
"""Hide the mucked card windows.""" """Hide the mucked card windows."""
for (i, w) in self.m_windows.iteritems(): for (i, w) in self.m_windows.iteritems():
self.positions[i] = w.get_position()
w.hide() w.hide()
self.displayed_cards = False self.displayed_cards = False
def button_press_cb(self, widget, event, *args): def button_press_cb(self, widget, event, *args):
"""Handle button clicks in the event boxes.""" """Handle button clicks in the event boxes."""
@ -413,6 +416,7 @@ class Flop_Mucked(Aux_Window):
if event.state & gtk.gdk.SHIFT_MASK: if event.state & gtk.gdk.SHIFT_MASK:
self.timer_on = False self.timer_on = False
self.expose_all() self.expose_all()
return
if event.button == 3: # right button event if event.button == 3: # right button event
pass pass
@ -428,9 +432,12 @@ class Flop_Mucked(Aux_Window):
window = widget.get_parent() window = widget.get_parent()
window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time) window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
def configure_event_cb(self, widget, event, i, *args):
self.positions[i] = widget.get_position()
def expose_all(self): def expose_all(self):
for (i, cards) in self.hud.cards.iteritems(): for (i, cards) in self.hud.cards.iteritems():
self.m_windows[i].present() self.m_windows[i].show()
self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back
self.displayed_cards = True self.displayed_cards = True
@ -443,8 +450,6 @@ class Flop_Mucked(Aux_Window):
new_locs[self.adj[int(i)]] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) new_locs[self.adj[int(i)]] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y)
else: else:
new_locs[i] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) new_locs[i] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y)
print "old locations =", self.params['layout'][self.hud.max]
print "saving locations =", new_locs
self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs) self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs)
if __name__== "__main__": if __name__== "__main__":

View File

@ -337,7 +337,7 @@ class fpdb:
new_ps_thread=GuiPositionalStats.GuiPositionalStats(self.db, self.config, self.querydict) new_ps_thread=GuiPositionalStats.GuiPositionalStats(self.db, self.config, self.querydict)
self.threads.append(new_ps_thread) self.threads.append(new_ps_thread)
ps_tab=new_ps_thread.get_vbox() ps_tab=new_ps_thread.get_vbox()
self.add_and_display_tab(ps_tab, "Ppositional Stats") self.add_and_display_tab(ps_tab, "Positional Stats")
def tab_main_help(self, widget, data): def tab_main_help(self, widget, data):

View File

@ -191,7 +191,6 @@ class Importer:
tmpcursor = self.fdb.db.cursor() tmpcursor = self.fdb.db.cursor()
tmpcursor.execute("Select count(1) from Hands;") tmpcursor.execute("Select count(1) from Hands;")
self.settings['handsInDB'] = tmpcursor.fetchone()[0] self.settings['handsInDB'] = tmpcursor.fetchone()[0]
tmpcursor.close()
except: except:
pass # if this fails we're probably doomed anyway pass # if this fails we're probably doomed anyway
if self.settings['handsInDB'] < 5000: return "drop" if self.settings['handsInDB'] < 5000: return "drop"
@ -336,7 +335,7 @@ class Importer:
else: else:
isTourney=fpdb_simple.isTourney(hand[0]) isTourney=fpdb_simple.isTourney(hand[0])
if not isTourney: if not isTourney:
fpdb_simple.filterAnteBlindFold(hand) hand = fpdb_simple.filterAnteBlindFold(hand)
self.hand=hand self.hand=hand
try: try:

View File

@ -28,7 +28,7 @@ SQLITE = 4
fastStoreHudCache = True # set this to True to test the new storeHudCache routine fastStoreHudCache = True # set this to True to test the new storeHudCache routine
saveActions = True # set this to False to avoid storing action data saveActions = True # set this to False to avoid storing action data
# Pros: speeds up imports # Pros: speeds up imports
# Cons: no action data is saved, so you need to keep the hand histories # Cons: no action data is saved, so you need to keep the hand histories
# variance not available on stats page # variance not available on stats page
@ -70,9 +70,10 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no,
import_options = config.get_import_parameters() import_options = config.get_import_parameters()
saveActions = False if import_options['saveActions'] == 'False' else True saveActions = False if import_options['saveActions'] == 'False' else True
fastStoreHudCache = True if import_options['fastStoreHudCache'] == 'True' else False fastStoreHudCache = False if import_options['fastStoreHudCache'] == 'False' else True
#print "DEBUG: saveActions: %s fastStoreHudCache: %s" %(saveActions, fastStoreHudCache) # print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache)
# print "DEBUG: import_options = ", import_options
t0 = time() t0 = time()
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)

View File

@ -29,6 +29,7 @@ MYSQL_INNODB = 2
PGSQL = 3 PGSQL = 3
SQLITE = 4 SQLITE = 4
# Data Structures for index and foreign key creation # Data Structures for index and foreign key creation
# drop_code is an int with possible values: 0 - don't drop for bulk import # drop_code is an int with possible values: 0 - don't drop for bulk import
# 1 - drop during bulk import # 1 - drop during bulk import
@ -51,7 +52,7 @@ indexes = [
, [ # indexes for postgres (list index 3) , [ # indexes for postgres (list index 3)
{'tab':'Boardcards', 'col':'handId', 'drop':0} {'tab':'Boardcards', 'col':'handId', 'drop':0}
, {'tab':'Gametypes', 'col':'siteId', 'drop':0} , {'tab':'Gametypes', 'col':'siteId', 'drop':0}
, {'tab':'Hands', 'col':'gametypeId', 'drop':1} , {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0} , {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
, {'tab':'HandsActions', 'col':'handplayerId', 'drop':0} , {'tab':'HandsActions', 'col':'handplayerId', 'drop':0}
, {'tab':'HandsPlayers', 'col':'handId', 'drop':1} , {'tab':'HandsPlayers', 'col':'handId', 'drop':1}
@ -160,12 +161,13 @@ def prepareBulkImport(fdb):
pass pass
elif fdb.backend == PGSQL: elif fdb.backend == PGSQL:
# DON'T FORGET TO RECREATE THEM!! # DON'T FORGET TO RECREATE THEM!!
print "dropping pg fk", fk['fktab'], fk['fkcol'] #print "dropping pg fk", fk['fktab'], fk['fkcol']
try: try:
fdb.cursor.execute("alter table " + fk['fktab'] + " drop constraint " #print "alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol'])
+ fk['fktab'] + '_' + fk['fkcol'] + '_fkey') fdb.cursor.execute("alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol']))
print "dropped pg fk pg fk %s_%s_fkey" % (fk['fktab'], fk['fkcol'])
except: except:
pass print "! failed drop pg fk %s_%s_fkey" % (fk['fktab'], fk['fkcol'])
else: else:
print "Only MySQL and Postgres supported so far" print "Only MySQL and Postgres supported so far"
return -1 return -1
@ -180,15 +182,15 @@ def prepareBulkImport(fdb):
pass pass
elif fdb.backend == PGSQL: elif fdb.backend == PGSQL:
# DON'T FORGET TO RECREATE THEM!! # DON'T FORGET TO RECREATE THEM!!
print "Index dropping disabled for postgresql." #print "Index dropping disabled for postgresql."
print "dropping pg index ", idx['tab'], idx['col'] #print "dropping pg index ", idx['tab'], idx['col']
# mod to use tab_col for index name? # mod to use tab_col for index name?
try: try:
print "drop index %s_%s_idx" % (idx['tab'],idx['col'])
fdb.cursor.execute( "drop index %s_%s_idx" % (idx['tab'],idx['col']) ) fdb.cursor.execute( "drop index %s_%s_idx" % (idx['tab'],idx['col']) )
print "dropped pg index ", idx['tab'], idx['col'] print "drop index %s_%s_idx" % (idx['tab'],idx['col'])
#print "dropped pg index ", idx['tab'], idx['col']
except: except:
pass print "! failed drop index %s_%s_idx" % (idx['tab'],idx['col'])
else: else:
print "Only MySQL and Postgres supported so far" print "Only MySQL and Postgres supported so far"
return -1 return -1
@ -510,7 +512,8 @@ def convertCardValues(arr):
map(convertCardValuesBoard, arr) map(convertCardValuesBoard, arr)
#end def convertCardValues #end def convertCardValues
card_map = { "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, "9" : 9, "T" : 10, "J" : 11, "Q" : 12, "K" : 13, "A" : 14} # a 0-card is one in a stud game that we did not see or was not shown
card_map = { "0": 0, "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, "9" : 9, "T" : 10, "J" : 11, "Q" : 12, "K" : 13, "A" : 14}
#converts the strings in the given array to ints (changes the passed array, no returning). see table design for conversion details #converts the strings in the given array to ints (changes the passed array, no returning). see table design for conversion details
def convertCardValuesBoard(arr): def convertCardValuesBoard(arr):
@ -608,7 +611,7 @@ def filterAnteBlindFold(hand):
if foldeeName in line: if foldeeName in line:
hand[i] = None hand[i] = None
hand = [line for line in hand if line] return [line for line in hand if line]
#end def filterAnteFold #end def filterAnteFold
def stripEOLspaces(str): def stripEOLspaces(str):
@ -651,7 +654,7 @@ def filterCrap(hand, isTourney):
elif (hand[i].endswith("is connected")): elif (hand[i].endswith("is connected")):
hand[i] = False hand[i] = False
elif (hand[i].endswith("is disconnected")): elif (hand[i].endswith("is disconnected")):
toRemove.append(hand[i]) hand[i] = False
elif (hand[i].find(" is low with [")!=-1): elif (hand[i].find(" is low with [")!=-1):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" mucks")): elif (hand[i].endswith(" mucks")):
@ -694,7 +697,7 @@ def filterCrap(hand, isTourney):
elif (hand[i].find(" said, \"")!=-1): elif (hand[i].find(" said, \"")!=-1):
hand[i] = False hand[i] = False
if isTourney: if isTourney and not hand[i] == False:
if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))): if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))):
hand[i] = False hand[i] = False
elif (hand[i].endswith(": sits out")): elif (hand[i].endswith(": sits out")):
@ -1408,11 +1411,14 @@ def storeActions(cursor, handsPlayersIds, actionTypes, allIns, actionAmounts, ac
#stores into table hands_actions #stores into table hands_actions
#print "start of storeActions, actionNos:",actionNos #print "start of storeActions, actionNos:",actionNos
#print " action_amounts:",action_amounts #print " action_amounts:",action_amounts
inserts = []
for i in xrange(len(actionTypes)): #iterate through streets for i in xrange(len(actionTypes)): #iterate through streets
for j in xrange(len(actionTypes[i])): #iterate through names for j in xrange(len(actionTypes[i])): #iterate through names
for k in xrange(len(actionTypes[i][j])): #iterate through individual actions of that player on that street for k in xrange(len(actionTypes[i][j])): #iterate through individual actions of that player on that street
cursor.execute ("INSERT INTO HandsActions (handPlayerId, street, actionNo, action, allIn, amount) VALUES (%s, %s, %s, %s, %s, %s)" # Add inserts into a list and let
, (handsPlayersIds[j], i, actionNos[i][j][k], actionTypes[i][j][k], allIns[i][j][k], actionAmounts[i][j][k])) inserts = inserts + [(handsPlayersIds[j], i, actionNos[i][j][k], actionTypes[i][j][k], allIns[i][j][k], actionAmounts[i][j][k])]
cursor.executemany("INSERT INTO HandsActions (handPlayerId, street, actionNo, action, allIn, amount) VALUES (%s, %s, %s, %s, %s, %s)", inserts)
#end def storeActions #end def storeActions
def store_board_cards(cursor, hands_id, board_values, board_suits): def store_board_cards(cursor, hands_id, board_values, board_suits):