From dd80468f5f969dc1a39be714006612748922628b Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 9 Jun 2009 14:18:56 -0400 Subject: [PATCH 01/30] Fix a whitespace problem. --- pyfpdb/WinTables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/WinTables.py b/pyfpdb/WinTables.py index 1b064eef..87431dda 100644 --- a/pyfpdb/WinTables.py +++ b/pyfpdb/WinTables.py @@ -62,7 +62,7 @@ class Table(Table_Window): return None (x, y, width, height) = win32gui.GetWindowRect(hwnd) - print "x = %s y = %s width = %s height = %s" % (x, y, width, height) + print "x = %s y = %s width = %s height = %s" % (x, y, width, height) self.x = int(x) + b_width self.y = int(y) + tb_height self.height = int(height) - b_width - tb_height From eea4656f4792f90d9b30baad124d1c2a0075e697 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 9 Jun 2009 16:38:26 -0400 Subject: [PATCH 02/30] Should now run on windows--but not work correctly. --- pyfpdb/WinTables.py | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pyfpdb/WinTables.py b/pyfpdb/WinTables.py index 87431dda..b867b83d 100644 --- a/pyfpdb/WinTables.py +++ b/pyfpdb/WinTables.py @@ -72,7 +72,8 @@ class Table(Table_Window): self.title = titles[hwnd] self.site = "" self.hud = None - self.number = gtk.gdk.window_foreign_new(long(self.window)) + self.number = hwnd + self.gdkhandle = gtk.gdk.window_foreign_new(long(self.window)) def get_geometry(self): @@ -112,32 +113,31 @@ class Table(Table_Window): win32api.CloseHandle(hToken) return exename + def topify(self, hud): + """Set the specified gtk window to stayontop in MS Windows.""" + + def windowEnumerationHandler(hwnd, resultList): + '''Callback for win32gui.EnumWindows() to generate list of window handles.''' + resultList.append((hwnd, win32gui.GetWindowText(hwnd))) + + unique_name = 'unique name for finding this window' + real_name = hud.main_window.get_title() + hud.main_window.set_title(unique_name) + tl_windows = [] + win32gui.EnumWindows(windowEnumerationHandler, tl_windows) + + for w in tl_windows: + if w[1] == unique_name: + hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(w[0]) + hud.main_window.gdkhandle.set_transient_for(self.gdkhandle) +# +# style = win32gui.GetWindowLong(self.number, win32con.GWL_EXSTYLE) +# style |= win32con.WS_CLIPCHILDREN +# win32gui.SetWindowLong(self.number, win32con.GWL_EXSTYLE, style) + break + + hud.main_window.set_title(real_name) + def win_enum_handler(hwnd, titles): titles[hwnd] = win32gui.GetWindowText(hwnd) -def topify_window(hud, window): - """Set the specified gtk window to stayontop in MS Windows.""" - - def windowEnumerationHandler(hwnd, resultList): - '''Callback for win32gui.EnumWindows() to generate list of window handles.''' - resultList.append((hwnd, win32gui.GetWindowText(hwnd))) - - unique_name = 'unique name for finding this window' - real_name = window.get_title() - window.set_title(unique_name) - tl_windows = [] - win32gui.EnumWindows(windowEnumerationHandler, tl_windows) - - for w in tl_windows: - if w[1] == unique_name: - hud.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(long(hud.table.number)) - hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(w[0]) - hud.main_window.gdkhandle.set_transient_for(hud.main_window.parentgdkhandle) - - style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE) - style |= win32con.WS_CLIPCHILDREN - win32gui.SetWindowLong(hud.table.number, win32con.GWL_EXSTYLE, style) - break - - window.set_title(real_name) - From 9b5f8c53bcc38b22d21efab1436d9896cfbd2134 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 9 Jun 2009 19:06:20 -0400 Subject: [PATCH 03/30] Changes to allow importing of razz hands. Tables not fully populated. --- pyfpdb/Hand.py | 3 ++- pyfpdb/fpdb_save_to_db.py | 15 +++++++-------- pyfpdb/fpdb_simple.py | 31 +++++++++++++++++++------------ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index c505a68a..38009250 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -878,7 +878,8 @@ Add a complete on [street] by [player] to [amountTo] def writeHand(self, fh=sys.__stdout__): # PokerStars format. - print >>fh, _("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, time.strftime('%Y/%m/%d - %H:%M:%S (ET)', self.starttime))) +# print >>fh, _("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, time.strftime('%Y/%m/%d - %H:%M:%S (ET)', self.starttime))) + print >>fh, _("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))) print >>fh, _("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) players_who_post_antes = set([x[0] for x in self.actions['ANTES']]) diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index 3c99d084..3870a6e9 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -26,14 +26,13 @@ MYSQL_INNODB = 2 PGSQL = 3 SQLITE = 4 -#fastStoreHudCache = False # set this to True to test the new storeHudCache routine -# -#saveActions = True # set this to False to avoid storing action data -# # Pros: speeds up imports -# # Cons: no action data is saved, so you need to keep the hand histories -# # variance not available on stats page -# # no graphs +fastStoreHudCache = False # set this to True to test the new storeHudCache routine +saveActions = True # set this to False to avoid storing action data + # Pros: speeds up imports + # Cons: no action data is saved, so you need to keep the hand histories + # variance not available on stats page + # : No graphs #stores a stud/razz hand into the database def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time ,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes @@ -48,7 +47,7 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id - ,hand_start_time, names, tableName, maxSeats) + ,hand_start_time, names, tableName, maxSeats, hudImportData) #print "before calling store_hands_players_stud, antes:", antes hands_players_ids = fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 31321aeb..2b6f248b 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1318,19 +1318,26 @@ def store_hands_players_stud(backend, conn, cursor, hands_id, player_ids, start_ result=[] #print "before inserts in store_hands_players_stud, antes:", antes for i in xrange(len(player_ids)): + card1 = Card.cardFromValueSuit(card_values[i][0], card_suits[i][0]) + card2 = Card.cardFromValueSuit(card_values[i][1], card_suits[i][1]) + card3 = Card.cardFromValueSuit(card_values[i][2], card_suits[i][2]) + card4 = Card.cardFromValueSuit(card_values[i][3], card_suits[i][3]) + card5 = Card.cardFromValueSuit(card_values[i][4], card_suits[i][4]) + card6 = Card.cardFromValueSuit(card_values[i][5], card_suits[i][5]) + card7 = Card.cardFromValueSuit(card_values[i][6], card_suits[i][6]) + cursor.execute ("""INSERT INTO HandsPlayers -(handId, playerId, startCash, ante, -card1Value, card1Suit, card2Value, card2Suit, -card3Value, card3Suit, card4Value, card4Suit, -card5Value, card5Suit, card6Value, card6Suit, -card7Value, card7Suit, winnings, rake, seatNo) -VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, -%s, %s, %s, %s)""", - (hands_id, player_ids[i], start_cashes[i], antes[i], - card_values[i][0], card_suits[i][0], card_values[i][1], card_suits[i][1], - card_values[i][2], card_suits[i][2], card_values[i][3], card_suits[i][3], - card_values[i][4], card_suits[i][4], card_values[i][5], card_suits[i][5], - card_values[i][6], card_suits[i][6], winnings[i], rakes[i], seatNos[i])) +(handId, playerId, startCash, ante, tourneyTypeId, +card1, card2, +card3, card4, +card5, card6, +card7, winnings, rake, seatNo) +VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", + (hands_id, player_ids[i], start_cashes[i], antes[i], 1, + card1, card2, + card3, card4, + card5, card6, + card7, winnings[i], rakes[i], seatNos[i])) #cursor.execute("SELECT id FROM HandsPlayers WHERE handId=%s AND playerId+0=%s", (hands_id, player_ids[i])) #result.append(cursor.fetchall()[0][0]) result.append( getLastInsertId(backend, conn, cursor) ) From e212bbd751771e984a3271727e828951f580aece Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 10 Jun 2009 18:19:49 +0800 Subject: [PATCH 04/30] Remove unused file --- pyfpdb/FpdbRegex.py | 161 -------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 pyfpdb/FpdbRegex.py diff --git a/pyfpdb/FpdbRegex.py b/pyfpdb/FpdbRegex.py deleted file mode 100644 index 8bfb9362..00000000 --- a/pyfpdb/FpdbRegex.py +++ /dev/null @@ -1,161 +0,0 @@ -# pokerstars_cash.py -# -*- coding: iso-8859-15 -# -# PokerStats, an online poker statistics tracking software for Linux -# Copyright (C) 2007-2008 Mika Boström -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 of the License. -# - -# Modified for use in fpdb by Carl Gherardi - -import re - -# These are PokerStars specific; -# More importantly, they are currently valid for cash game only. -##### -# XXX: There was a weird problem with saved hand histories in PokerStars -# client 2.491; if a user was present on the table (and thus anywhere in -# the hand history), with non-standard characters in their username, the -# client would prepend a literal Ctrl-P (ASCII 16, 0x10) character to -# the hand history title line. Hence, to allow these strangely saved -# hands to be parsed and imported, there is a conditional "one extra -# character" allowed at the start of the new hand regex. - - -class FpdbRegex: - def __init__(self): - self.__GAME_INFO_REGEX='' - self.__SPLIT_HAND_REGEX='\n\n\n' - self.__NEW_HAND_REGEX='^.?PokerStars Game #\d+:\s+Hold\'em' - self.__HAND_INFO_REGEX='^.*#(\d+):\s+(\S+)\s([\s\S]+)\s\(\$?([.0-9]+)/\$?([.0-9]+)\)\s-\s(\S+)\s-?\s?(\S+)\s\(?(\w+)\)?' - self.__TABLE_INFO_REGEX='^\S+\s+\'.*\'\s+(\d+)-max\s+Seat\s#(\d+)' - self.__PLAYER_INFO_REGEX='^Seat\s(\d+):\s(.*)\s\(\$?([.\d]+)\s' - self.__POST_SB_REGEX='^(.*):\sposts small blind' - self.__POST_BB_REGEX='^(.*):\sposts big blind' - self.__POST_BOTH_REGEX='^(.*):\sposts small & big blinds' - self.__HAND_STAGE_REGEX='^\*{3}\s(.*)\s\*{3}' - self.__HOLE_CARD_REGEX='^\*{3}\sHOLE CARDS' - self.__FLOP_CARD_REGEX='^\*{3}\sFLOP\s\*{3}\s\[(\S{2})\s(\S{2})\s(\S{2})\]' - self.__TURN_CARD_REGEX='^\*{3}\sTURN\s\*{3}\s\[\S{2}\s\S{2}\s\S{2}\]\s\[(\S{2})\]' - self.__RIVER_CARD_REGEX='^\*{3}\sRIVER\s\*{3}\s\[\S{2}\s\S{2}\s\S{2}\s\S{2}\]\s\[(\S{2})\]' - self.__SHOWDOWN_REGEX='^\*{3}\sSHOW DOWN' - self.__SUMMARY_REGEX='^\*{3}\sSUMMARY' - self.__UNCALLED_BET_REGEX='^Uncalled bet \(\$([.\d]+)\) returned to (.*)' - self.__POT_AND_RAKE_REGEX='^Total\spot\s\$([.\d]+).*\|\sRake\s\$([.\d]+)' - self.__COLLECT_POT_REGEX='^(.*)\scollected\s\$([.\d]+)\sfrom\s((main|side)\s)?pot' - self.__HERO_CARDS_REGEX='^Dealt\sto\s(.*)\s\[(\S{2})\s(\S{2})\]' - self.__SHOWN_CARDS_REGEX='^(.*):\sshows\s\[(\S{2})\s(\S{2})\]' - self.__ACTION_STEP_REGEX='^(.*):\s(bets|checks|raises|calls|folds)((\s\$([.\d]+))?(\sto\s\$([.\d]+))?)?' - - self.__SHOWDOWN_ACTION_REGEX='^(.*):\s(shows|mucks)' - self.__SUMMARY_CARDS_REGEX='^Seat\s\d+:\s(.*)\s(showed|mucked)\s\[(\S{2})\s(\S{2})\]' - self.__SUMMARY_CARDS_EXTRA_REGEX='^Seat\s\d+:\s(.*)\s(\(.*\)\s)(showed|mucked)\s\[(\S{2})\s(\S{2})\]' - - def compileRegexes(self): - ### Compile the regexes - self.game_info_re = re.compile(self.__GAME_INFO_REGEX) - self.split_hand_re = re.compile(self.__SPLIT_HAND_REGEX) - self.hand_start_re = re.compile(self.__NEW_HAND_REGEX) - self.hand_info_re = re.compile(self.__HAND_INFO_REGEX) - self.table_info_re = re.compile(self.__TABLE_INFO_REGEX) - self.player_info_re = re.compile(self.__PLAYER_INFO_REGEX) - self.small_blind_re = re.compile(self.__POST_SB_REGEX) - self.big_blind_re = re.compile(self.__POST_BB_REGEX) - self.both_blinds_re = re.compile(self.__POST_BOTH_REGEX) - self.hand_stage_re = re.compile(self.__HAND_STAGE_REGEX) - self.hole_cards_re = re.compile(self.__HOLE_CARD_REGEX) - self.flop_cards_re = re.compile(self.__FLOP_CARD_REGEX) - self.turn_card_re = re.compile(self.__TURN_CARD_REGEX) - self.river_card_re = re.compile(self.__RIVER_CARD_REGEX) - self.showdown_re = re.compile(self.__SHOWDOWN_REGEX) - self.summary_re = re.compile(self.__SUMMARY_REGEX) - self.uncalled_bet_re = re.compile(self.__UNCALLED_BET_REGEX) - self.collect_pot_re = re.compile(self.__COLLECT_POT_REGEX) - self.hero_cards_re = re.compile(self.__HERO_CARDS_REGEX) - self.cards_shown_re = re.compile(self.__SHOWN_CARDS_REGEX) - self.summary_cards_re = re.compile(self.__SUMMARY_CARDS_REGEX) - self.summary_cards_extra_re = re.compile(self.__SUMMARY_CARDS_EXTRA_REGEX) - self.action_re = re.compile(self.__ACTION_STEP_REGEX) - self.rake_re = re.compile(self.__POT_AND_RAKE_REGEX) - self.showdown_action_re = re.compile(self.__SHOWDOWN_ACTION_REGEX) - - # Set methods for plugins to override - - def setGameInfoRegex(self, string): - self.__GAME_INFO_REGEX = string - - def setSplitHandRegex(self, string): - self.__SPLIT_HAND_REGEX = string - - def setNewHandRegex(self, string): - self.__NEW_HAND_REGEX = string - - def setHandInfoRegex(self, string): - self.__HAND_INFO_REGEX = string - - def setTableInfoRegex(self, string): - self.__TABLE_INFO_REGEX = string - - def setPlayerInfoRegex(self, string): - self.__PLAYER_INFO_REGEX = string - - def setPostSbRegex(self, string): - self.__POST_SB_REGEX = string - - def setPostBbRegex(self, string): - self.__POST_BB_REGEX = string - - def setPostBothRegex(self, string): - self.__POST_BOTH_REGEX = string - - def setHandStageRegex(self, string): - self.__HAND_STAGE_REGEX = string - - def setHoleCardRegex(self, string): - self.__HOLE_CARD_REGEX = string - - def setFlopCardRegex(self, string): - self.__FLOP_CARD_REGEX = string - - def setTurnCardRegex(self, string): - self.__TURN_CARD_REGEX = string - - def setRiverCardRegex(self, string): - self.__RIVER_CARD_REGEX = string - - def setShowdownRegex(self, string): - self.__SHOWDOWN_REGEX = string - - def setSummaryRegex(self, string): - self.__SUMMARY_REGEX = string - - def setUncalledBetRegex(self, string): - self.__UNCALLED_BET_REGEX = string - - def setCollectPotRegex(self, string): - self.__COLLECT_POT_REGEX = string - - def setHeroCardsRegex(self, string): - self.__HERO_CARDS_REGEX = string - - def setShownCardsRegex(self, string): - self.__SHOWN_CARDS_REGEX = string - - def setSummaryCardsRegex(self, string): - self.__SUMMARY_CARDS_REGEX = string - - def setSummaryCardsExtraRegex(self, string): - self.__SUMMARY_CARDS_EXTRA_REGEX = string - - def setActionStepRegex(self, string): - self.__ACTION_STEP_REGEX = string - - def setPotAndRakeRegex(self, string): - self.__POT_AND_RAKE_REGEX = string - - def setShowdownActionRegex(self, string): - self.__SHOWDOWN_ACTION_REGEX = string - From ed9f02b11390fb63fb1be989ca615d108be4fba4 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 10 Jun 2009 20:48:33 +0800 Subject: [PATCH 05/30] Revert "pass all settings through so that a new one can be used to skip updating hudcache (not used yet)" This reverts commit b935a5ad67e3f88f765499f33a832500690cc939. --- pyfpdb/fpdb_import.py | 2 +- pyfpdb/fpdb_save_to_db.py | 36 ++++++++++++++---------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 3fa20b40..99330bb9 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -394,7 +394,7 @@ class Importer: self.hand=hand try: - handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb.db + handsId = fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db ,self.fdb.cursor, self.siteIds[site], category, hand, self.config) self.fdb.db.commit() diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index d06f8c45..3c99d084 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -35,12 +35,11 @@ SQLITE = 4 # # no graphs #stores a stud/razz hand into the database -def ring_stud(config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time +def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time ,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes ,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName ,seatNos): - backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = False if import_options['saveActions'] == False else True @@ -56,8 +55,7 @@ def ring_stud(config, settings, db, cursor, base, category, site_hand_no, gamety ,start_cashes, antes, card_values ,card_suits, winnings, rakes, seatNos) - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) if saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, action_types @@ -65,13 +63,12 @@ def ring_stud(config, settings, db, cursor, base, category, site_hand_no, gamety return hands_id #end def ring_stud -def ring_holdem_omaha(config, settings, db, cursor, base, category, site_hand_no, gametype_id +def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, gametype_id ,hand_start_time, names, player_ids, start_cashes, positions, card_values ,card_suits, board_values, board_suits, winnings, rakes, action_types, allIns ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a holdem/omaha hand into the database""" - backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = False if import_options['saveActions'] == False else True fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False @@ -93,11 +90,10 @@ def ring_holdem_omaha(config, settings, db, cursor, base, category, site_hand_no , positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData) t4 = time() #print "ring holdem, backend=%d" % backend - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if fastStoreHudCache: + fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + else: + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) t5 = time() fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) t6 = time() @@ -108,7 +104,7 @@ def ring_holdem_omaha(config, settings, db, cursor, base, category, site_hand_no return hands_id #end def ring_holdem_omaha -def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout +def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout ,entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId ,siteId #end of tourney specific params ,site_hand_no, gametype_id, hand_start_time, names, player_ids @@ -117,7 +113,6 @@ def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourn ,actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a tourney holdem/omaha hand into the database""" - backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = True if import_options['saveActions'] == True else False fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False @@ -136,11 +131,10 @@ def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourn , card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids) #print "tourney holdem, backend=%d" % backend - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if fastStoreHudCache: + fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + else: + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) @@ -149,14 +143,13 @@ def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourn return hands_id #end def tourney_holdem_omaha -def tourney_stud(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries +def tourney_stud(config, backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries ,prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId ,siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes ,cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts ,actionNos, hudImportData, maxSeats, tableName, seatNos): #stores a tourney stud/razz hand into the database - backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = True if import_options['saveActions'] == True else False fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False @@ -173,8 +166,7 @@ def tourney_stud(config, settings, db, cursor, base, category, siteTourneyNo, bu , playerIds, startCashes, antes, cardValues, cardSuits , winnings, rakes, seatNos, tourneys_players_ids) - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) + fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) if saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos) From 49a04af0c567f31f1d9271719bacfdec38e7faf0 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 12 Jun 2009 12:29:17 -0400 Subject: [PATCH 06/30] Add stud8 to PokerStars HH conversion. --- pyfpdb/Hand.py | 6 +++++- pyfpdb/PokerStarsToFpdb.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 38009250..2cd05252 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -80,6 +80,10 @@ class Hand: self.totalcollected = None self.rake = None + def __str__(self): + str = '' + str = str + "Hand Object for %s at %s" % (self.handid, self.sitename) + return str def insert(self, db): """ Function to insert Hand into database @@ -382,7 +386,7 @@ Map the tuple self.gametype onto the pokerstars string describing it "omahahilo" : "Omaha Hi/Lo", "razz" : "Razz", "studhi" : "7 Card Stud", - "studhilo" : "FIXME", + "studhilo" : "7 Card Stud Hi/Lo", "fivedraw" : "5 Card Draw", "27_1draw" : "FIXME", "27_3draw" : "Triple Draw 2-7 Lowball", diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 703dadcf..44bd88a2 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python + #!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2008, Carl Gherardi @@ -26,7 +26,7 @@ from HandHistoryConverter import * class PokerStars(HandHistoryConverter): # Static regexes - re_GameInfo = re.compile("PokerStars Game #(?P[0-9]+):\s+(HORSE)? \(?(?PHold\'em|Razz|7 Card Stud|Omaha|Omaha Hi/Lo|Badugi) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)", re.MULTILINE) + re_GameInfo = re.compile("PokerStars Game #(?P[0-9]+):\s+(HORSE)? \(?(?PHold\'em|Razz|7 Card Stud|7 Card Stud Hi/Lo|Omaha|Omaha Hi/Lo|Badugi) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)", re.MULTILINE) re_SplitHands = re.compile('\n\n+') re_TailSplitHands = re.compile('(\n\n\n+)') re_HandInfo = re.compile("^Table \'(?P[- a-zA-Z]+)\'(?P.+?$)?", re.MULTILINE) @@ -95,6 +95,7 @@ follow : whether to tail -f the input""" 'Omaha Hi/Lo' : ('hold','omahahilo'), 'Razz' : ('stud','razz'), '7 Card Stud' : ('stud','studhi'), + '7 Card Stud Hi/Lo' : ('stud','studhilo'), 'Badugi' : ('draw','badugi') } currencies = { u'€':'EUR', '$':'USD', '':'T$' } From b1ea38bea9361b678b1cc98487547a88c8845734 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 14 Jun 2009 23:14:53 -0400 Subject: [PATCH 07/30] Add -c config cl option. Fpdb passes cl options to HUD. --- pyfpdb/Configuration.py | 1 + pyfpdb/GuiAutoImport.py | 7 ++++++- pyfpdb/HUD_main.py | 31 +++++++++++++++------------- pyfpdb/Hud.py | 2 +- pyfpdb/Options.py | 45 +++++++++++++++++++++++++++++++++++++++++ pyfpdb/fpdb.py | 15 ++++++-------- 6 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 pyfpdb/Options.py diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 1d93f3f1..0ea4b371 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -250,6 +250,7 @@ class Config: self.default_config_path = self.get_default_config_path() if file != None: # configuration file path has been passed + file = os.path.expanduser(file) if not os.path.exists(file): print "Configuration file %s not found. Using defaults." % (file) sys.stderr.write("Configuration file %s not found. Using defaults." % (file)) diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 2b4c8b76..7f6c80e8 100755 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -28,6 +28,7 @@ import time import fpdb_import from optparse import OptionParser import Configuration +import string class GuiAutoImport (threading.Thread): def __init__(self, settings, config): @@ -165,7 +166,11 @@ class GuiAutoImport (threading.Thread): command = os.path.join(sys.path[0], 'HUD_main.py') #command = self.config.execution_path('HUD_main.py') # Hi Ray. Sorry about this, kludging. bs = 1 - self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE, + print "GUI:options =", self.settings['cl_options'] + options = string.split(self.settings['cl_options']) + cl = [command, ] + options + print "cl =", cl + self.pipe_to_hud = subprocess.Popen(cl, bufsize = bs, stdin = subprocess.PIPE, universal_newlines=True) # self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE, # universal_newlines=True) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 64cafaf8..2ffd057b 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -29,12 +29,20 @@ Main for FreePokerTools HUD. # Standard Library modules import sys - -# redirect the stderr -errorfile = open('HUD-error.txt', 'w', 0) -sys.stderr = errorfile - import os +import Options + +(options, sys.argv) = Options.fpdb_options() + +print "HUD: dbname =", options.dbname +print "HUD: config =", options.config +print "HUD: logging =", options.errorsToConsole + +if not options.errorsToConsole: + print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_." + errorFile = open('fpdb-error-log.txt', 'w', 0) + sys.stderr = errorFile + import thread import time import string @@ -59,7 +67,7 @@ class HUD_main(object): def __init__(self, db_name = 'fpdb'): self.db_name = db_name - self.config = Configuration.Config() + self.config = Configuration.Config(file=options.config, dbname=options.dbname) self.hud_dict = {} # a thread to read stdin @@ -198,17 +206,12 @@ class HUD_main(object): self.db_connection.connection.rollback() if __name__== "__main__": - sys.stderr.write("HUD_main starting\n") -# database name can be passed on command line - try: - db_name = sys.argv[1] - except: - db_name = 'fpdb' - sys.stderr.write("Using db name = %s\n" % (db_name)) + sys.stderr.write("HUD_main starting\n") + sys.stderr.write("Using db name = %s\n" % (options.dbname)) # start the HUD_main object - hm = HUD_main(db_name = db_name) + hm = HUD_main(db_name = options.dbname) # start the event loop gtk.main() diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 363175a1..56ad08f3 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -43,7 +43,7 @@ import Configuration import Stats import Mucked import Database -import HUD_main +#import HUD_main def importName(module_name, name): """Import a named object 'name' from module 'module_name'.""" diff --git a/pyfpdb/Options.py b/pyfpdb/Options.py new file mode 100644 index 00000000..38307d40 --- /dev/null +++ b/pyfpdb/Options.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +#Copyright 2008 Ray E. Barker +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU Affero General Public License as published by +#the Free Software Foundation, version 3 of the License. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU Affero General Public License +#along with this program. If not, see . +#In the "official" distribution you can find the license in +#agpl-3.0.txt in the docs folder of the package. + +import os +import sys +from optparse import OptionParser + +def fpdb_options(): + + """Process command line options for fpdb and HUD_main.""" + parser = OptionParser() + parser.add_option("-x", "--errorsToConsole", + action="store_true", + help="If passed error output will go to the console rather than .") + parser.add_option("-d", "--databaseName", + dest="dbname", default="fpdb", + help="Overrides the default database name") + parser.add_option("-c", "--configFile", + dest="config", default=None, + help="Specifies a configuration file.") + (options, sys.argv) = parser.parse_args() + return (options, sys.argv) + +if __name__== "__main__": + (options, sys.argv) = fpdb_options() + print "errorsToConsole =", options.errorsToConsole + print "database name =", options.dbname + print "config file =", options.config + + print "press enter to end" + sys.stdin.readline() \ No newline at end of file diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index c0f63a04..b03e8424 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -17,15 +17,11 @@ import os import sys -from optparse import OptionParser +import Options +import string - -parser = OptionParser() -parser.add_option("-x", "--errorsToConsole", action="store_true", - help="If passed error output will go to the console rather than .") -parser.add_option("-d", "--databaseName", dest="dbname", default="fpdb", - help="Overrides the default database name") -(options, sys.argv) = parser.parse_args() +cl_options = string.join(sys.argv[1:]) +(options, sys.argv) = Options.fpdb_options() if not options.errorsToConsole: print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_." @@ -356,6 +352,7 @@ class fpdb: else: self.settings['os']="windows" + self.settings.update({'cl_options': cl_options}) self.settings.update(self.config.get_db_parameters()) self.settings.update(self.config.get_tv_parameters()) self.settings.update(self.config.get_import_parameters()) @@ -486,7 +483,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") def __init__(self): self.threads=[] self.db=None - self.config = Configuration.Config(dbname=options.dbname) + self.config = Configuration.Config(file=options.config, dbname=options.dbname) self.load_profile() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) From 14fbae1b54a3d8beed6b472880cd04ce333b1a07 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Mon, 15 Jun 2009 22:21:27 +0100 Subject: [PATCH 08/30] get cards out --- pyfpdb/Hand.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index d660a5ea..ff59645f 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -1146,14 +1146,18 @@ limit 1""", {'handid':handid}) res = c.fetchone() gametype = {'category':res[1],'base':res[2],'type':res[3],'limitType':res[4],'hilo':res[5],'sb':res[6],'bb':res[7], 'currency':res[10]} h = HoldemOmahaHand(hhc = None, sitename=res[0], gametype = gametype, handText=None, builtFrom = "DB", handid=handid) - cards = map("".join, zip(map(str,res[11:21:2]), res[12:21:2])) + rank = {0:'X',1:'1',2:'2',3:'3',4:'4', + 5:'5',6:'6',7:'7',8:'8',9:'9', + 10:'T',11:'J',12:'Q',13:'K',14:'A'} + ranks = [rank[r] for r in res[11:21:2]] + cards = map("".join, zip(ranks, res[12:21:2])) - if cards[0] != "0x": + if cards[0] != "Xx": h.setCommunityCards('FLOP', cards[0:3]) - if cards[3] != "0x": - h.setCommunityCards('TURN', cards[3]) - if cards[4] != "0x": - h.setCommunityCards('RIVER', cards[4]) + if cards[3] != "Xx": + h.setCommunityCards('TURN', [cards[3]]) + if cards[4] != "Xx": + h.setCommunityCards('RIVER', [cards[4]]) #[Card.valueSuitFromCard(x) for x in cards] @@ -1182,9 +1186,10 @@ WHERE h.id = %(handid)s c.execute(""" SELECT hp.seatno, + hp.winnings / 100.0 as winnings, p.name, round(hp.startcash / 100.0,2) as chips, - (hp.card1,hp.card2) as hole + hp.card1,hp.card2 FROM handsplayers as hp, players as p @@ -1192,9 +1197,11 @@ WHERE hp.handid = %(handid)s and p.id = hp.playerid """, {'handid':handid}) - for (seat, name, chips, cards) in c.fetchall(): + for (seat, winnings, name, chips, card1,card2) in c.fetchall(): h.addPlayer(seat,name,chips) - h.addHoleCards([Card.valueSuitFromCard(x) for x in cards],name) + h.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)),name) + if winnings > 0: + h.addCollectPot(name, winnings) # actions c.execute(""" @@ -1237,7 +1244,7 @@ ORDER BY else: print act, player, streetnum, allin, amount # TODO : other actions - #hhc.readCollectPot(self) + #hhc.readShowdownActions(self) #hc.readShownCards(self) h.totalPot() From 574a286e0c89adf06c23fb8245c0328ea0d7187f Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Mon, 15 Jun 2009 22:30:58 +0100 Subject: [PATCH 09/30] round amounts to 2 dp --- pyfpdb/Hand.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 05be0520..46bd55e7 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -1115,10 +1115,10 @@ select g.type, g.limitType, g.hilo, - g.smallBlind / 100.0, - g.bigBlind / 100.0 , - g.smallBet / 100.0, - g.bigBet / 100.0, + round(g.smallBlind / 100.0,2), + round(g.bigBlind / 100.0,2), + round(g.smallBet / 100.0,2), + round(g.bigBet / 100.0,2), s.currency, bc.card1value, bc.card1suit, @@ -1185,7 +1185,7 @@ WHERE h.id = %(handid)s c.execute(""" SELECT hp.seatno, - hp.winnings / 100.0 as winnings, + round(hp.winnings / 100.0,2) as winnings, p.name, round(hp.startcash / 100.0,2) as chips, hp.card1,hp.card2 @@ -1210,7 +1210,7 @@ SELECT ha.street, ha.action, ha.allin, - ha.amount / 100.0 + round(ha.amount / 100.0,2) FROM handsplayers as hp, handsactions as ha, From 2a7a275e3a28117c2c62e446aadcc4213df5fc73 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Tue, 16 Jun 2009 00:29:44 +0100 Subject: [PATCH 10/30] some stan to write an HTML hand --- pyfpdb/Hand.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 46bd55e7..6c4cd0e8 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -514,6 +514,59 @@ Card ranks will be uppercased self.addHoleCards(holeandboard.difference(board),player,shown=True) + def writeHTMLHand(self, fh=sys.__stdout__): + from nevow import tags as T + from nevow import flat + players_who_act_preflop = (([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']])) + players_stacks = [x for x in self.players if x[1] in players_who_act_preflop] + + action_streets = [x for x in self.actionStreets if len(self.actions[x]) > 0] + def render_stack(context,data): + pat = context.tag.patternGenerator('list_item') + for player in data: + x = "Seat %s: %s ($%s in chips) " %(player[0], player[1], + player[2]) + context.tag[ pat().fillSlots('playerStack', x)] + return context.tag + + def render_street(context,data): + pat = context.tag.patternGenerator('list_item') + for street in data: + actions = [ + T.h3['%s' % street], + T.ol(class_='actions', data=self.actions[street], + render=render_action)[ + T.li(pattern='list_item')[ T.slot(name='action')] + ] + ] + context.tag[ pat().fillSlots('street', actions)] + return context.tag + + def render_action(context,data): + pat = context.tag.patternGenerator('list_item') + for act in data: + x = "%s %s" % (act[0],act[1]) + context.tag[ pat().fillSlots('action', x)] + return context.tag + + s = T.p[ + T.h1[ "%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, + self.getGameTypeAsString(), self.sb, self.bb, + datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET')) + ], + T.h2[ "Table '%s' %d-max Seat #%s is the button" %(self.tablename, + self.maxseats, self.buttonpos)], + T.ol(class_='stacks', data = players_stacks, render=render_stack)[ + T.li(pattern='list_item')[ T.slot(name='playerStack') ] + ], + T.ol(class_='streets', data = action_streets, + render=render_street)[ + T.li(pattern='list_item')[ T.slot(name='street')] + ] + ] + return flat.flatten(s) + + def writeHand(self, fh=sys.__stdout__): # PokerStars format. print >>fh, ("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))) From c4659ce5efa6d5940e7d8879deebd6387db231f8 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 16 Jun 2009 09:55:23 -0400 Subject: [PATCH 11/30] Untangle settings and backend changes. --- pyfpdb/fpdb_parse_logic.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index 150707c1..2d93b69f 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -21,7 +21,8 @@ import fpdb_simple import fpdb_save_to_db #parses a holdem hand -def mainParser(backend, db, cursor, siteID, category, hand, config): +def mainParser(settings, db, cursor, siteID, category, hand, config): + backend = settings['db-backend'] category = fpdb_simple.recogniseCategory(hand[0]) base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud" @@ -141,7 +142,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config): if base == "hold": result = fpdb_save_to_db.tourney_holdem_omaha( - config, backend, db, cursor, base, category, siteTourneyNo, buyin + config, settings, db, cursor, base, category, siteTourneyNo, buyin , fee, knockout, entries, prizepool, tourneyStartTime , payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo , gametypeID, handStartTime, names, playerIDs, startCashes @@ -150,7 +151,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config): , actionNos, hudImportData, maxSeats, tableName, seatNos) elif base == "stud": result = fpdb_save_to_db.tourney_stud( - config, backend, db, cursor, base, category, siteTourneyNo + config, settings, db, cursor, base, category, siteTourneyNo , buyin, fee, knockout, entries, prizepool, tourneyStartTime , payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo , gametypeID, handStartTime, names, playerIDs, startCashes @@ -162,7 +163,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config): else: if base == "hold": result = fpdb_save_to_db.ring_holdem_omaha( - config, backend, db, cursor, base, category, siteHandNo + config, settings, db, cursor, base, category, siteHandNo , gametypeID, handStartTime, names, playerIDs , startCashes, positions, cardValues, cardSuits , boardValues, boardSuits, winnings, rakes @@ -170,7 +171,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config): , hudImportData, maxSeats, tableName, seatNos) elif base == "stud": result = fpdb_save_to_db.ring_stud( - config, backend, db, cursor, base, category, siteHandNo, gametypeID + config, settings, db, cursor, base, category, siteHandNo, gametypeID , handStartTime, names, playerIDs, startCashes, antes , cardValues, cardSuits, winnings, rakes, actionTypes, allIns , actionAmounts, actionNos, hudImportData, maxSeats, tableName From bb633fd43554da6fa7ee8eff1d5d96639baf488f Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 16 Jun 2009 20:04:06 -0400 Subject: [PATCH 12/30] Correctly pass cl options to HUD_main in Windows. --- pyfpdb/GuiAutoImport.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 7f6c80e8..fb278f17 100755 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -158,25 +158,15 @@ class GuiAutoImport (threading.Thread): widget.set_label(u' _Stop Autoimport ') if self.pipe_to_hud is None: if os.name == 'nt': - command = "python HUD_main.py" + " %s" % (self.database) + command = "python HUD_main.py" + " " + self.settings['cl_options'] bs = 0 # windows is not happy with line buffing here self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE, universal_newlines=True) else: command = os.path.join(sys.path[0], 'HUD_main.py') - #command = self.config.execution_path('HUD_main.py') # Hi Ray. Sorry about this, kludging. - bs = 1 - print "GUI:options =", self.settings['cl_options'] - options = string.split(self.settings['cl_options']) - cl = [command, ] + options - print "cl =", cl - self.pipe_to_hud = subprocess.Popen(cl, bufsize = bs, stdin = subprocess.PIPE, + cl = [command, ] + string.split(self.settings['cl_options']) + self.pipe_to_hud = subprocess.Popen(cl, bufsize = 1, stdin = subprocess.PIPE, universal_newlines=True) - # self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE, - # universal_newlines=True) - # command = command + " %s" % (self.database) - # print "command = ", command - # self.pipe_to_hud = os.popen(command, 'w') # Add directories to importer object. for site in self.input_settings: From 4a6c257b0fff8595650742cc917c4ea6e38983a8 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 16 Jun 2009 23:00:46 -0400 Subject: [PATCH 13/30] get_cards query now works directly with the 0-52 card encoding scheme. --- pyfpdb/Database.py | 16 ++++------------ pyfpdb/SQL.py | 1 - 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 9582354a..b6c97a29 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -156,21 +156,13 @@ class Database: def get_cards(self, hand): """Get and return the cards for each player in the hand.""" - cards = {} # dict of cards, the key is the seat number example: {1: 'AcQd9hTs5d'} + cards = {} # dict of cards, the key is the seat number, + # the value is a tuple of the players cards + # example: {1: (0, 0, 20, 21, 22, 0 , 0)} c = self.connection.cursor() c.execute(self.sql.query['get_cards'], [hand]) - colnames = [desc[0] for desc in c.description] - cardnames = ['card1', 'card2', 'card3', 'card4', 'card5', 'card6', 'card7'] for row in c.fetchall(): - cs = ['', '', '', '', '', '', ''] - seat = -1 - for col,name in enumerate(colnames): - if name in cardnames: - cs[cardnames.index(name)] = Card.valueSuitFromCard(row[col]) - elif name == 'seat_number': - seat = row[col] - if seat != -1: - cards[seat] = ''.join(cs) + cards[row[0]] = row[1:] return cards def get_common_cards(self, hand): diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index a36f812d..1a9deb60 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -528,7 +528,6 @@ class Sql: self.query['get_cards'] = """ select seatNo AS seat_number, - name AS screen_name, card1, /*card1Value, card1Suit, */ card2, /*card2Value, card2Suit, */ card3, /*card3Value, card3Suit, */ From 63efc13cc944fec7e47e927de553080fa18f4834 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 17 Jun 2009 14:24:16 -0400 Subject: [PATCH 14/30] Make Stud_Mucked work with the new card encoding scheme. --- pyfpdb/Mucked.py | 89 +++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 93f6d102..12da2a97 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -35,6 +35,7 @@ import gobject # FreePokerTools modules import Configuration import Database +import Card class Aux_Window: def __init__(self, hud, params, config): @@ -67,16 +68,23 @@ class Aux_Window: # Some utility routines useful for Aux_Windows # def get_card_images(self): - card_images = {} - suits = ('S', 'H', 'D', 'C') - ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B') + + card_images = 53 * [0] + suits = ('s', 'h', 'd', 'c') + ranks = (14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2) pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck'])) - for j in range(0, 14): + for j in range(0, 13): for i in range(0, 4): temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) - card_images[(ranks[j], suits[i])] = temp_pb + card_images[Card.cardFromValueSuit(ranks[j], suits[i])] = temp_pb + temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) +# also pick out a card back and store in [0] + j = 13 + i = 2 + pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) + card_images[0] = temp_pb return(card_images) # cards are 30 wide x 42 high @@ -108,9 +116,10 @@ class Stud_mucked(Aux_Window): def create(self): - self.container =gtk.Window() + self.container = gtk.Window() self.vbox = gtk.VBox() self.container.add(self.vbox) + self.container.set_title(self.hud.table.name) self.mucked_list.create(self.vbox) self.mucked_cards.create(self.vbox) @@ -207,7 +216,9 @@ class Stud_list: # find the hero's seat from the stat_dict for stat in self.parent.hud.stat_dict.itervalues(): if stat['screen_name'] == hero: - return self.parent.hud.cards[stat['seat']][0:6] + return Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][0]) +\ + Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][1]) +\ + Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][2]) return "xxxxxx" def update_gui(self, new_hand_id): @@ -240,7 +251,7 @@ class Stud_cards: for r in range(0, self.rows): for c in range(0, self.cols): - self.seen_cards[(c, r)] = gtk.image_new_from_pixbuf(self.card_images[('B', 'S')]) + self.seen_cards[(c, r)] = gtk.image_new_from_pixbuf(self.card_images[(0)]) self.eb[(c, r)]= gtk.EventBox() # set up the contents for the cells @@ -287,11 +298,11 @@ class Stud_cards: self.clear() for c, cards in self.parent.hud.cards.iteritems(): self.grid_contents[(1, c - 1)].set_text(self.get_screen_name(c)) - for i in ((0, cards[0:2]), (1, cards[2:4]), (2, cards[4:6]), (3, cards[6:8]), - (4, cards[8:10]), (5, cards[10:12]), (6, cards[12:14])): - if not i[1] == "xx": + for i in ((0, cards[0]), (1, cards[1]), (2, cards[2]), (3, cards[3]), + (4, cards[4]), (5, cards[5]), (6, cards[6])): + if not i[1] == 0: self.seen_cards[(i[0], c - 1)]. \ - set_from_pixbuf(self.card_images[self.parent.split_cards(i[1])]) + set_from_pixbuf(self.card_images[i[1]]) ## action in tool tips for 3rd street cards for c in (0, 1, 2): for r in range(0, self.rows): @@ -314,7 +325,7 @@ class Stud_cards: for r in range(0, self.rows): self.grid_contents[(1, r)].set_text(" ") for c in range(0, 7): - self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')]) + self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[0]) self.eb[(c, r)].set_tooltip_text('') class Flop_Mucked(Aux_Window): @@ -459,29 +470,31 @@ class Flop_Mucked(Aux_Window): new_locs[i] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs) -if __name__== "__main__": - - def destroy(*args): # call back for terminating the main eventloop - gtk.main_quit() # used only for testing +# This test program doesn't work - def process_new_hand(source, condition, db_connection): #callback from stdin watch -- testing only -# there is a new hand_id to be processed -# just read it and pass it to update - new_hand_id = sys.stdin.readline() - new_hand_id = new_hand_id.rstrip() # remove trailing whitespace - m.update_data(new_hand_id, db_connection) - m.update_gui(new_hand_id) - return(True) - - config = Configuration.Config() - db_connection = Database.Database(config, 'fpdb', '') - main_window = gtk.Window() - main_window.set_keep_above(True) - main_window.connect("destroy", destroy) - - aux_to_call = "stud_mucked" - aux_params = config.get_aux_parameters(aux_to_call) - m = eval("%s(main_window, None, config, aux_params)" % aux_params['class']) - - s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand, db_connection) - gtk.main() +#if __name__== "__main__": +# +# def destroy(*args): # call back for terminating the main eventloop +# gtk.main_quit() # used only for testing +# +# def process_new_hand(source, condition, db_connection): #callback from stdin watch -- testing only +## there is a new hand_id to be processed +## just read it and pass it to update +# new_hand_id = sys.stdin.readline() +# new_hand_id = new_hand_id.rstrip() # remove trailing whitespace +# m.update_data(new_hand_id, db_connection) +# m.update_gui(new_hand_id) +# return(True) +# +# config = Configuration.Config() +# db_connection = Database.Database(config, 'fpdbTEST', '') +# main_window = gtk.Window() +# main_window.set_keep_above(True) +# main_window.connect("destroy", destroy) +# +# aux_to_call = "stud_mucked" +# aux_params = config.get_aux_parameters(aux_to_call) +# m = eval("%s(None, config, aux_params)" % aux_params['class']) +# +# s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand, db_connection) +# gtk.main() From 42f2b73c1a089bfbdedbe427721bb44ee68a08d7 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 17 Jun 2009 14:26:16 -0400 Subject: [PATCH 15/30] Get rid of some intermediate print. --- pyfpdb/HUD_main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 2ffd057b..218707bd 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -34,10 +34,6 @@ import Options (options, sys.argv) = Options.fpdb_options() -print "HUD: dbname =", options.dbname -print "HUD: config =", options.config -print "HUD: logging =", options.errorsToConsole - if not options.errorsToConsole: print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_." errorFile = open('fpdb-error-log.txt', 'w', 0) From a6a98a750f0cce8a86f1247fd86c760551d73625 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 18 Jun 2009 14:11:53 -0400 Subject: [PATCH 16/30] Clean up changes to use 0-52 card encoding. --- pyfpdb/Mucked.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 12da2a97..8ae6bc60 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -76,18 +76,19 @@ class Aux_Window: for j in range(0, 13): for i in range(0, 4): - temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) - pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) - card_images[Card.cardFromValueSuit(ranks[j], suits[i])] = temp_pb + card_images[Card.cardFromValueSuit(ranks[j], suits[i])] = self.cropper(pb, i, j) temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) # also pick out a card back and store in [0] - j = 13 - i = 2 - pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) - card_images[0] = temp_pb + card_images[0] = self.cropper(pb, 2, 13) return(card_images) # cards are 30 wide x 42 high + def cropper(self, pb, i, j): + """Crop out a card image given an FTP deck and the i, j position.""" + temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) + pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) + return temp_pb + def split_cards(self, card): if card == 'xx': return ('B', 'S') return (card[0], card[1].upper()) From 44aed2c95f3b7e68b73902cbf00c7f368cb3cc86 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Fri, 19 Jun 2009 07:04:57 +0100 Subject: [PATCH 17/30] populate hands.boardcards --- pyfpdb/Card.py | 17 ++++++++++++++++- pyfpdb/fpdb_save_to_db.py | 3 ++- pyfpdb/fpdb_simple.py | 9 +++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 75c742f9..ab6843c5 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -57,6 +57,21 @@ def fourStartCards(value1, suit1, value2, suit2, value3, suit3, value4, suit4): #AAKKs #AAKKr # Is probably what we are looking for + + # mct: + # my maths says there are 4 classes of suitedness + # SSSS SSSx SSxy SSHH + # encode them as follows: + # SSSS (K, J, 6, 3) + # - 13C4 = 715 possibilities + # SSSx (K, J, 6),(3) + # - 13C3 * 13 = 3718 possibilities + # SSxy (K, J),(6),(3) + # - 13C2 * 13*13 = 13182 possibilities + # SSHH (K, J),(6, 3) + # - 13C2 * 13C2 = 6084 possibilities + # Needless to say they won't fit on a 13x13 grid. + # The actual number of hands in each class is far greater return(0) def cardFromValueSuit(value, suit): @@ -70,7 +85,7 @@ def cardFromValueSuit(value, suit): def valueSuitFromCard(card): """ Function to convert a card stored in the database (int 0-52) into value and suit like 9s, 4c etc """ - if card < 0 or card > 52: + if card < 0 or card > 52 or not card: return('') else: return( ['', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', 'Th', 'Jh', 'Qh', 'Kh', 'Ah' diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index 3c99d084..2eba8bfa 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -83,7 +83,8 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, t2 = time() hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id - ,hand_start_time, names, tableName, maxSeats, hudImportData) + ,hand_start_time, names, tableName, maxSeats, + hudImportData, board_values, board_suits) t3 = time() hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha( backend, db, cursor, category, hands_id, player_ids, start_cashes diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 31321aeb..adc1a106 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1147,10 +1147,13 @@ card5Value, card5Suit) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", #end def store_board_cards def storeHands(backend, conn, cursor, site_hand_no, gametype_id - ,hand_start_time, names, tableName, maxSeats, hudCache): + ,hand_start_time, names, tableName, maxSeats, hudCache, + board_values, board_suits): + cards = [Card.cardFromValueSuit(v,s) for v,s in zip(board_values,board_suits)] #stores into table hands: cursor.execute ("""INSERT INTO Hands (siteHandNo, gametypeId, handStart, seats, tableName, importTime, maxSeats + ,boardcard1,boardcard2,boardcard3,boardcard4,boardcard5 ,playersVpi, playersAtStreet1, playersAtStreet2 ,playersAtStreet3, playersAtStreet4, playersAtShowdown ,street0Raises, street1Raises, street2Raises @@ -1159,9 +1162,11 @@ def storeHands(backend, conn, cursor, site_hand_no, gametype_id ,showdownPot ) VALUES - (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """ , (site_hand_no, gametype_id, hand_start_time, len(names), tableName, datetime.datetime.today(), maxSeats + ,cards[0], cards[1], cards[2], cards[3], cards[4] ,hudCache['playersVpi'], hudCache['playersAtStreet1'], hudCache['playersAtStreet2'] ,hudCache['playersAtStreet3'], hudCache['playersAtStreet4'], hudCache['playersAtShowdown'] ,hudCache['street0Raises'], hudCache['street1Raises'], hudCache['street2Raises'] From 620576ba210c24a9d94b8cec4593abd3a5907da8 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Fri, 19 Jun 2009 07:21:35 +0100 Subject: [PATCH 18/30] more html output --- pyfpdb/Hand.py | 237 ++++++++++++++++++++++--------------- pyfpdb/PokerStarsToFpdb.py | 2 +- 2 files changed, 143 insertions(+), 96 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 6c4cd0e8..bee52dd5 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -39,15 +39,14 @@ class Hand: self.starttime = 0 self.handText = handText self.handid = 0 - self.tablename = "Slartibartfast" - self.hero = "Hiro" + self.tablename = "" + self.hero = "" self.maxseats = 10 self.counted_seats = 0 self.buttonpos = 0 self.seating = [] self.players = [] self.posted = [] - self.involved = True # Collections indexed by street names self.bets = {} @@ -55,23 +54,26 @@ class Hand: self.streets = {} self.actions = {} # [['mct','bets','$10'],['mika','folds'],['carlg','raises','$20']] self.board = {} # dict from street names to community cards - for street in self.streetList: + self.holecards = {} + for street in self.allStreets: self.streets[street] = "" # portions of the handText, filled by markStreets() self.bets[street] = {} self.lastBet[street] = 0 self.actions[street] = [] self.board[street] = [] + self.holecards[street] = {} # dict from player names to holecards # Collections indexed by player names - self.holecards = {} # dict from player names to dicts by street ... of tuples ... of holecards +# self.holecards = {} # dict from player names to dicts by street ... of tuples ... of holecards self.discards = {} # dict from player names to dicts by street ... of tuples ... of discarded holecards self.stacks = {} self.collected = [] #list of ? self.collectees = {} # dict from player names to amounts collected (?) # Sets of players - self.shown = set() self.folded = set() + self.dealt = set() # 'dealt to' line to be printed + self.shown = set() # cards were shown # self.action = [] # Things to do with money @@ -90,7 +92,7 @@ db: a connected fpdb_db object""" sqlids = db.getSqlPlayerIDs([p[1] for p in self.players], self.siteId) # HudCache data to come from DerivedStats class # HandsActions - all actions for all players for all streets - self.actions - # BoardCards - Skip - no longer necessary? + # BoardCards - Skip - no longer necessary # Hands - Summary information of hand indexed by handId - gameinfo #hh['siteHandNo'] = self.handid # gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), @@ -163,12 +165,10 @@ If a player has None chips he won't be added.""" if chips is not None: self.players.append([seat, name, chips]) self.stacks[name] = Decimal(chips) - self.holecards[name] = [] - self.discards[name] = [] self.pot.addPlayer(name) - for street in self.streetList: + for street in self.allStreets: self.bets[street][name] = [] - self.holecards[name] = {} # dict from street names. + #self.holecards[name] = {} # dict from street names. self.discards[name] = {} # dict from street names. @@ -407,32 +407,32 @@ Map the tuple self.gametype onto the pokerstars string describing it def printHand(self): self.writeHand(sys.stdout) - def printActionLine(self, act, fh): + def actionString(self, act): if act[1] == 'folds': - print >>fh, ("%s: folds " %(act[0])) + return ("%s: folds " %(act[0])) elif act[1] == 'checks': - print >>fh, ("%s: checks " %(act[0])) + return ("%s: checks " %(act[0])) elif act[1] == 'calls': - print >>fh, ("%s: calls $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: calls $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'bets': - print >>fh, ("%s: bets $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: bets $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'raises': - print >>fh, ("%s: raises $%s to $%s%s" %(act[0], act[2], act[3], ' and is all-in' if act[5] else '')) + return ("%s: raises $%s to $%s%s" %(act[0], act[2], act[3], ' and is all-in' if act[5] else '')) elif act[1] == 'completea': - print >>fh, ("%s: completes to $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: completes to $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'posts': if(act[2] == "small blind"): - print >>fh, ("%s: posts small blind $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) + return ("%s: posts small blind $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) elif(act[2] == "big blind"): - print >>fh, ("%s: posts big blind $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) + return ("%s: posts big blind $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) elif(act[2] == "both"): - print >>fh, ("%s: posts small & big blinds $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) + return ("%s: posts small & big blinds $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) elif act[1] == 'bringin': - print >>fh, ("%s: brings in for $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: brings in for $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'discards': - print >>fh, ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards[act[0]]['DRAWONE']) + "]" if self.hero == act[0] else '')) + return ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards[act[0]]['DRAWONE']) + "]" if self.hero == act[0] else '')) elif act[1] == 'stands pat': - print >>fh, ("%s: stands pat" %(act[0])) + return ("%s: stands pat" %(act[0])) class HoldemOmahaHand(Hand): @@ -440,9 +440,10 @@ class HoldemOmahaHand(Hand): if gametype['base'] != 'hold': pass # or indeed don't pass and complain instead logging.debug("HoldemOmahaHand") - self.streetList = ['BLINDSANTES', 'DEAL', 'PREFLOP','FLOP','TURN','RIVER'] # a list of the observed street names in order + self.allStreets = ['BLINDSANTES', 'PREFLOP','FLOP','TURN','RIVER'] + self.holeStreets = ['PREFLOP'] self.communityStreets = ['FLOP', 'TURN', 'RIVER'] - self.actionStreets = ['PREFLOP','FLOP','TURN','RIVER'] + self.actionStreets = ['BLINDSANTES','PREFLOP','FLOP','TURN','RIVER'] Hand.__init__(self, sitename, gametype, handText, builtFrom = "HHC") self.sb = gametype['sb'] self.bb = gametype['bb'] @@ -480,24 +481,32 @@ class HoldemOmahaHand(Hand): pass - def addHoleCards(self, cards, player, shown=False): + def addHoleCards(self, cards, player, shown=False, dealt=False): """\ Assigns observed holecards to a player. cards list of card bigrams e.g. ['2h','Jc'] player (string) name of player +shown whether they were revealed at showdown +dealt whether they were seen in a 'dealt to' line """ logging.debug("addHoleCards %s %s" % (cards, player)) try: self.checkPlayerExists(player) - cardset = set(self.card(c) for c in cards) - if shown and len(cardset) > 0: - self.shown.add(player) - if 'PREFLOP' in self.holecards[player]: - self.holecards[player]['PREFLOP'].update(cardset) - else: - self.holecards[player]['PREFLOP'] = cardset except FpdbParseError, e: print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) + return + + cardset = set((self.card(c) for c in cards)) + if len(cardset) == 0: + return + if dealt: + self.dealt.add(player) + if shown: + self.shown.add(player) + if player in self.holecards['PREFLOP']: + self.holecards['PREFLOP'][player].update(cardset) + else: + self.holecards['PREFLOP'][player] = cardset def addShownCards(self, cards, player, holeandboard=None): """\ @@ -506,8 +515,7 @@ Card ranks will be uppercased """ logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard)) if cards is not None: - self.shown.add(player) - self.addHoleCards(cards,player) + self.addHoleCards(cards,player,shown=True) elif holeandboard is not None: holeandboard = set([self.card(c) for c in holeandboard]) board = set([c for s in self.board.values() for c in s]) @@ -519,7 +527,6 @@ Card ranks will be uppercased from nevow import flat players_who_act_preflop = (([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']])) players_stacks = [x for x in self.players if x[1] in players_who_act_preflop] - action_streets = [x for x in self.actionStreets if len(self.actions[x]) > 0] def render_stack(context,data): pat = context.tag.patternGenerator('list_item') @@ -532,39 +539,82 @@ Card ranks will be uppercased def render_street(context,data): pat = context.tag.patternGenerator('list_item') for street in data: - actions = [ - T.h3['%s' % street], - T.ol(class_='actions', data=self.actions[street], - render=render_action)[ - T.li(pattern='list_item')[ T.slot(name='action')] - ] - ] - context.tag[ pat().fillSlots('street', actions)] + lines = [] + if street in self.holeStreets and self.holecards[street]: + lines.append( + T.ol(class_='dealclosed', data=street, + render=render_deal) [ + T.li(pattern='list_item')[ T.slot(name='deal') ] + ] + ) + if street in self.communityStreets and self.board[street]: + lines.append( + T.ol(class_='community', data=street, + render=render_deal_community)[ + T.li(pattern='list_item')[ T.slot(name='deal') ] + ] + ) + if street in self.actionStreets and self.actions[street]: + lines.append( + T.ol(class_='actions', data=self.actions[street], render=render_action) [ + T.li(pattern='list_item')[ T.slot(name='action') ] + ] + ) + if lines: + context.tag[ pat().fillSlots('street', [ T.h3[ street ] ]+lines)] return context.tag + def render_deal(context,data): + # data is streetname +# we can have open+closed, or just open, or just closed. + + if self.holecards[data]: + for player in self.holecards[data]: + somestuff = 'dealt to %s %s' % (player, self.holecards[data][player]) + pat = context.tag.patternGenerator('list_item') + context.tag[ pat().fillSlots('deal', somestuff)] + return context.tag + + def render_deal_community(context,data): + # data is streetname + if self.board[data]: + somestuff = '[' + ' '.join(self.board[data]) + ']' + pat = context.tag.patternGenerator('list_item') + context.tag[ pat().fillSlots('deal', somestuff)] + return context.tag def render_action(context,data): pat = context.tag.patternGenerator('list_item') for act in data: - x = "%s %s" % (act[0],act[1]) + x = self.actionString(act) context.tag[ pat().fillSlots('action', x)] return context.tag s = T.p[ - T.h1[ "%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, - self.getGameTypeAsString(), self.sb, self.bb, - datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET')) + T.h1[ + T.span(class_='site')["%s Game #%s]" % ('PokerStars', self.handid)], + T.span(class_='type_limit')[ "%s ($%s/$%s)" %(self.getGameTypeAsString(), self.sb, self.bb) ], + T.span(class_='date')[ datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET') ] ], T.h2[ "Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)], T.ol(class_='stacks', data = players_stacks, render=render_stack)[ T.li(pattern='list_item')[ T.slot(name='playerStack') ] ], - T.ol(class_='streets', data = action_streets, + T.ol(class_='streets', data = self.allStreets, render=render_street)[ T.li(pattern='list_item')[ T.slot(name='street')] ] ] - return flat.flatten(s) + import tidy + + options = dict(input_xml=True, + output_xhtml=True, + add_xml_decl=False, + doctype='omit', + indent='auto', + tidy_mark=False) + + return str(tidy.parseString(flat.flatten(s), **options)) def writeHand(self, fh=sys.__stdout__): @@ -580,33 +630,36 @@ Card ranks will be uppercased if self.actions['BLINDSANTES']: for act in self.actions['BLINDSANTES']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) print >>fh, ("*** HOLE CARDS ***") - if self.involved: - print >>fh, ("Dealt to %s [%s]" %(self.hero , " ".join(self.holecards[self.hero]['PREFLOP']))) + for player in self.dealt: + print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player]))) + if self.hero == "": + for player in self.shown.difference(self.dealt): + print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player]))) if self.actions['PREFLOP']: for act in self.actions['PREFLOP']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if self.board['FLOP']: print >>fh, ("*** FLOP *** [%s]" %( " ".join(self.board['FLOP']))) if self.actions['FLOP']: for act in self.actions['FLOP']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if self.board['TURN']: print >>fh, ("*** TURN *** [%s] [%s]" %( " ".join(self.board['FLOP']), " ".join(self.board['TURN']))) if self.actions['TURN']: for act in self.actions['TURN']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if self.board['RIVER']: print >>fh, ("*** RIVER *** [%s] [%s]" %(" ".join(self.board['FLOP']+self.board['TURN']), " ".join(self.board['RIVER']) )) if self.actions['RIVER']: for act in self.actions['RIVER']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) #Some sites don't have a showdown section so we have to figure out if there should be one @@ -622,8 +675,8 @@ Card ranks will be uppercased numOfHoleCardsNeeded = 4 elif self.gametype['category'] in ('holdem'): numOfHoleCardsNeeded = 2 - if len(self.holecards[name]['PREFLOP']) == numOfHoleCardsNeeded: - print >>fh, ("%s shows [%s] (a hand...)" % (name, " ".join(self.holecards[name]['PREFLOP']))) + if len(self.holecards['PREFLOP'][name]) == numOfHoleCardsNeeded: + print >>fh, ("%s shows [%s] (a hand...)" % (name, " ".join(self.holecards['PREFLOP'][name]))) # Current PS format has the lines: # Uncalled bet ($111.25) returned to s0rrow @@ -792,12 +845,12 @@ Card ranks will be uppercased (nc,oc) = self.holecards[player]['DEAL'] print >>fh, _("Dealt to %s: [%s]") % (player, " ".join(nc)) for act in self.actions['DEAL']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if 'DRAWONE' in self.actions: print >>fh, _("*** FIRST DRAW ***") for act in self.actions['DRAWONE']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': (nc,oc) = self.holecards[act[0]]['DRAWONE'] dc = self.discards[act[0]]['DRAWONE'] @@ -807,7 +860,7 @@ Card ranks will be uppercased if 'DRAWTWO' in self.actions: print >>fh, _("*** SECOND DRAW ***") for act in self.actions['DRAWTWO']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': (nc,oc) = self.holecards[act[0]]['DRAWTWO'] dc = self.discards[act[0]]['DRAWTWO'] @@ -817,7 +870,7 @@ Card ranks will be uppercased if 'DRAWTHREE' in self.actions: print >>fh, _("*** THIRD DRAW ***") for act in self.actions['DRAWTHREE']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': (nc,oc) = self.holecards[act[0]]['DRAWTHREE'] dc = self.discards[act[0]]['DRAWTHREE'] @@ -956,7 +1009,7 @@ Add a complete on [street] by [player] to [amountTo] print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(closed) + "] " if closed else " ", "[" + " ".join(open) + "]" if open else "") for act in self.actions['THIRD']: #FIXME: Need some logic here for bringin vs completes - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if 'FOURTH' in self.actions: dealt = 0 @@ -973,7 +1026,7 @@ Add a complete on [street] by [player] to [amountTo] print >>fh, _("*** 4TH STREET ***") print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['FOURTH']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if 'FIFTH' in self.actions: dealt = 0 @@ -991,7 +1044,7 @@ Add a complete on [street] by [player] to [amountTo] print >>fh, _("*** 5TH STREET ***") print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['FIFTH']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if 'SIXTH' in self.actions: dealt = 0 @@ -1009,7 +1062,7 @@ Add a complete on [street] by [player] to [amountTo] print >>fh, _("*** 6TH STREET ***") print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['SIXTH']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) if 'SEVENTH' in self.actions: # OK. It's possible that they're all in at an earlier street, but only closed cards are dealt. @@ -1028,7 +1081,7 @@ Add a complete on [street] by [player] to [amountTo] if new: print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['SEVENTH']: - self.printActionLine(act, fh) + print >>fh, self.actionString(act) #Some sites don't have a showdown section so we have to figure out if there should be one # The logic for a showdown is: at the end of river action there are at least two players in the hand @@ -1159,7 +1212,8 @@ class Pot(object): def assemble(cnxn, handid): c = cnxn.cursor() - # We need the following for the Hand.__init__ + # We need at least sitename, gametype, handid + # for the Hand.__init__ c.execute(""" select s.name, @@ -1173,22 +1227,19 @@ select round(g.smallBet / 100.0,2), round(g.bigBet / 100.0,2), s.currency, - bc.card1value, - bc.card1suit, - bc.card2value,bc.card2suit, - bc.card3value,bc.card3suit, - bc.card4value,bc.card4suit, - bc.card5value,bc.card5suit + h.boardcard1, + h.boardcard2, + h.boardcard3, + h.boardcard4, + h.boardcard5 from hands as h, - boardcards as bc, sites as s, gametypes as g, handsplayers as hp, players as p where h.id = %(handid)s -and bc.handid = h.id and g.id = h.gametypeid and hp.handid = h.id and p.id = hp.playerid @@ -1198,24 +1249,15 @@ limit 1""", {'handid':handid}) res = c.fetchone() gametype = {'category':res[1],'base':res[2],'type':res[3],'limitType':res[4],'hilo':res[5],'sb':res[6],'bb':res[7], 'currency':res[10]} h = HoldemOmahaHand(hhc = None, sitename=res[0], gametype = gametype, handText=None, builtFrom = "DB", handid=handid) - rank = {0:'X',1:'1',2:'2',3:'3',4:'4', - 5:'5',6:'6',7:'7',8:'8',9:'9', - 10:'T',11:'J',12:'Q',13:'K',14:'A'} - ranks = [rank[r] for r in res[11:21:2]] - cards = map("".join, zip(ranks, res[12:21:2])) - - if cards[0] != "Xx": + cards = map(Card.valueSuitFromCard, res[11:16] ) + if cards[0]: h.setCommunityCards('FLOP', cards[0:3]) - if cards[3] != "Xx": + if cards[3]: h.setCommunityCards('TURN', [cards[3]]) - if cards[4] != "Xx": + if cards[4]: h.setCommunityCards('RIVER', [cards[4]]) #[Card.valueSuitFromCard(x) for x in cards] - - #TODO : doesn't look like this is in the database; don't like the way Hand requires it - h.hero = 'mcturnbull' - # HandInfo : HID, TABLE # BUTTON - why is this treated specially in Hand? # answer: it is written out in hand histories @@ -1241,7 +1283,8 @@ SELECT round(hp.winnings / 100.0,2) as winnings, p.name, round(hp.startcash / 100.0,2) as chips, - hp.card1,hp.card2 + hp.card1,hp.card2, + hp.position FROM handsplayers as hp, players as p @@ -1249,12 +1292,16 @@ WHERE hp.handid = %(handid)s and p.id = hp.playerid """, {'handid':handid}) - for (seat, winnings, name, chips, card1,card2) in c.fetchall(): + for (seat, winnings, name, chips, card1,card2, position) in c.fetchall(): h.addPlayer(seat,name,chips) - h.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)),name) + if card1 and card2: + h.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)), name, dealt=True) if winnings > 0: h.addCollectPot(name, winnings) + if position == 'B': + h.buttonpos = seat + # actions c.execute(""" SELECT @@ -1278,7 +1325,7 @@ ORDER BY res = c.fetchall() for (actnum,player, streetnum, act, allin, amount) in res: act=act.strip() - street = h.streetList[streetnum+2] + street = h.allStreets[streetnum+1] if act==u'blind': h.addBlind(player, 'big blind', amount) # TODO: The type of blind is not recorded in the DB. diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 703dadcf..aaf18463 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -208,7 +208,7 @@ follow : whether to tail -f the input""" for a in self.re_PostBB.finditer(hand.handText): hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB')) for a in self.re_PostBoth.finditer(hand.handText): - hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB')) + hand.addBlind(a.group('PNAME'), 'both', a.group('SBBB')) def readHeroCards(self, hand): m = self.re_HeroCards.search(hand.handText) From afddc130a5cea12e5d86274597b5b22d79a55524 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 19 Jun 2009 09:39:17 -0400 Subject: [PATCH 19/30] Fix minor error in writing seen hole cards. --- pyfpdb/Hand.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 5342487b..c8481269 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -703,11 +703,12 @@ Card ranks will be uppercased if board: # sometimes hand ends preflop without a board print >>fh, ("Board [%s]" % (" ".join(board))) + print "holecards =", self.holecards for player in [x for x in self.players if x[1] in players_who_act_preflop]: seatnum = player[0] name = player[1] if name in self.collectees and name in self.shown: - print >>fh, ("Seat %d: %s showed [%s] and won ($%s)" % (seatnum, name, " ".join(self.holecards[name]['PREFLOP']), self.collectees[name])) + print >>fh, ("Seat %d: %s showed [%s] and won ($%s)" % (seatnum, name, " ".join(self.holecards['PREFLOP'][name]), self.collectees[name])) elif name in self.collectees: print >>fh, ("Seat %d: %s collected ($%s)" % (seatnum, name, self.collectees[name])) #~ elif name in self.shown: @@ -716,7 +717,7 @@ Card ranks will be uppercased print >>fh, ("Seat %d: %s folded" % (seatnum, name)) else: if name in self.shown: - print >>fh, ("Seat %d: %s showed [%s] and lost with..." % (seatnum, name, " ".join(self.holecards[name]['PREFLOP']))) + print >>fh, ("Seat %d: %s showed [%s] and lost with..." % (seatnum, name, " ".join(self.holecards['PREFLOP'][name]))) else: print >>fh, ("Seat %d: %s mucked" % (seatnum, name)) From 053bfb9cee0f5b9c263004bcadc6b5a115cb4d37 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 19 Jun 2009 09:43:49 -0400 Subject: [PATCH 20/30] Remove intermediate print from previous commit. --- pyfpdb/Hand.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index c8481269..6849a32c 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -703,7 +703,6 @@ Card ranks will be uppercased if board: # sometimes hand ends preflop without a board print >>fh, ("Board [%s]" % (" ".join(board))) - print "holecards =", self.holecards for player in [x for x in self.players if x[1] in players_who_act_preflop]: seatnum = player[0] name = player[1] From a47ff7fb9be821870197ef36c3b6e1bcf14c1890 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 00:58:41 +0800 Subject: [PATCH 21/30] Fix case sensitivity in test for Hands table before dropping --- pyfpdb/fpdb_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 7c1fc800..86776b82 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -578,7 +578,7 @@ class fpdb_db: self.cursor.execute( "lock tables Hands write" ) except: # Table 'fpdb.hands' doesn't exist - if str(sys.exc_value).find(".hands' doesn't exist") >= 0: + if str(sys.exc_value).find(".Hands' doesn't exist") >= 0: return(2) print "Error! failed to obtain global lock. Close all programs accessing " \ + "database (including fpdb) and try again (%s)." \ From 966fba2165334dee1a2c9bee0d0491c9c1045bd7 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 01:17:06 +0800 Subject: [PATCH 22/30] Fix parameter being passed to Sql __init__ db_server not db_backend --- pyfpdb/Database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 10780c69..f8dd8f0d 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -45,7 +45,7 @@ class Database: db_params = c.get_db_parameters() self.type = db_params['db-type'] - self.sql = SQL.Sql(game = game, type = self.type, db_server = db_params['db-backend']) + self.sql = SQL.Sql(game = game, type = self.type, db_server = db_params['db-server']) self.connection.rollback() # To add to config: From fdf4b65136f8e0d1c7f9cde859bb3de759ca33cd Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 9 Jun 2009 22:55:18 +0100 Subject: [PATCH 23/30] pass all settings through so that a new one can be used to skip updating hudcache (not used yet) --- pyfpdb/fpdb_import.py | 2 +- pyfpdb/fpdb_save_to_db.py | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 99330bb9..3fa20b40 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -394,7 +394,7 @@ class Importer: self.hand=hand try: - handsId = fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db + handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb.db ,self.fdb.cursor, self.siteIds[site], category, hand, self.config) self.fdb.db.commit() diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index e612a166..b6e8686c 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -34,11 +34,12 @@ saveActions = True # set this to False to avoid storing action data # variance not available on stats page # : No graphs #stores a stud/razz hand into the database -def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time +def ring_stud(config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time ,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes ,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName ,seatNos): + backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = False if import_options['saveActions'] == False else True @@ -54,7 +55,8 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp ,start_cashes, antes, card_values ,card_suits, winnings, rakes, seatNos) - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) if saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, action_types @@ -62,12 +64,13 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp return hands_id #end def ring_stud -def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, gametype_id +def ring_holdem_omaha(config, settings, db, cursor, base, category, site_hand_no, gametype_id ,hand_start_time, names, player_ids, start_cashes, positions, card_values ,card_suits, board_values, board_suits, winnings, rakes, action_types, allIns ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a holdem/omaha hand into the database""" + backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = False if import_options['saveActions'] == False else True fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False @@ -90,10 +93,11 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, , positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData) t4 = time() #print "ring holdem, backend=%d" % backend - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + if fastStoreHudCache: + fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + else: + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) t5 = time() fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) t6 = time() @@ -104,7 +108,7 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, return hands_id #end def ring_holdem_omaha -def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout +def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout ,entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId ,siteId #end of tourney specific params ,site_hand_no, gametype_id, hand_start_time, names, player_ids @@ -113,6 +117,7 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne ,actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a tourney holdem/omaha hand into the database""" + backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = True if import_options['saveActions'] == True else False fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False @@ -131,10 +136,11 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne , card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids) #print "tourney holdem, backend=%d" % backend - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + if fastStoreHudCache: + fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + else: + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) @@ -143,13 +149,14 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne return hands_id #end def tourney_holdem_omaha -def tourney_stud(config, backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries +def tourney_stud(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries ,prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId ,siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes ,cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts ,actionNos, hudImportData, maxSeats, tableName, seatNos): #stores a tourney stud/razz hand into the database + backend = settings['db-backend'] import_options = config.get_import_parameters() saveActions = True if import_options['saveActions'] == True else False fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False @@ -166,7 +173,8 @@ def tourney_stud(config, backend, db, cursor, base, category, siteTourneyNo, buy , playerIds, startCashes, antes, cardValues, cardSuits , winnings, rakes, seatNos, tourneys_players_ids) - fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) if saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos) From f1921bebdea33ab3c6624bce7356c750e3fa2d56 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 04:15:52 +0800 Subject: [PATCH 24/30] Move functions from fpdb_save_to_db into Database.py Doesn't actually do much cleanup. Intend on moving all db functions into Database.py and fpdb_db.py and providing and API, the functionality of fpdb_simple et all to shift into the HHC --- pyfpdb/Database.py | 167 ++++++++++++++++++++++++++++++++++ pyfpdb/fpdb_import.py | 4 +- pyfpdb/fpdb_parse_logic.py | 38 ++++---- pyfpdb/fpdb_save_to_db.py | 182 ------------------------------------- 4 files changed, 189 insertions(+), 202 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index f8dd8f0d..7c13283c 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -33,6 +33,7 @@ import string # FreePokerTools modules import fpdb_db +import fpdb_simple import Configuration import SQL import Card @@ -77,6 +78,9 @@ class Database: #cur.execute(self.sql.query['get_table_name'], (hand_id, )) #row = cur.fetchone() + def commit(self): + self.fdb.db.commit() + def close_connection(self): self.connection.close() @@ -264,6 +268,169 @@ class Database: else: return None +#import fpdb_simple +# +#MYSQL_INNODB = 2 +#PGSQL = 3 +#SQLITE = 4 +# +#fastStoreHudCache = False # set this to True to test the new storeHudCache routine +# +#saveActions = True # set this to False to avoid storing action data +# # Pros: speeds up imports +# # Cons: no action data is saved, so you need to keep the hand histories +# # variance not available on stats page +# # : No graphs + + + #stores a stud/razz hand into the database + def ring_stud(self, config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time + ,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes + ,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName + ,seatNos): + + backend = settings['db-backend'] + import_options = config.get_import_parameters() + + saveActions = False if import_options['saveActions'] == False else True + fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False + + fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) + + hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + ,hand_start_time, names, tableName, maxSeats, hudImportData) + + #print "before calling store_hands_players_stud, antes:", antes + hands_players_ids = fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids + ,start_cashes, antes, card_values + ,card_suits, winnings, rakes, seatNos) + + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + + if saveActions: + fpdb_simple.storeActions(cursor, hands_players_ids, action_types + ,allIns, action_amounts, actionNos) + return hands_id + #end def ring_stud + + def ring_holdem_omaha(self, config, settings, db, cursor, base, category, site_hand_no, gametype_id + ,hand_start_time, names, player_ids, start_cashes, positions, card_values + ,card_suits, board_values, board_suits, winnings, rakes, action_types, allIns + ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): + """stores a holdem/omaha hand into the database""" + + backend = settings['db-backend'] + import_options = config.get_import_parameters() + saveActions = False if import_options['saveActions'] == False else True + fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False + + # print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache) + # print "DEBUG: import_options = ", import_options + + t0 = time() + fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) + t1 = time() + fpdb_simple.fill_board_cards(board_values, board_suits) + t2 = time() + + hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + ,hand_start_time, names, tableName, maxSeats, + hudImportData, board_values, board_suits) + t3 = time() + hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha( + backend, db, cursor, category, hands_id, player_ids, start_cashes + , positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData) + t4 = time() + #print "ring holdem, backend=%d" % backend + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + if fastStoreHudCache: + fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + else: + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + t5 = time() + fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) + t6 = time() + if saveActions: + fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos) + t7 = time() + #print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4, t6-t5) + return hands_id + #end def ring_holdem_omaha + + def tourney_holdem_omaha(self, config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout + ,entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId + ,siteId #end of tourney specific params + ,site_hand_no, gametype_id, hand_start_time, names, player_ids + ,start_cashes, positions, card_values, card_suits, board_values + ,board_suits, winnings, rakes, action_types, allIns, action_amounts + ,actionNos, hudImportData, maxSeats, tableName, seatNos): + """stores a tourney holdem/omaha hand into the database""" + + backend = settings['db-backend'] + import_options = config.get_import_parameters() + saveActions = True if import_options['saveActions'] == True else False + fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False + + fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) + fpdb_simple.fill_board_cards(board_values, board_suits) + + tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start) + tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings) + + hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + ,hand_start_time, names, tableName, maxSeats) + + hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha_tourney( + backend, db, cursor, category, hands_id, player_ids, start_cashes, positions + , card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids) + + #print "tourney holdem, backend=%d" % backend + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + if fastStoreHudCache: + fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + else: + fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + + fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) + + if saveActions: + fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos) + return hands_id + #end def tourney_holdem_omaha + + def tourney_stud(self, config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries + ,prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId + ,siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes + ,cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts + ,actionNos, hudImportData, maxSeats, tableName, seatNos): + #stores a tourney stud/razz hand into the database + + backend = settings['db-backend'] + import_options = config.get_import_parameters() + saveActions = True if import_options['saveActions'] == True else False + fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False + + fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits) + + tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime) + + tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings) + + hands_id = fpdb_simple.storeHands(backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats) + + hands_players_ids = fpdb_simple.store_hands_players_stud_tourney(backend, db, cursor, hands_id + , playerIds, startCashes, antes, cardValues, cardSuits + , winnings, rakes, seatNos, tourneys_players_ids) + + if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': + fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) + + if saveActions: + fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos) + return hands_id + #end def tourney_stud + if __name__=="__main__": c = Configuration.Config() diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 3fa20b40..99411573 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -394,8 +394,8 @@ class Importer: self.hand=hand try: - handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb.db - ,self.fdb.cursor, self.siteIds[site], category, hand, self.config) + handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb + , self.siteIds[site], category, hand, self.config) self.fdb.db.commit() stored += 1 diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index ee5d9c40..eff8179f 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -18,11 +18,13 @@ #methods that are specific to holdem but not trivial import fpdb_simple -import fpdb_save_to_db +import Database #parses a holdem hand -def mainParser(settings, db, cursor, siteID, category, hand, config): +def mainParser(settings, fdb, siteID, category, hand, config): backend = settings['db-backend'] + #This is redundant - hopefully fdb will be a Database object in an interation soon + db = Database.Database(config, 'fpdb', '') category = fpdb_simple.recogniseCategory(hand[0]) base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud" @@ -47,7 +49,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): break #print "small blind line:",smallBlindLine - gametypeID = fpdb_simple.recogniseGametypeID(backend, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney) + gametypeID = fpdb_simple.recogniseGametypeID(backend, fdb.db, fdb.cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney) if isTourney: siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0]) buyin = fpdb_simple.parseBuyin(hand[0]) @@ -58,9 +60,9 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): tourneyStartTime= handStartTime #todo: read tourney start time rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0]) - tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(cursor, siteID, buyin, fee, knockout, rebuyOrAddon) + tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(fdb.cursor, siteID, buyin, fee, knockout, rebuyOrAddon) - fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo) + fpdb_simple.isAlreadyInDB(fdb.cursor, gametypeID, siteHandNo) hand = fpdb_simple.filterCrap(hand, isTourney) @@ -74,7 +76,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): seatLines.append(line) names = fpdb_simple.parseNames(seatLines) - playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID) + playerIDs = fpdb_simple.recognisePlayerIDs(fdb.cursor, names, siteID) tmp = fpdb_simple.parseCashesAndSeatNos(seatLines) startCashes = tmp['startCashes'] seatNos = tmp['seatNos'] @@ -113,7 +115,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): tableName = tableResult['tableName'] #print "before part5, antes:", antes - #part 5: final preparations, then call fpdb_save_to_db.* with + #part 5: final preparations, then call Database.* with # the arrays as they are - that file will fill them. fpdb_simple.convertCardValues(cardValues) if base == "hold": @@ -121,8 +123,8 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): fpdb_simple.convertBlindBet(actionTypes, actionAmounts) fpdb_simple.checkPositions(positions) - cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, )) - limit_type = cursor.fetchone()[0] + fdb.cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, )) + limit_type = fdb.cursor.fetchone()[0] fpdb_simple.convert3B4B(category, limit_type, actionTypes, actionAmounts) totalWinnings = sum(winnings) @@ -143,8 +145,8 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee) if base == "hold": - result = fpdb_save_to_db.tourney_holdem_omaha( - config, settings, db, cursor, base, category, siteTourneyNo, buyin + result = db.tourney_holdem_omaha( + config, settings, fdb.db, fdb.cursor, base, category, siteTourneyNo, buyin , fee, knockout, entries, prizepool, tourneyStartTime , payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo , gametypeID, handStartTime, names, playerIDs, startCashes @@ -152,8 +154,8 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): , winnings, rakes, actionTypes, allIns, actionAmounts , actionNos, hudImportData, maxSeats, tableName, seatNos) elif base == "stud": - result = fpdb_save_to_db.tourney_stud( - config, settings, db, cursor, base, category, siteTourneyNo + result = db.tourney_stud( + config, settings, fdb.db, fdb.cursor, base, category, siteTourneyNo , buyin, fee, knockout, entries, prizepool, tourneyStartTime , payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo , gametypeID, handStartTime, names, playerIDs, startCashes @@ -164,23 +166,23 @@ def mainParser(settings, db, cursor, siteID, category, hand, config): raise fpdb_simple.FpdbError("unrecognised category") else: if base == "hold": - result = fpdb_save_to_db.ring_holdem_omaha( - config, settings, db, cursor, base, category, siteHandNo + result = db.ring_holdem_omaha( + config, settings, fdb.db, fdb.cursor, base, category, siteHandNo , gametypeID, handStartTime, names, playerIDs , startCashes, positions, cardValues, cardSuits , boardValues, boardSuits, winnings, rakes , actionTypes, allIns, actionAmounts, actionNos , hudImportData, maxSeats, tableName, seatNos) elif base == "stud": - result = fpdb_save_to_db.ring_stud( - config, settings, db, cursor, base, category, siteHandNo, gametypeID + result = db.ring_stud( + config, settings, fdb.db, fdb.cursor, base, category, siteHandNo, gametypeID , handStartTime, names, playerIDs, startCashes, antes , cardValues, cardSuits, winnings, rakes, actionTypes, allIns , actionAmounts, actionNos, hudImportData, maxSeats, tableName , seatNos) else: raise fpdb_simple.FpdbError ("unrecognised category") - db.commit() + fdb.db.commit() return result #end def mainParser diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index b6e8686c..e69de29b 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -1,182 +0,0 @@ -#!/usr/bin/python - -#Copyright 2008 Steffen Jobbagy-Felso -#This program is free software: you can redistribute it and/or modify -#it under the terms of the GNU Affero General Public License as published by -#the Free Software Foundation, version 3 of the License. -# -#This program is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -#GNU General Public License for more details. -# -#You should have received a copy of the GNU Affero General Public License -#along with this program. If not, see . -#In the "official" distribution you can find the license in -#agpl-3.0.txt in the docs folder of the package. - -#This file contains methods to store hands into the db. decides to move this -#into a seperate file since its ugly, fairly long and just generally in the way. - -from time import time - -import fpdb_simple - -MYSQL_INNODB = 2 -PGSQL = 3 -SQLITE = 4 - -fastStoreHudCache = False # set this to True to test the new storeHudCache routine - -saveActions = True # set this to False to avoid storing action data - # Pros: speeds up imports - # Cons: no action data is saved, so you need to keep the hand histories - # variance not available on stats page - # : No graphs -#stores a stud/razz hand into the database -def ring_stud(config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time - ,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes - ,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName - ,seatNos): - - backend = settings['db-backend'] - import_options = config.get_import_parameters() - - saveActions = False if import_options['saveActions'] == False else True - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - - fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) - - hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id - ,hand_start_time, names, tableName, maxSeats, hudImportData) - - #print "before calling store_hands_players_stud, antes:", antes - hands_players_ids = fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids - ,start_cashes, antes, card_values - ,card_suits, winnings, rakes, seatNos) - - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - - if saveActions: - fpdb_simple.storeActions(cursor, hands_players_ids, action_types - ,allIns, action_amounts, actionNos) - return hands_id -#end def ring_stud - -def ring_holdem_omaha(config, settings, db, cursor, base, category, site_hand_no, gametype_id - ,hand_start_time, names, player_ids, start_cashes, positions, card_values - ,card_suits, board_values, board_suits, winnings, rakes, action_types, allIns - ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): - """stores a holdem/omaha hand into the database""" - - backend = settings['db-backend'] - import_options = config.get_import_parameters() - saveActions = False if import_options['saveActions'] == False else True - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - -# print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache) -# print "DEBUG: import_options = ", import_options - - t0 = time() - fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) - t1 = time() - fpdb_simple.fill_board_cards(board_values, board_suits) - t2 = time() - - hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id - ,hand_start_time, names, tableName, maxSeats, - hudImportData, board_values, board_suits) - t3 = time() - hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha( - backend, db, cursor, category, hands_id, player_ids, start_cashes - , positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData) - t4 = time() - #print "ring holdem, backend=%d" % backend - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - t5 = time() - fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) - t6 = time() - if saveActions: - fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos) - t7 = time() - #print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4, t6-t5) - return hands_id -#end def ring_holdem_omaha - -def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout - ,entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId - ,siteId #end of tourney specific params - ,site_hand_no, gametype_id, hand_start_time, names, player_ids - ,start_cashes, positions, card_values, card_suits, board_values - ,board_suits, winnings, rakes, action_types, allIns, action_amounts - ,actionNos, hudImportData, maxSeats, tableName, seatNos): - """stores a tourney holdem/omaha hand into the database""" - - backend = settings['db-backend'] - import_options = config.get_import_parameters() - saveActions = True if import_options['saveActions'] == True else False - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - - fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) - fpdb_simple.fill_board_cards(board_values, board_suits) - - tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start) - tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings) - - hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id - ,hand_start_time, names, tableName, maxSeats) - - hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha_tourney( - backend, db, cursor, category, hands_id, player_ids, start_cashes, positions - , card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids) - - #print "tourney holdem, backend=%d" % backend - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - - fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) - - if saveActions: - fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos) - return hands_id -#end def tourney_holdem_omaha - -def tourney_stud(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries - ,prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId - ,siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes - ,cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts - ,actionNos, hudImportData, maxSeats, tableName, seatNos): -#stores a tourney stud/razz hand into the database - - backend = settings['db-backend'] - import_options = config.get_import_parameters() - saveActions = True if import_options['saveActions'] == True else False - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - - fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits) - - tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime) - - tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings) - - hands_id = fpdb_simple.storeHands(backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats) - - hands_players_ids = fpdb_simple.store_hands_players_stud_tourney(backend, db, cursor, hands_id - , playerIds, startCashes, antes, cardValues, cardSuits - , winnings, rakes, seatNos, tourneys_players_ids) - - if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) - - if saveActions: - fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos) - return hands_id -#end def tourney_stud From 2b3e507a3c5cd2a5e7ed09d1b87e00f221f0a32f Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 05:33:33 +0800 Subject: [PATCH 25/30] Factor out some common code --- pyfpdb/Database.py | 80 +++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 55 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 7c13283c..b394622a 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -45,7 +45,9 @@ class Database: self.connection = self.fdb.db db_params = c.get_db_parameters() + self.import_options = c.get_import_parameters() self.type = db_params['db-type'] + self.backend = db_params['db-backend'] self.sql = SQL.Sql(game = game, type = self.type, db_server = db_params['db-server']) self.connection.rollback() @@ -77,6 +79,9 @@ class Database: self.hand_nhands_ago = 0 # todo #cur.execute(self.sql.query['get_table_name'], (hand_id, )) #row = cur.fetchone() + self.saveActions = False if self.import_options['saveActions'] == False else True + self.fastStoreHudCache = True if self.import_options['fastStoreHudCache'] == True else False + def commit(self): self.fdb.db.commit() @@ -268,20 +273,6 @@ class Database: else: return None -#import fpdb_simple -# -#MYSQL_INNODB = 2 -#PGSQL = 3 -#SQLITE = 4 -# -#fastStoreHudCache = False # set this to True to test the new storeHudCache routine -# -#saveActions = True # set this to False to avoid storing action data -# # Pros: speeds up imports -# # Cons: no action data is saved, so you need to keep the hand histories -# # variance not available on stats page -# # : No graphs - #stores a stud/razz hand into the database def ring_stud(self, config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time @@ -289,26 +280,20 @@ class Database: ,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName ,seatNos): - backend = settings['db-backend'] - import_options = config.get_import_parameters() - - saveActions = False if import_options['saveActions'] == False else True - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) - hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + hands_id = fpdb_simple.storeHands(self.backend, db, cursor, site_hand_no, gametype_id ,hand_start_time, names, tableName, maxSeats, hudImportData) #print "before calling store_hands_players_stud, antes:", antes - hands_players_ids = fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids + hands_players_ids = fpdb_simple.store_hands_players_stud(self.backend, db, cursor, hands_id, player_ids ,start_cashes, antes, card_values ,card_suits, winnings, rakes, seatNos) if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - if saveActions: + if self.saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, action_types ,allIns, action_amounts, actionNos) return hands_id @@ -320,11 +305,6 @@ class Database: ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a holdem/omaha hand into the database""" - backend = settings['db-backend'] - import_options = config.get_import_parameters() - saveActions = False if import_options['saveActions'] == False else True - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - # print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache) # print "DEBUG: import_options = ", import_options @@ -334,24 +314,24 @@ class Database: fpdb_simple.fill_board_cards(board_values, board_suits) t2 = time() - hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + hands_id = fpdb_simple.storeHands(self.backend, db, cursor, site_hand_no, gametype_id ,hand_start_time, names, tableName, maxSeats, hudImportData, board_values, board_suits) t3 = time() hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha( - backend, db, cursor, category, hands_id, player_ids, start_cashes + self.backend, db, cursor, category, hands_id, player_ids, start_cashes , positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData) t4 = time() #print "ring holdem, backend=%d" % backend if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if self.fastStoreHudCache: + fpdb_simple.storeHudCache2(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) t5 = time() fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) t6 = time() - if saveActions: + if self.saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos) t7 = time() #print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4, t6-t5) @@ -367,34 +347,29 @@ class Database: ,actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a tourney holdem/omaha hand into the database""" - backend = settings['db-backend'] - import_options = config.get_import_parameters() - saveActions = True if import_options['saveActions'] == True else False - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) fpdb_simple.fill_board_cards(board_values, board_suits) tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start) tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings) - hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + hands_id = fpdb_simple.storeHands(self.backend, db, cursor, site_hand_no, gametype_id ,hand_start_time, names, tableName, maxSeats) hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha_tourney( - backend, db, cursor, category, hands_id, player_ids, start_cashes, positions + self.backend, db, cursor, category, hands_id, player_ids, start_cashes, positions , card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids) #print "tourney holdem, backend=%d" % backend if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if fastStoreHudCache: - fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + if self.fastStoreHudCache: + fpdb_simple.storeHudCache2(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) else: - fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) - if saveActions: + if self.saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos) return hands_id #end def tourney_holdem_omaha @@ -406,27 +381,22 @@ class Database: ,actionNos, hudImportData, maxSeats, tableName, seatNos): #stores a tourney stud/razz hand into the database - backend = settings['db-backend'] - import_options = config.get_import_parameters() - saveActions = True if import_options['saveActions'] == True else False - fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False - fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits) tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime) tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings) - hands_id = fpdb_simple.storeHands(backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats) + hands_id = fpdb_simple.storeHands(self.backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats) - hands_players_ids = fpdb_simple.store_hands_players_stud_tourney(backend, db, cursor, hands_id + hands_players_ids = fpdb_simple.store_hands_players_stud_tourney(self.backend, db, cursor, hands_id , playerIds, startCashes, antes, cardValues, cardSuits , winnings, rakes, seatNos, tourneys_players_ids) if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) + fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData) - if saveActions: + if self.saveActions: fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos) return hands_id #end def tourney_stud From 2569eeddc813304fd5a1b4bfe79d5ecc4611c8d4 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 05:37:30 +0800 Subject: [PATCH 26/30] Remve legacy storeHudCache function --- pyfpdb/Database.py | 12 +-- pyfpdb/fpdb_simple.py | 183 ------------------------------------------ 2 files changed, 2 insertions(+), 193 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index b394622a..2762143e 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -80,7 +80,6 @@ class Database: #cur.execute(self.sql.query['get_table_name'], (hand_id, )) #row = cur.fetchone() self.saveActions = False if self.import_options['saveActions'] == False else True - self.fastStoreHudCache = True if self.import_options['fastStoreHudCache'] == True else False def commit(self): @@ -305,7 +304,6 @@ class Database: ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a holdem/omaha hand into the database""" - # print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache) # print "DEBUG: import_options = ", import_options t0 = time() @@ -324,10 +322,7 @@ class Database: t4 = time() #print "ring holdem, backend=%d" % backend if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if self.fastStoreHudCache: - fpdb_simple.storeHudCache2(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) t5 = time() fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) t6 = time() @@ -362,10 +357,7 @@ class Database: #print "tourney holdem, backend=%d" % backend if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop': - if self.fastStoreHudCache: - fpdb_simple.storeHudCache2(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) - else: - fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) + fpdb_simple.storeHudCache(self.backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData) fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 398a20e5..34f99e2f 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -2126,189 +2126,6 @@ def storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, # hard-code styleKey as 'A000000' (all-time cache, no key) for now styleKey = 'A000000' - #print "storeHudCache, len(playerIds)=", len(playerIds), " len(vpip)=" \ - #, len(hudImportData['street0VPI']), " len(totprof)=", len(hudImportData['totalProfit']) - for player in xrange(len(playerIds)): - - # Set up a clean row - row=[] - row.append(0)#blank for id - row.append(gametypeId) - row.append(playerIds[player]) - row.append(len(playerIds))#seats - for i in xrange(len(hudImportData)+2): - row.append(0) - - if base=="hold": - row[4]=hudImportData['position'][player] - else: - row[4]=0 - row[5]=1 #tourneysGametypeId - row[6]+=1 #HDs - if hudImportData['street0VPI'][player]: row[7]+=1 - if hudImportData['street0Aggr'][player]: row[8]+=1 - if hudImportData['street0_3BChance'][player]: row[9]+=1 - if hudImportData['street0_3BDone'][player]: row[10]+=1 - if hudImportData['street1Seen'][player]: row[11]+=1 - if hudImportData['street2Seen'][player]: row[12]+=1 - if hudImportData['street3Seen'][player]: row[13]+=1 - if hudImportData['street4Seen'][player]: row[14]+=1 - if hudImportData['sawShowdown'][player]: row[15]+=1 - if hudImportData['street1Aggr'][player]: row[16]+=1 - if hudImportData['street2Aggr'][player]: row[17]+=1 - if hudImportData['street3Aggr'][player]: row[18]+=1 - if hudImportData['street4Aggr'][player]: row[19]+=1 - if hudImportData['otherRaisedStreet1'][player]: row[20]+=1 - if hudImportData['otherRaisedStreet2'][player]: row[21]+=1 - if hudImportData['otherRaisedStreet3'][player]: row[22]+=1 - if hudImportData['otherRaisedStreet4'][player]: row[23]+=1 - if hudImportData['foldToOtherRaisedStreet1'][player]: row[24]+=1 - if hudImportData['foldToOtherRaisedStreet2'][player]: row[25]+=1 - if hudImportData['foldToOtherRaisedStreet3'][player]: row[26]+=1 - if hudImportData['foldToOtherRaisedStreet4'][player]: row[27]+=1 - if hudImportData['wonWhenSeenStreet1'][player]!=0.0: row[28]+=hudImportData['wonWhenSeenStreet1'][player] - if hudImportData['wonAtSD'][player]!=0.0: row[29]+=hudImportData['wonAtSD'][player] - if hudImportData['stealAttemptChance'][player]: row[30]+=1 - if hudImportData['stealAttempted'][player]: row[31]+=1 - if hudImportData['foldBbToStealChance'][player]: row[32]+=1 - if hudImportData['foldedBbToSteal'][player]: row[33]+=1 - if hudImportData['foldSbToStealChance'][player]: row[34]+=1 - if hudImportData['foldedSbToSteal'][player]: row[35]+=1 - - if hudImportData['street1CBChance'][player]: row[36]+=1 - if hudImportData['street1CBDone'][player]: row[37]+=1 - if hudImportData['street2CBChance'][player]: row[38]+=1 - if hudImportData['street2CBDone'][player]: row[39]+=1 - if hudImportData['street3CBChance'][player]: row[40]+=1 - if hudImportData['street3CBDone'][player]: row[41]+=1 - if hudImportData['street4CBChance'][player]: row[42]+=1 - if hudImportData['street4CBDone'][player]: row[43]+=1 - - if hudImportData['foldToStreet1CBChance'][player]: row[44]+=1 - if hudImportData['foldToStreet1CBDone'][player]: row[45]+=1 - if hudImportData['foldToStreet2CBChance'][player]: row[46]+=1 - if hudImportData['foldToStreet2CBDone'][player]: row[47]+=1 - if hudImportData['foldToStreet3CBChance'][player]: row[48]+=1 - if hudImportData['foldToStreet3CBDone'][player]: row[49]+=1 - if hudImportData['foldToStreet4CBChance'][player]: row[50]+=1 - if hudImportData['foldToStreet4CBDone'][player]: row[51]+=1 - - #print "player=", player - #print "len(totalProfit)=", len(hudImportData['totalProfit']) - if hudImportData['totalProfit'][player]: - row[52]+=hudImportData['totalProfit'][player] - - if hudImportData['street1CheckCallRaiseChance'][player]: row[53]+=1 - if hudImportData['street1CheckCallRaiseDone'][player]: row[54]+=1 - if hudImportData['street2CheckCallRaiseChance'][player]: row[55]+=1 - if hudImportData['street2CheckCallRaiseDone'][player]: row[56]+=1 - if hudImportData['street3CheckCallRaiseChance'][player]: row[57]+=1 - if hudImportData['street3CheckCallRaiseDone'][player]: row[58]+=1 - if hudImportData['street4CheckCallRaiseChance'][player]: row[59]+=1 - if hudImportData['street4CheckCallRaiseDone'][player]: row[60]+=1 - - # Try to do the update first: - num = cursor.execute("""UPDATE HudCache -SET HDs=HDs+%s, street0VPI=street0VPI+%s, street0Aggr=street0Aggr+%s, - street0_3BChance=street0_3BChance+%s, street0_3BDone=street0_3BDone+%s, - street1Seen=street1Seen+%s, street2Seen=street2Seen+%s, street3Seen=street3Seen+%s, - street4Seen=street4Seen+%s, sawShowdown=sawShowdown+%s, - street1Aggr=street1Aggr+%s, street2Aggr=street2Aggr+%s, street3Aggr=street3Aggr+%s, - street4Aggr=street4Aggr+%s, otherRaisedStreet1=otherRaisedStreet1+%s, - otherRaisedStreet2=otherRaisedStreet2+%s, otherRaisedStreet3=otherRaisedStreet3+%s, - otherRaisedStreet4=otherRaisedStreet4+%s, - foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s, foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s, - foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s, foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s, - wonWhenSeenStreet1=wonWhenSeenStreet1+%s, wonAtSD=wonAtSD+%s, stealAttemptChance=stealAttemptChance+%s, - stealAttempted=stealAttempted+%s, foldBbToStealChance=foldBbToStealChance+%s, - foldedBbToSteal=foldedBbToSteal+%s, - foldSbToStealChance=foldSbToStealChance+%s, foldedSbToSteal=foldedSbToSteal+%s, - street1CBChance=street1CBChance+%s, street1CBDone=street1CBDone+%s, street2CBChance=street2CBChance+%s, - street2CBDone=street2CBDone+%s, street3CBChance=street3CBChance+%s, - street3CBDone=street3CBDone+%s, street4CBChance=street4CBChance+%s, street4CBDone=street4CBDone+%s, - foldToStreet1CBChance=foldToStreet1CBChance+%s, foldToStreet1CBDone=foldToStreet1CBDone+%s, - foldToStreet2CBChance=foldToStreet2CBChance+%s, foldToStreet2CBDone=foldToStreet2CBDone+%s, - foldToStreet3CBChance=foldToStreet3CBChance+%s, - foldToStreet3CBDone=foldToStreet3CBDone+%s, foldToStreet4CBChance=foldToStreet4CBChance+%s, - foldToStreet4CBDone=foldToStreet4CBDone+%s, totalProfit=totalProfit+%s, - street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s, - street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s, street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s, - street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s, street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s, - street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s, street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s, - street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s -WHERE gametypeId+0=%s -AND playerId=%s -AND activeSeats=%s -AND position=%s -AND tourneyTypeId+0=%s -AND styleKey=%s - """, (row[6], row[7], row[8], row[9], row[10], - row[11], row[12], row[13], row[14], row[15], - row[16], row[17], row[18], row[19], row[20], - row[21], row[22], row[23], row[24], row[25], - row[26], row[27], row[28], row[29], row[30], - row[31], row[32], row[33], row[34], row[35], - row[36], row[37], row[38], row[39], row[40], - row[41], row[42], row[43], row[44], row[45], - row[46], row[47], row[48], row[49], row[50], - row[51], row[52], row[53], row[54], row[55], - row[56], row[57], row[58], row[59], row[60], - row[1], row[2], row[3], str(row[4]), row[5], styleKey)) - # Test statusmessage to see if update worked, do insert if not - #print "storehud2, upd num =", num - if ( (backend == PGSQL and cursor.statusmessage != "UPDATE 1") - or (backend == MYSQL_INNODB and num == 0) ): - #print "playerid before insert:",row[2]," num = ", num - cursor.execute("""INSERT INTO HudCache -(gametypeId, playerId, activeSeats, position, tourneyTypeId, styleKey, -HDs, street0VPI, street0Aggr, street0_3BChance, street0_3BDone, -street1Seen, street2Seen, street3Seen, street4Seen, sawShowdown, -street1Aggr, street2Aggr, street3Aggr, street4Aggr, otherRaisedStreet1, -otherRaisedStreet2, otherRaisedStreet3, otherRaisedStreet4, foldToOtherRaisedStreet1, foldToOtherRaisedStreet2, -foldToOtherRaisedStreet3, foldToOtherRaisedStreet4, wonWhenSeenStreet1, wonAtSD, stealAttemptChance, -stealAttempted, foldBbToStealChance, foldedBbToSteal, foldSbToStealChance, foldedSbToSteal, -street1CBChance, street1CBDone, street2CBChance, street2CBDone, street3CBChance, -street3CBDone, street4CBChance, street4CBDone, foldToStreet1CBChance, foldToStreet1CBDone, -foldToStreet2CBChance, foldToStreet2CBDone, foldToStreet3CBChance, foldToStreet3CBDone, foldToStreet4CBChance, -foldToStreet4CBDone, totalProfit, street1CheckCallRaiseChance, street1CheckCallRaiseDone, street2CheckCallRaiseChance, -street2CheckCallRaiseDone, street3CheckCallRaiseChance, street3CheckCallRaiseDone, street4CheckCallRaiseChance, street4CheckCallRaiseDone) -VALUES (%s, %s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s, -%s, %s, %s, %s, %s)""" - , (row[1], row[2], row[3], row[4], row[5], styleKey, row[6], row[7], row[8], row[9], row[10] - ,row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18], row[19], row[20] - ,row[21], row[22], row[23], row[24], row[25], row[26], row[27], row[28], row[29], row[30] - ,row[31], row[32], row[33], row[34], row[35], row[36], row[37], row[38], row[39], row[40] - ,row[41], row[42], row[43], row[44], row[45], row[46], row[47], row[48], row[49], row[50] - ,row[51], row[52], row[53], row[54], row[55], row[56], row[57], row[58], row[59], row[60]) ) - #print "hopefully inserted hud data line: ", cursor.statusmessage - # message seems to be "INSERT 0 1" - else: - #print "updated(2) hud data line" - pass -# else: -# print "todo: implement storeHudCache for stud base" -#end def storeHudCache - -def storeHudCache2(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData): - """Modified version aiming for more speed ...""" -# if (category=="holdem" or category=="omahahi" or category=="omahahilo"): - if use_date_in_hudcache: - #print "key =", "d%02d%02d%02d " % (hand_start_time.year-2000, hand_start_time.month, hand_start_time.day) - styleKey = "d%02d%02d%02d" % (hand_start_time.year-2000, hand_start_time.month, hand_start_time.day) - else: - # hard-code styleKey as 'A000000' (all-time cache, no key) for now - styleKey = 'A000000' - #print "storeHudCache2, len(playerIds)=", len(playerIds), " len(vpip)=" \ #, len(hudImportData['street0VPI']), " len(totprof)=", len(hudImportData['totalProfit']) for player in xrange(len(playerIds)): From 864e37ddc863d76b8a50de1beb4a0edf870d3fd8 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 05:38:33 +0800 Subject: [PATCH 27/30] Remove empty file --- pyfpdb/fpdb_save_to_db.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pyfpdb/fpdb_save_to_db.py diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py deleted file mode 100644 index e69de29b..00000000 From d00031edf7d161cc4ec2c319e644d1063156501c Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 06:22:57 +0800 Subject: [PATCH 28/30] Add get_last_insert_id() to Database API --- pyfpdb/Database.py | 6 ++++-- pyfpdb/fpdb_db.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 2762143e..932a8578 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -272,6 +272,9 @@ class Database: else: return None + def get_last_insert_id(self): + return self.fdb.getLastInsertId() + #stores a stud/razz hand into the database def ring_stud(self, config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time @@ -304,8 +307,6 @@ class Database: ,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos): """stores a holdem/omaha hand into the database""" - # print "DEBUG: import_options = ", import_options - t0 = time() fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) t1 = time() @@ -315,6 +316,7 @@ class Database: hands_id = fpdb_simple.storeHands(self.backend, db, cursor, site_hand_no, gametype_id ,hand_start_time, names, tableName, maxSeats, hudImportData, board_values, board_suits) + #TEMPORARY CALL! - Just until all functions are migrated t3 = time() hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha( self.backend, db, cursor, category, hands_id, player_ids, start_cashes diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 86776b82..201b98fd 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -596,7 +596,35 @@ class fpdb_db: + "database (including fpdb) and try again (%s)." \ % ( str(sys.exc_value).rstrip('\n'), ) return(1) - return(0) + return(0) + + def getLastInsertId(self): + if self.backend == self.MYSQL_INNODB: + ret = self.db.insert_id() + if ret < 1 or ret > 999999999: + print "getLastInsertId(): problem fetching insert_id? ret=", ret + ret = -1 + elif self.backend == self.PGSQL: + # some options: + # currval(hands_id_seq) - use name of implicit seq here + # lastval() - still needs sequences set up? + # insert ... returning is useful syntax (but postgres specific?) + # see rules (fancy trigger type things) + self.cursor.execute ("SELECT lastval()") + row = self.cursor.fetchone() + if not row: + print "getLastInsertId(%s): problem fetching lastval? row=" % seq, row + ret = -1 + else: + ret = row[0] + elif self.backend == self.SQLITE: + # don't know how to do this in sqlite + print "getLastInsertId(): not coded for sqlite yet" + ret = -1 + else: + print "getLastInsertId(): unknown backend ", self.backend + ret = -1 + return ret def storeHand(self, p): #stores into table hands: From 706ce46a9f06c71a7eaa52a21ed5f6941da5e1c0 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 07:58:53 +0800 Subject: [PATCH 29/30] Boardcards for Hands table in new importer --- pyfpdb/Hand.py | 9 +++++++++ pyfpdb/fpdb_db.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 6849a32c..38c3609b 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -111,6 +111,14 @@ db: a connected fpdb_db object""" # boardcard3 smallint, # boardcard4 smallint, # boardcard5 smallint, + # Flop turn and river may all be empty - add (likely) too many elements and trim with range + # boardcards = board['FLOP'] + board['TURN'] + board['RIVER'] + [u'0x', u'0x', u'0x', u'0x', u'0x'] + # cards = [Card.cardFromValueSuit(v,s) for v,s in boardcards[0:4]] + # hh['boardcard1'] = cards[0] + # hh['boardcard2'] = cards[1] + # hh['boardcard3'] = cards[2] + # hh['boardcard4'] = cards[3] + # hh['boardcard5'] = cards[4] # texture smallint, # playersVpi SMALLINT NOT NULL, /* num of players vpi */ # Needs to be recorded @@ -194,6 +202,7 @@ If a player has None chips he won't be added.""" def setCommunityCards(self, street, cards): logging.debug("setCommunityCards %s %s" %(street, cards)) self.board[street] = [self.card(c) for c in cards] + print "DEBUG: self.board: %s" % self.board def card(self,c): """upper case the ranks but not suits, 'atjqk' => 'ATJQK'""" diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 201b98fd..29817af9 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -630,6 +630,7 @@ class fpdb_db: #stores into table hands: self.cursor.execute ("""INSERT INTO Hands (siteHandNo, gametypeId, handStart, seats, tableName, importTime, maxSeats + ,boardcard1, boardcard2, boardcard3, boardcard4, boardcard5 ,playersVpi, playersAtStreet1, playersAtStreet2 ,playersAtStreet3, playersAtStreet4, playersAtShowdown ,street0Raises, street1Raises, street2Raises @@ -640,6 +641,7 @@ class fpdb_db: VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" ,(p['siteHandNo'], gametype_id, p['handStart'], len(names), p['tableName'], datetime.datetime.today(), p['maxSeats'] + ,p['boardcard1'], ['boardcard2'], p['boardcard3'], ['boardcard4'], ['boardcard5'] ,hudCache['playersVpi'], hudCache['playersAtStreet1'], hudCache['playersAtStreet2'] ,hudCache['playersAtStreet3'], hudCache['playersAtStreet4'], hudCache['playersAtShowdown'] ,hudCache['street0Raises'], hudCache['street1Raises'], hudCache['street2Raises'] From 22ff98d7c9461c9e54351609574bbbc1b1e36723 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Jun 2009 14:02:03 +0800 Subject: [PATCH 30/30] Remove passthrough section from import_file_dict --- pyfpdb/fpdb_import.py | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 99411573..455c1e27 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -288,36 +288,34 @@ class Importer: if os.path.isdir(file): self.addToDirList[file] = [site] + [filter] return - if filter == "passthrough" or filter == "": - (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(file, site) - else: - conv = None - # Load filter, process file, pass returned filename to import_fpdb_file + + conv = None + # Load filter, process file, pass returned filename to import_fpdb_file - print "\nConverting %s" % file - hhbase = self.config.get_import_parameters().get("hhArchiveBase") - hhbase = os.path.expanduser(hhbase) - hhdir = os.path.join(hhbase,site) - try: - out_path = os.path.join(hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file)) - except: - out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file)) + print "\nConverting %s" % file + hhbase = self.config.get_import_parameters().get("hhArchiveBase") + hhbase = os.path.expanduser(hhbase) + hhdir = os.path.join(hhbase,site) + try: + out_path = os.path.join(hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file)) + except: + out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file)) - filter_name = filter.replace("ToFpdb", "") + filter_name = filter.replace("ToFpdb", "") - mod = __import__(filter) - obj = getattr(mod, filter_name, None) - if callable(obj): - conv = obj(in_path = file, out_path = out_path) - if(conv.getStatus()): - (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) - else: - # conversion didn't work - # TODO: appropriate response? - return (0, 0, 0, 1, 0) + mod = __import__(filter) + obj = getattr(mod, filter_name, None) + if callable(obj): + conv = obj(in_path = file, out_path = out_path) + if(conv.getStatus()): + (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) else: - print "Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter) - return + # conversion didn't work + # TODO: appropriate response? + return (0, 0, 0, 1, 0) + else: + print "Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter) + return #This will barf if conv.getStatus != True return (stored, duplicates, partial, errors, ttime)