From a5b9ea860d41bbe0bf81e7a1199962994e2ea241 Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 13 Mar 2009 06:21:48 -0400 Subject: [PATCH 01/25] fix runUpdated() to not freak out if a file disappears on it --- pyfpdb/fpdb_import.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index b8036e46..506e71ee 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -190,24 +190,26 @@ class Importer: self.addImportDirectory(self.dirlist[site][0], False, site, self.dirlist[site][1]) for file in self.filelist: - stat_info = os.stat(file) - try: - lastupdate = self.updated[file] - if stat_info.st_mtime > lastupdate: - self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) + if os.path.exists(file): + stat_info = os.stat(file) + try: + lastupdate = self.updated[file] + if stat_info.st_mtime > lastupdate: + self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) + self.updated[file] = time() + except: self.updated[file] = time() - except: - self.updated[file] = time() - # If modified in the last minute run an immediate import. - # This codepath only runs first time the file is found. - if os.path.isdir(file) or (time() - stat_info.st_mtime) < 60: - # TODO attach a HHC thread to the file - # TODO import the output of the HHC thread -- this needs to wait for the HHC to block? - self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) + # If modified in the last minute run an immediate import. + # This codepath only runs first time the file is found. + if os.path.isdir(file) or (time() - stat_info.st_mtime) < 60: + # TODO attach a HHC thread to the file + # TODO import the output of the HHC thread -- this needs to wait for the HHC to block? + self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) # TODO we also test if directory, why? #if os.path.isdir(file): #self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) - + else: + removeFromFileList[file] = True self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList) for file in self.removeFromFileList: From 69c026bd29b79444ed6e22e91b092b417fb941c2 Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 13 Mar 2009 18:05:27 -0400 Subject: [PATCH 02/25] remove "import Utils" --- pyfpdb/Hud.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index c9e0ea07..ac9a53a3 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -44,7 +44,6 @@ import Stats import Mucked import Database import HUD_main -import Utils def importName(module_name, name, params): """Import a named object 'name' from module 'module_name'.""" From 79d9bd6d58b066aa1fb8d4601a7a5254910f0499 Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 13 Mar 2009 18:09:25 -0400 Subject: [PATCH 03/25] make third parameter to importName() optional --- pyfpdb/Hud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index ac9a53a3..a8591041 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -45,7 +45,7 @@ import Mucked import Database import HUD_main -def importName(module_name, name, params): +def importName(module_name, name, *params): """Import a named object 'name' from module 'module_name'.""" # Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! # Modded by Carl G to support additional params From 80c3922bc09e7b3b2a44237418f54e4fef286f18 Mon Sep 17 00:00:00 2001 From: eblade Date: Mon, 16 Mar 2009 18:35:56 -0400 Subject: [PATCH 04/25] remove pyc, merge with everyone else remove some useless junk in fpdb.display_tab() --- pyfpdb/HandHistoryConverter.pyc | Bin 10310 -> 0 bytes pyfpdb/fpdb.py | 29 ++++++++++------------------- 2 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 pyfpdb/HandHistoryConverter.pyc diff --git a/pyfpdb/HandHistoryConverter.pyc b/pyfpdb/HandHistoryConverter.pyc deleted file mode 100644 index cecce850bd34cf39a3de334ca43c043c978ef648..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10310 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 diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index f1ff7e1a..5cdd3d3b 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -81,23 +81,13 @@ class fpdb: def display_tab(self, new_tab_name): """displays the indicated tab""" #print "start of display_tab, len(self.tab_names):",len(self.tab_names) - tab_no=-1 - #if len(self.tab_names)>1: - for i in range(len(self.tab_names)): - #print "display_tab, new_tab_name:",new_tab_name," self.tab_names[i]:", self.tab_names[i] - if (new_tab_name==self.tab_names[i]): - tab_no=i - #self.tab_buttons[i].set_active(False) - #else: - # tab_no=0 + tab_no = -1 + for i, name in enumerate(self.tab_names): + if name == new_tab_name: + tab_no = i + break - #current_tab_no=-1 - for i in range(len(self.tab_names)): - if self.current_tab==self.tabs[i]: - #self.tab_buttons[i].set_active(False) - pass - - if tab_no==-1: + if tab_no == -1: raise fpdb_simple.FpdbError("invalid tab_no") else: self.main_vbox.remove(self.current_tab) @@ -199,12 +189,13 @@ class fpdb: def dia_recreate_tables(self, widget, data): """Dialogue that asks user to confirm that he wants to delete and recreate the tables""" self.obtain_global_lock() - dia_confirm=gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, + + dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm deleting and recreating tables") - diastring=("Please confirm that you want to (re-)create the tables. If there already are tables in the database "+self.db.database+" on "+self.db.host+" they will be deleted.") + diastring = "Please confirm that you want to (re-)create the tables. If there already are tables in the database "+self.db.database+" on "+self.db.host+" they will be deleted." dia_confirm.format_secondary_text(diastring)#todo: make above string with bold for db, host and deleted - response=dia_confirm.run() + response = dia_confirm.run() dia_confirm.destroy() if response == gtk.RESPONSE_YES: self.db.recreate_tables() From 8e5396295d39d9c8bd2010f236e31bcdc43eabd5 Mon Sep 17 00:00:00 2001 From: eblade Date: Mon, 16 Mar 2009 20:52:50 -0400 Subject: [PATCH 05/25] some silly cleanup --- pyfpdb/fpdb_db.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 6f934819..771b79fa 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -23,12 +23,12 @@ import FpdbSQLQueries class fpdb_db: def __init__(self): """Simple constructor, doesnt really do anything""" - self.db=None - self.cursor=None - self.sql = {} - self.MYSQL_INNODB=2 - self.PGSQL=3 - self.SQLITE=4 + self.db = None + self.cursor = None + self.sql = {} + self.MYSQL_INNODB = 2 + self.PGSQL = 3 + self.SQLITE = 4 #end def __init__ def do_connect(self, config=None): @@ -37,10 +37,7 @@ class fpdb_db: raise FpdbError('Configuration not defined') self.settings = {} - if (os.sep=="/"): - self.settings['os']="linuxmac" - else: - self.settings['os']="windows" + self.settings['os'] = "linuxmac" if os.name != "nt" else "windows" self.settings.update(config.get_db_parameters()) self.connect(self.settings['db-backend'], From a424a9c77d0ce545e3e94d82f98776dc754fed61 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 17:07:32 -0400 Subject: [PATCH 06/25] fpdb_parse_logic: cleanup --- pyfpdb/fpdb_parse_logic.py | 153 ++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 78 deletions(-) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index 9dd54f83..180bde47 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -22,47 +22,46 @@ import fpdb_save_to_db #parses a holdem hand def mainParser(backend, db, cursor, site, category, hand, config): - category=fpdb_simple.recogniseCategory(hand[0]) - if (category=="holdem" or category=="omahahi" or category=="omahahilo"): - base="hold" - else: - base="stud" + category = fpdb_simple.recogniseCategory(hand[0]) + + base = "hold" if category == "holdem" or category == "omahahi" or ctegory == "omahahilo" else "stud" + #part 0: create the empty arrays - lineTypes=[] #char, valid values: header, name, cards, action, win, rake, ignore - lineStreets=[] #char, valid values: (predeal, preflop, flop, turn, river) + lineTypes = [] #char, valid values: header, name, cards, action, win, rake, ignore + lineStreets = [] #char, valid values: (predeal, preflop, flop, turn, river) cardValues, cardSuits, boardValues, boardSuits, antes, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo, seatLines, winnings, rakes=[],[],[],[],[],[],[],[],[],[],[],[],[] #part 1: read hand no and check for duplicate - siteHandNo=fpdb_simple.parseSiteHandNo(hand[0]) - handStartTime=fpdb_simple.parseHandStartTime(hand[0], site) - siteID=fpdb_simple.recogniseSiteID(cursor, site) + siteHandNo = fpdb_simple.parseSiteHandNo(hand[0]) + handStartTime = fpdb_simple.parseHandStartTime(hand[0], site) + siteID = fpdb_simple.recogniseSiteID(cursor, site) #print "parse logic, siteID:",siteID,"site:",site - isTourney=fpdb_simple.isTourney(hand[0]) - smallBlindLine=0 - for i in range(len(hand)): - if 'posts small blind' in hand[i] or 'posts the small blind' in hand[i]: - if hand[i][-2:] == "$0": - continue - smallBlindLine=i - #print "found small blind line:",smallBlindLine + isTourney = fpdb_simple.isTourney(hand[0]) + smallBlindLine = 0 + for i, line in enumerate(hand): + if 'posts small blind' in line or 'posts the small blind' in line: + if line[-2:] == "$0": continue + smallBlindLine = i 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, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney) if isTourney: - if site!="ps": + if site != "ps": raise fpdb_simple.FpdbError("tourneys are only supported on PS right now") - siteTourneyNo=fpdb_simple.parseTourneyNo(hand[0]) - buyin=fpdb_simple.parseBuyin(hand[0]) - fee=fpdb_simple.parseFee(hand[0]) - entries=-1 #todo: parse this - prizepool=-1 #todo: parse this - knockout=0 - tourneyStartTime=handStartTime #todo: read tourney start time - rebuyOrAddon=fpdb_simple.isRebuyOrAddon(hand[0]) + siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0]) + buyin = fpdb_simple.parseBuyin(hand[0]) + fee = fpdb_simple.parseFee(hand[0]) + entries = -1 #todo: parse this + prizepool = -1 #todo: parse this + knockout = 0 + 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(cursor, siteID, buyin, fee, knockout, rebuyOrAddon) + fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo) #part 2: classify lines by type (e.g. cards, action, win, sectionchange) and street @@ -70,85 +69,83 @@ def mainParser(backend, db, cursor, site, category, hand, config): #part 3: read basic player info #3a read player names, startcashes - for i in range (len(hand)): #todo: use maxseats+1 here. - if (lineTypes[i]=="name"): - seatLines.append(hand[i]) - names=fpdb_simple.parseNames(seatLines) - playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID) - tmp=fpdb_simple.parseCashesAndSeatNos(seatLines, site) - startCashes=tmp['startCashes'] - seatNos=tmp['seatNos'] + for i, line in enumerate(hand): + if lineTypes[i] == "name": + seatLines.append(line) + + names = fpdb_simple.parseNames(seatLines) + playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID) + tmp = fpdb_simple.parseCashesAndSeatNos(seatLines, site) + startCashes = tmp['startCashes'] + seatNos = tmp['seatNos'] fpdb_simple.createArrays(category, len(names), cardValues, cardSuits, antes, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo) #3b read positions - if base=="hold": - positions = fpdb_simple.parsePositions (hand, names) + if base == "hold": + positions = fpdb_simple.parsePositions(hand, names) #part 4: take appropriate action for each line based on linetype - for i in range(len(hand)): - if (lineTypes[i]=="cards"): - fpdb_simple.parseCardLine (site, category, lineStreets[i], hand[i], names, cardValues, cardSuits, boardValues, boardSuits) + for i, line in enumerate(hand): + if lineTypes[i] == "cards": + fpdb_simple.parseCardLine(site, category, lineStreets[i], line, names, cardValues, cardSuits, boardValues, boardSuits) #if category=="studhilo": # print "hand[i]:", hand[i] # print "cardValues:", cardValues # print "cardSuits:", cardSuits - elif (lineTypes[i]=="action"): - fpdb_simple.parseActionLine (site, base, isTourney, hand[i], lineStreets[i], playerIDs, names, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo) - elif (lineTypes[i]=="win"): - fpdb_simple.parseWinLine (hand[i], site, names, winnings, isTourney) - elif (lineTypes[i]=="rake"): - if isTourney: - totalRake=0 - else: - totalRake=fpdb_simple.parseRake(hand[i]) + elif lineTypes[i] == "action": + fpdb_simple.parseActionLine(site, base, isTourney, line, lineStreets[i], playerIDs, names, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo) + elif lineTypes[i] == "win": + fpdb_simple.parseWinLine(line, site, names, winnings, isTourney) + elif lineTypes[i] == "rake": + totalRake = 0 if isTourney else fpdb_simple.parseRake(line) fpdb_simple.splitRake(winnings, rakes, totalRake) - elif (lineTypes[i]=="header" or lineTypes[i]=="rake" or lineTypes[i]=="name" or lineTypes[i]=="ignore"): + elif lineTypes[i]=="header" or lineTypes[i]=="rake" or lineTypes[i]=="name" or lineTypes[i]=="ignore": pass - elif (lineTypes[i]=="ante"): - fpdb_simple.parseAnteLine(hand[i], site, isTourney, names, antes) - elif (lineTypes[i]=="table"): - tableResult=fpdb_simple.parseTableLine(site, base, hand[i]) + elif lineTypes[i]=="ante": + fpdb_simple.parseAnteLine(line, site, isTourney, names, antes) + elif lineTypes[i]=="table": + tableResult=fpdb_simple.parseTableLine(site, base, line) else: raise fpdb_simple.FpdbError("unrecognised lineType:"+lineTypes[i]) - if site=="ftp": - tableResult=fpdb_simple.parseTableLine(site, base, hand[0]) - maxSeats=tableResult['maxSeats'] - tableName=tableResult['tableName'] + + if site == "ftp": + tableResult = fpdb_simple.parseTableLine(site, base, hand[0]) + + maxSeats = tableResult['maxSeats'] + tableName = tableResult['tableName'] #print "before part5, antes:", antes #part 5: final preparations, then call fpdb_save_to_db.* with # the arrays as they are - that file will fill them. fpdb_simple.convertCardValues(cardValues) - if base=="hold": + if base == "hold": fpdb_simple.convertCardValuesBoard(boardValues) fpdb_simple.convertBlindBet(actionTypes, actionAmounts) fpdb_simple.checkPositions(positions) cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, )) - limit_type=cursor.fetchone()[0] + limit_type = cursor.fetchone()[0] fpdb_simple.convert3B4B(site, category, limit_type, actionTypes, actionAmounts) - totalWinnings=0 - for i in range(len(winnings)): - totalWinnings+=winnings[i] + totalWinnings = sum(winnings) - if base=="hold": - hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes + # if hold'em, use positions and not antes, if stud do not use positions, use antes + if base == "hold": + hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes , allIns, actionTypeByNo, winnings, totalWinnings, positions , actionTypes, actionAmounts, None) else: - hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes + hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes , allIns, actionTypeByNo, winnings, totalWinnings, None , actionTypes, actionAmounts, antes) if isTourney: - ranks=[] - for i in range (len(names)): - ranks.append(0) - payin_amounts=fpdb_simple.calcPayin(len(names), buyin, fee) + ranks = [] + map(lambda x: 0, names) # create an array of 0's equal to the length of names + payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee) - if base=="hold": + if base == "hold": result = fpdb_save_to_db.tourney_holdem_omaha( config, backend, db, cursor, base, category, siteTourneyNo, buyin , fee, knockout, entries, prizepool, tourneyStartTime @@ -157,7 +154,7 @@ def mainParser(backend, db, cursor, site, category, hand, config): , positions, cardValues, cardSuits, boardValues, boardSuits , winnings, rakes, actionTypes, allIns, actionAmounts , actionNos, hudImportData, maxSeats, tableName, seatNos) - elif base=="stud": + elif base == "stud": result = fpdb_save_to_db.tourney_stud( config, backend, db, cursor, base, category, siteTourneyNo , buyin, fee, knockout, entries, prizepool, tourneyStartTime @@ -167,9 +164,9 @@ def mainParser(backend, db, cursor, site, category, hand, config): , allIns, actionAmounts, actionNos, hudImportData, maxSeats , tableName, seatNos) else: - raise fpdb_simple.FpdbError ("unrecognised category") + raise fpdb_simple.FpdbError("unrecognised category") # it's impossible to get here, but w/e else: - if base=="hold": + if base == "hold": result = fpdb_save_to_db.ring_holdem_omaha( config, backend, db, cursor, base, category, siteHandNo , gametypeID, handStartTime, names, playerIDs @@ -177,7 +174,7 @@ def mainParser(backend, db, cursor, site, category, hand, config): , boardValues, boardSuits, winnings, rakes , actionTypes, allIns, actionAmounts, actionNos , hudImportData, maxSeats, tableName, seatNos) - elif base=="stud": + elif base == "stud": result = fpdb_save_to_db.ring_stud( config, backend, db, cursor, base, category, siteHandNo, gametypeID , handStartTime, names, playerIDs, startCashes, antes @@ -185,7 +182,7 @@ def mainParser(backend, db, cursor, site, category, hand, config): , actionAmounts, actionNos, hudImportData, maxSeats, tableName , seatNos) else: - raise fpdb_simple.FpdbError ("unrecognised category") + raise fpdb_simple.FpdbError ("unrecognised category") # also impossible to get here db.commit() return result #end def mainParser From 1b626271ee12e99aa66dfba973f945002d6e4c2a Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 17:15:21 -0400 Subject: [PATCH 07/25] fpdb_save_to_db: minor cleanup --- pyfpdb/fpdb_save_to_db.py | 75 ++++++++++++++------------------------- 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index b215f7ee..f13c8032 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -22,13 +22,13 @@ from time import time import fpdb_simple -MYSQL_INNODB=2 -PGSQL=3 -SQLITE=4 +MYSQL_INNODB = 2 +PGSQL = 3 +SQLITE = 4 -fastStoreHudCache=True # set this to True to test the new storeHudCache routine +fastStoreHudCache = True # set this to True to test the new storeHudCache routine -saveActions=False # set this to False to avoid storing action data +saveActions = False # 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 @@ -40,22 +40,17 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp ,seatNos): import_options = config.get_import_parameters() - if import_options['saveActions'] == 'True': - saveActions = True - else: - saveActions = False - if import_options['fastStoreHudCache'] == 'True': - fastStoreHudCache = True - else: - fastStoreHudCache = False + + 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) - hands_id=fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id + hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id ,hand_start_time, names, tableName, maxSeats) #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(backend, db, cursor, hands_id, player_ids ,start_cashes, antes, card_values ,card_suits, winnings, rakes, seatNos) @@ -74,14 +69,8 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, """stores a holdem/omaha hand into the database""" import_options = config.get_import_parameters() - if import_options['saveActions'] == 'True': - saveActions = True - else: - saveActions = False - if import_options['fastStoreHudCache'] == 'True': - fastStoreHudCache = True - else: - fastStoreHudCache = False + saveActions = True if import_options['saveActions'] == 'True' else False + fastStoreHudCache = True if import_options['fastStoreHudCache'] == 'True' else False t0 = time() fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) @@ -89,10 +78,10 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, 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(backend, db, cursor, site_hand_no, gametype_id ,hand_start_time, names, tableName, maxSeats) t3 = time() - hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha( + 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) t4 = time() @@ -121,25 +110,19 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne """stores a tourney holdem/omaha hand into the database""" import_options = config.get_import_parameters() - if import_options['saveActions'] == 'True': - saveActions = True - else: - saveActions = False - if import_options['fastStoreHudCache'] == 'True': - fastStoreHudCache = True - else: - fastStoreHudCache = False + 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) + 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(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( + 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) @@ -164,24 +147,18 @@ def tourney_stud(config, backend, db, cursor, base, category, siteTourneyNo, buy #stores a tourney stud/razz hand into the database import_options = config.get_import_parameters() - if import_options['saveActions'] == 'True': - saveActions = True - else: - saveActions = False - if import_options['fastStoreHudCache'] == 'True': - fastStoreHudCache = True - else: - fastStoreHudCache = False + 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) + 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) + 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(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(backend, db, cursor, hands_id , playerIds, startCashes, antes, cardValues, cardSuits , winnings, rakes, seatNos, tourneys_players_ids) From 8b933bbd7b6ad1ed8a792e0ee8213ddb1f483d70 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 21:22:04 -0400 Subject: [PATCH 08/25] fpdb_import: formatting cleanup fpdb_simple: significant performance enhancements likely in checkPositions, convertCardValuesBoard, filterCrap, float2int, isActionLine, isWinLine --- pyfpdb/fpdb_import.py | 24 +-- pyfpdb/fpdb_simple.py | 336 ++++++++++++++++-------------------------- 2 files changed, 141 insertions(+), 219 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index b7212f4a..9eaa1fcd 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -51,22 +51,22 @@ class Importer: def __init__(self, caller, settings, config): """Constructor""" - self.settings=settings - self.caller=caller - self.config = config - self.fdb = None - self.cursor = None - self.filelist = {} - self.dirlist = {} + self.settings = settings + self.caller = caller + self.config = config + self.fdb = None + self.cursor = None + self.filelist = {} + self.dirlist = {} self.addToDirList = {} self.removeFromFileList = {} # to remove deleted files - self.monitor = False - self.updated = {} #Time last import was run {file:mtime} - self.lines = None - self.faobs = None #File as one big string + self.monitor = False + self.updated = {} #Time last import was run {file:mtime} + self.lines = None + self.faobs = None #File as one big string self.pos_in_file = {} # dict to remember how far we have read in the file #Set defaults - self.callHud = self.config.get_import_parameters().get("callFpdbHud") + self.callHud = self.config.get_import_parameters().get("callFpdbHud") if 'minPrint' not in self.settings: #TODO: Is this value in the xml file? self.settings['minPrint'] = 30 diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 2677d11b..c47b6c86 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -18,14 +18,17 @@ #This file contains simple functions for fpdb import datetime +import time import re -PS=1 -FTP=2 +PS = 1 +FTP = 2 + +# TODO: these constants are also used in fpdb_save_to_db and others, is there a way to do like C #define, and #include ? +MYSQL_INNODB = 2 +PGSQL = 3 +SQLITE = 4 -MYSQL_INNODB=2 -PGSQL=3 -SQLITE=4 # Data Structures for index and foreign key creation # drop_code is an int with possible values: 0 - don't drop for bulk import # 1 - drop during bulk import @@ -384,27 +387,20 @@ def calcPayin(count, buyin, fee): result.append (buyin+fee) return result #end def calcPayin - + def checkPositions(positions): - """verifies that these positions are valid""" - for i in xrange(len(positions)): - pos=positions[i] - try:#todo: use type recognition instead of error - if (len(pos)!=1): - raise FpdbError("invalid position found in checkPositions. i: "+str(i)+" position: "+pos) #dont need to str() here - except TypeError:#->not string->is int->fine - pass - - ### RHH modified to allow for "position 9" here (pos==9 is when you're a dead hand before the BB - ### eric - position 8 could be valid - if only one blind is posted, but there's still 10 people, ie a sitout is present, and the small is dead... - if not (pos == "B" or pos == "S" or (pos >= 0 and pos <= 9)): - raise FpdbError("invalid position found in checkPositions. i: "+str(i)+" position: "+str(pos)) -#end def fpdb_simple.checkPositions + """ verify positions are valid """ + for p in positions: + if not (p == "B" or p == "S" or (p >= 0 and p <= 9)): + raise FpdbError("invalid position '" + p + "' found in checkPositions") + + ### RHH modified to allow for "position 9" here (pos==9 is when you're a dead hand before the BB + ### eric - position 8 could be valid - if only one blind is posted, but there's still 10 people, ie a sitout is present, and the small is dead... #classifies each line for further processing in later code. Manipulates the passed arrays. def classifyLines(hand, category, lineTypes, lineStreets): - currentStreet="predeal" - done=False #set this to true once we reach the last relevant line (the summary, except rake, is all repeats) + currentStreet = "predeal" + done = False #set this to true once we reach the last relevant line (the summary, except rake, is all repeats) for i, line in enumerate(hand): if done: if "[" not in line or "mucked [" not in line: @@ -518,19 +514,10 @@ def convertCardValues(arr): #converts the strings in the given array to ints (changes the passed array, no returning). see table design for conversion details def convertCardValuesBoard(arr): + # TODO: this could probably be useful in many places, it should be a constant somewhere maybe? + card_map = { "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, "9" : 9, "T" : 10, "J" : 11, "Q" : 12, "K" : 13, "A" : 14} for i in xrange(len(arr)): - if (arr[i]=="A"): - arr[i]=14 - elif (arr[i]=="K"): - arr[i]=13 - elif (arr[i]=="Q"): - arr[i]=12 - elif (arr[i]=="J"): - arr[i]=11 - elif (arr[i]=="T"): - arr[i]=10 - else: - arr[i]=int(arr[i]) + arr[i] = card_map[arr[i]] #end def convertCardValuesBoard #this creates the 2D/3D arrays. manipulates the passed arrays instead of returning. @@ -544,10 +531,7 @@ def createArrays(category, seats, card_values, card_suits, antes, winnings, rake winnings.append(0) rakes.append(0) - if (category=="holdem" or category=="omahahi" or category=="omahahilo"): - streetCount=4 - else: - streetCount=5 + streetCount = 4 if category == "holdem" or category == "omahahi" or category == "omahahilo" else 5 for i in xrange(streetCount): #build the first dimension array, for streets tmp=[] @@ -569,15 +553,15 @@ def createArrays(category, seats, card_values, card_suits, antes, winnings, rake action_amounts[i].append(tmp) tmp=[] actionNos[i].append(tmp) - if (category=="holdem" or category=="omahahi" or category=="omahahilo"): - pass - elif (category=="razz" or category=="studhi" or category=="studhilo"):#need to fill card arrays. +# if (category=="holdem" or category=="omahahi" or category=="omahahilo"): +# pass + if category=="razz" or category=="studhi" or category=="studhilo":#need to fill card arrays. for i in xrange(seats): - for j in xrange (7): + for j in xrange(7): card_values[i].append(0) card_suits[i].append("x") - else: - raise FpdbError("invalid category") +# else: +# raise FpdbError("invalid category") #end def createArrays def fill_board_cards(board_values, board_suits): @@ -590,16 +574,16 @@ def fill_board_cards(board_values, board_suits): def fillCardArrays(player_count, base, category, card_values, card_suits): """fills up the two card arrays""" if (category=="holdem"): - cardCount=2 + cardCount = 2 elif (category=="omahahi" or category=="omahahilo"): - cardCount=4 + cardCount = 4 elif base=="stud": - cardCount=7 + cardCount = 7 else: - raise fpdb_simple.FpdbError ("invalid category:", category) + raise fpdb_simple.FpdbError("invalid category:", category) - for i in xrange (player_count): - while (len(card_values[i]) 0 +# ret = any(True for searchstr in ActionLines if searchstr in line) +# ret = len( [ x for x in ActionLines if line.find(x) > -1] ) > 0 +# ret = any(searchstr in line for searchstr in ActionLines) #end def isActionLine #returns whether this is a duplicate @@ -828,56 +795,14 @@ def isRebuyOrAddon(topline): #returns whether the passed topline indicates a tournament or not def isTourney(topline): - if (topline.find("Tournament")!=-1): - return True - else: - return False + return "Tournament" in topline #end def isTourney +WinLines = ( "wins the pot", "ties for the ", "wins side pot", "wins the low main pot", "wins the high main pot", + "wins the high pot", "wins the high side pot", "wins the main pot", "wins the side pot", "collected" ) #returns boolean whether the passed line is a win line def isWinLine(line): - if (line.find("wins the pot")!=-1): - return True - elif (line.find("ties for the high pot")!=-1): - return True - elif (line.find("ties for the high main pot")!=-1): - return True - elif (line.find("ties for the high side pot")!=-1): - return True - elif (line.find("ties for the low pot")!=-1): - return True - elif (line.find("ties for the low main pot")!=-1): - return True - elif (line.find("ties for the low side pot")!=-1): - return True - elif (line.find("ties for the main pot")!=-1): #for ftp tied main pot of split pot - return True - elif (line.find("ties for the pot")!=-1): #for ftp tie - return True - elif (line.find("ties for the side pot")!=-1): #for ftp tied split pots - return True - elif (line.find("wins side pot #")!=-1): #for ftp multi split pots - return True - elif (line.find("wins the low main pot")!=-1): - return True - elif (line.find("wins the low pot")!=-1): - return True - elif (line.find("wins the low side pot")!=-1): - return True - elif (line.find("wins the high main pot")!=-1): - return True - elif (line.find("wins the high pot")!=-1): - return True - elif (line.find("wins the high side pot")!=-1): - return True - elif (line.find("wins the main pot")!=-1): - return True - elif (line.find("wins the side pot")!=-1): #for ftp split pots - return True - elif (line.find("collected")!=-1): - return True - else: - return False #not raising error here, any unknown line wouldve been detected in isActionLine already + return len( [ x for x in WinLines if x in line ] ) > 0 #end def isWinLine #returns the amount of cash/chips put into the put in the given action line @@ -892,23 +817,20 @@ def parseActionAmount(line, atype, site, isTourney): if line.endswith(" and is capped"): line=line[:-14] - - if (atype=="fold"): - amount=0 - elif (atype=="check"): - amount=0 - elif (atype=="unbet" and site=="ftp"): - pos1=line.find("$")+1 - pos2=line.find(" returned to") - amount=float2int(line[pos1:pos2]) - elif (atype=="unbet" and site=="ps"): - #print "ps unbet, line:",line - pos1=line.find("$")+1 - if pos1==0: - pos1=line.find("(")+1 - pos2=line.find(")") - amount=float2int(line[pos1:pos2]) - elif (atype=="bet" and site=="ps" and line.find(": raises $")!=-1 and line.find("to $")!=-1): + if atype == "fold" or atype == "check": + amount = 0 + elif atype == "unbet": + if site == "ftp": + pos1 = line.find("$") + 1 + pos2 = line.find(" returned to") + amount = float2int(line[pos1:pos2]) + elif site == "ps": + pos1 = line.find("$") + 1 + if pos1 == 0: + pos1 = line.find("(") + 1 + pos2 = line.find(")") + amount = float2int(line[pos1:pos2]) + elif atype == "bet" and site == "ps" and line.find(": raises $")!=-1 and line.find("to $")!=-1: pos=line.find("to $")+4 amount=float2int(line[pos:]) else: From c6179a1b85a8963be49c637d632262989fc2dd60 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 22:05:01 -0400 Subject: [PATCH 09/25] fix typo --- pyfpdb/fpdb_parse_logic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index 180bde47..a58aba78 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -24,7 +24,7 @@ import fpdb_save_to_db def mainParser(backend, db, cursor, site, category, hand, config): category = fpdb_simple.recogniseCategory(hand[0]) - base = "hold" if category == "holdem" or category == "omahahi" or ctegory == "omahahilo" else "stud" + base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud" #part 0: create the empty arrays lineTypes = [] #char, valid values: header, name, cards, action, win, rake, ignore From 4830b7212130af550d27e497cb13bcc68570cf35 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 22:31:39 -0400 Subject: [PATCH 10/25] more cleanup --- pyfpdb/fpdb_simple.py | 260 +++++++++++++++++++++--------------------- 1 file changed, 129 insertions(+), 131 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index c47b6c86..9461d6a1 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -831,22 +831,22 @@ def parseActionAmount(line, atype, site, isTourney): pos2 = line.find(")") amount = float2int(line[pos1:pos2]) elif atype == "bet" and site == "ps" and line.find(": raises $")!=-1 and line.find("to $")!=-1: - pos=line.find("to $")+4 - amount=float2int(line[pos:]) + pos = line.find("to $")+4 + amount = float2int(line[pos:]) else: if not isTourney: - pos=line.rfind("$")+1 + pos = line.rfind("$")+1 #print "parseActionAmount, line:", line, "line[pos:]:", line[pos:] - amount=float2int(line[pos:]) + amount = float2int(line[pos:]) else: #print "line:"+line+"EOL" - pos=line.rfind(" ")+1 + pos = line.rfind(" ")+1 #print "pos:",pos #print "pos of 20:", line.find("20") - amount=int(line[pos:]) + amount = int(line[pos:]) - if atype=="unbet": - amount*=-1 + if atype == "unbet": + amount *= -1 return amount #end def parseActionAmount @@ -854,25 +854,25 @@ def parseActionAmount(line, atype, site, isTourney): # action_amounts. For stud this expects numeric streets (3-7), for # holdem/omaha it expects predeal, preflop, flop, turn or river def parseActionLine(site, base, isTourney, line, street, playerIDs, names, action_types, allIns, action_amounts, actionNos, actionTypeByNo): - if (street=="predeal" or street=="preflop"): - street=0 - elif (street=="flop"): - street=1 - elif (street=="turn"): - street=2 - elif (street=="river"): - street=3 + if street == "predeal" or street == "preflop": + street = 0 + elif street == "flop": + street = 1 + elif street == "turn": + street = 2 + elif street == "river": + street = 3 - nextActionNo=0 + nextActionNo = 0 for player in xrange(len(actionNos[street])): for count in xrange(len(actionNos[street][player])): if actionNos[street][player][count]>=nextActionNo: nextActionNo=actionNos[street][player][count]+1 - line, allIn=goesAllInOnThisLine(line) - atype=parseActionType(line) - playerno=recognisePlayerNo(line, names, atype) - amount=parseActionAmount(line, atype, site, isTourney) + (line, allIn) = goesAllInOnThisLine(line) + atype = parseActionType(line) + playerno = recognisePlayerNo(line, names, atype) + amount = parseActionAmount(line, atype, site, isTourney) action_types[street][playerno].append(atype) allIns[street][playerno].append(allIn) @@ -884,13 +884,13 @@ def parseActionLine(site, base, isTourney, line, street, playerIDs, names, actio def goesAllInOnThisLine(line): """returns whether the player went all-in on this line and removes the all-in text from the line.""" - isAllIn=False + isAllIn = False if (line.endswith(" and is all-in")): - line=line[:-14] - isAllIn=True + line = line[:-14] + isAllIn = True elif (line.endswith(", and is all in")): - line=line[:-15] - isAllIn=True + line = line[:-15] + isAllIn = True return (line, isAllIn) #end def goesAllInOnThisLine @@ -934,48 +934,48 @@ def parseActionType(line): #parses the ante out of the given line and checks which player paid it, updates antes accordingly. def parseAnteLine(line, site, isTourney, names, antes): - for i in xrange(len(names)): - if (line.startswith(names[i].encode("latin-1"))): #found the ante'er - pos=line.rfind("$")+1 + for i, name in enumerate(names): + if line.startswith(name.encode("latin-1")): + pos = line.rfind("$") + 1 if not isTourney: - antes[i]+=float2int(line[pos:]) + antes[i] += float2int(line[pos:]) else: - if line.find("all-in")==-1: - pos=line.rfind(" ")+1 - antes[i]+=int(line[pos:]) + if "all-in" not in line: + pos = line.rfind(" ") + 1 + antes[i] += int(line[pos:]) else: - pos1=line.rfind("ante")+5 - pos2=line.find(" ",pos1) - antes[i]+=int(line[pos1:pos2]) + pos1 = line.rfind("ante") + 5 + pos2 = line.find(" ", pos1) + antes[i] += int(line[pos1:pos2]) #print "parseAnteLine line: ", line, "antes[i]", antes[i], "antes", antes #end def parseAntes #returns the buyin of a tourney in cents def parseBuyin(topline): - pos1=topline.find("$")+1 - pos2=topline.find("+") + pos1 = topline.find("$")+1 + pos2 = topline.find("+") return float2int(topline[pos1:pos2]) #end def parseBuyin #parses a card line and changes the passed arrays accordingly #todo: reorganise this messy method def parseCardLine(site, category, street, line, names, cardValues, cardSuits, boardValues, boardSuits): - if (line.startswith("Dealt to ") or line.find(" shows [")!=-1 or line.find("mucked [")!=-1): - playerNo=recognisePlayerNo(line, names, "card") #anything but unbet will be ok for that string + if line.startswith("Dealt to") or " shows [" in line or "mucked [" in line: + playerNo = recognisePlayerNo(line, names, "card") #anything but unbet will be ok for that string - pos=line.rfind("[")+1 - if (category=="holdem"): + pos = line.rfind("[")+1 + if category == "holdem": for i in (pos, pos+3): cardValues[playerNo].append(line[i:i+1]) cardSuits[playerNo].append(line[i+1:i+2]) - if (len(cardValues[playerNo])!=2): + if len(cardValues[playerNo]) !=2: if cardValues[playerNo][0]==cardValues[playerNo][2] and cardSuits[playerNo][1]==cardSuits[playerNo][3]: #two tests will do cardValues[playerNo]=cardValues[playerNo][0:2] cardSuits[playerNo]=cardSuits[playerNo][0:2] else: print "line:",line,"cardValues[playerNo]:",cardValues[playerNo] raise FpdbError("read too many/too few holecards in parseCardLine") - elif (category=="omahahi" or category=="omahahilo"): + elif category == "omahahi" or category == "omahahilo": for i in (pos, pos+3, pos+6, pos+9): cardValues[playerNo].append(line[i:i+1]) cardSuits[playerNo].append(line[i+1:i+2]) @@ -986,8 +986,8 @@ def parseCardLine(site, category, street, line, names, cardValues, cardSuits, bo else: print "line:",line,"cardValues[playerNo]:",cardValues[playerNo] raise FpdbError("read too many/too few holecards in parseCardLine") - elif (category=="razz" or category=="studhi" or category=="studhilo"): - if (line.find("shows")==-1 and line.find("mucked")==-1): + elif category=="razz" or category=="studhi" or category=="studhilo": + if "shows" not in line and "mucked" not in line: #print "parseCardLine(in stud if), street:", street if line[pos+2]=="]": #-> not (hero and 3rd street) cardValues[playerNo][street+2]=line[pos:pos+1] @@ -1126,85 +1126,81 @@ def parseNames(lines): return result #end def parseNames -#returns an array with the positions of the respective players -def parsePositions (hand, names): - #prep array - positions=[] - for i in xrange(len(names)): - positions.append(-1) - - #find blinds - sb,bb=-1,-1 - for i in xrange (len(hand)): - if (sb==-1 and hand[i].find("small blind")!=-1 and hand[i].find("dead small blind")==-1): - sb=hand[i] - #print "sb:",sb - if (bb==-1 and hand[i].find("big blind")!=-1 and hand[i].find("dead big blind")==-1): - bb=hand[i] - #print "bb:",bb +def parsePositions(hand, names): + positions = map(lambda x: -1, names) - #identify blinds - #print "parsePositions before recognising sb/bb. names:",names - sbExists=True - if (sb!=-1): - sb=recognisePlayerNo(sb, names, "bet") - else: - sbExists=False - if (bb!=-1): - bb=recognisePlayerNo(bb, names, "bet") - + #find blinds + sb,bb=-1,-1 + for i in xrange (len(hand)): + if (sb==-1 and hand[i].find("small blind")!=-1 and hand[i].find("dead small blind")==-1): + sb=hand[i] + #print "sb:",sb + if (bb==-1 and hand[i].find("big blind")!=-1 and hand[i].find("dead big blind")==-1): + bb=hand[i] + #print "bb:",bb + +#identify blinds +#print "parsePositions before recognising sb/bb. names:",names + sbExists=True + if (sb!=-1): + sb=recognisePlayerNo(sb, names, "bet") + else: + sbExists=False + if (bb!=-1): + bb=recognisePlayerNo(bb, names, "bet") + # print "sb = ", sb, "bb = ", bb - if bb == sb: - sbExists = False - sb = -1 - - #write blinds into array - if (sbExists): - positions[sb]="S" - positions[bb]="B" - - - #fill up rest of array - if (sbExists): - arraypos=sb-1 - else: - arraypos=bb-1 - distFromBtn=0 - while (arraypos>=0 and arraypos != bb): - #print "parsePositions first while, arraypos:",arraypos,"positions:",positions - positions[arraypos]=distFromBtn - arraypos-=1 - distFromBtn+=1 + if bb == sb: + sbExists = False + sb = -1 - # eric - this takes into account dead seats between blinds - if sbExists: - i = bb - 1 - while positions[i] < 0 and i != sb: - positions[i] = 9 - i -= 1 - ### RHH - Changed to set the null seats before BB to "9" - if sbExists: - i = sb-1 - else: - i = bb-1 - while positions[i] < 0: - positions[i]=9 - i-=1 - - arraypos=len(names)-1 - if (bb!=0 or (bb==0 and sbExists==False) or (bb == 1 and sb != arraypos) ): - while (arraypos>bb and arraypos > sb): - positions[arraypos]=distFromBtn - arraypos-=1 - distFromBtn+=1 - - for i in xrange (len(names)): - if positions[i]==-1: - print "parsePositions names:",names - print "result:",positions - raise FpdbError ("failed to read positions") + #write blinds into array + if (sbExists): + positions[sb]="S" + positions[bb]="B" + + + #fill up rest of array + if (sbExists): + arraypos=sb-1 + else: + arraypos=bb-1 + distFromBtn=0 + while (arraypos>=0 and arraypos != bb): + #print "parsePositions first while, arraypos:",arraypos,"positions:",positions + positions[arraypos]=distFromBtn + arraypos-=1 + distFromBtn+=1 + + # eric - this takes into account dead seats between blinds + if sbExists: + i = bb - 1 + while positions[i] < 0 and i != sb: + positions[i] = 9 + i -= 1 + ### RHH - Changed to set the null seats before BB to "9" + if sbExists: + i = sb-1 + else: + i = bb-1 + while positions[i] < 0: + positions[i]=9 + i-=1 + + arraypos=len(names)-1 + if (bb!=0 or (bb==0 and sbExists==False) or (bb == 1 and sb != arraypos) ): + while (arraypos>bb and arraypos > sb): + positions[arraypos]=distFromBtn + arraypos-=1 + distFromBtn+=1 + + for i in xrange (len(names)): + if positions[i]==-1: + print "parsePositions names:",names + print "result:",positions + raise FpdbError ("failed to read positions") # print str(positions), "\n" - return positions + return positions #end def parsePositions #simply parses the rake amount and returns it as an int @@ -1290,18 +1286,20 @@ def parseWinLine(line, site, names, winnings, isTourney): #returns the category (as per database) string for the given line def recogniseCategory(line): - if (line.find("Razz")!=-1): + if "Razz" in line: return "razz" - elif (line.find("Hold'em")!=-1): + elif "Hold'em" in line: return "holdem" - elif (line.find("Omaha")!=-1 and line.find("Hi/Lo")==-1 and line.find("H/L")==-1): - return "omahahi" - elif (line.find("Omaha")!=-1 and (line.find("Hi/Lo")!=-1 or line.find("H/L")!=-1)): - return "omahahilo" - elif (line.find("Stud")!=-1 and line.find("Hi/Lo")==-1 and line.find("H/L")==-1): - return "studhi" - elif (line.find("Stud")!=-1 and (line.find("Hi/Lo")!=-1 or line.find("H/L")!=-1)): - return "studhilo" + elif "Omaha" in line: + if "Hi/Lo" not in line and "H/L" not in line: + return "omahahi" + else: + return "omahahilo" + elif "Stud" in line: + if "Hi/Lo" not in line and "H/L" not in line: + return "studhi" + else: + return "studhilo" else: raise FpdbError("failed to recognise category, line:"+line) #end def recogniseCategory From f823db4eefef06d8518453d3c4fd6167e995f7a6 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 23:27:15 -0400 Subject: [PATCH 11/25] generateHudCacheData: fix the code for identifying cutoff, button, sb, bb --- pyfpdb/fpdb_simple.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 9461d6a1..7c78f4c3 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1712,19 +1712,20 @@ sure to also change the following storage method and table_viewer.prepare_data i firstPfRaiserNo=-1 firstPfCallByNo=-1 firstPfCallerId=-1 - for i in xrange(len(actionTypeByNo[0])): - if actionTypeByNo[0][i][1]=="bet": - firstPfRaiseByNo=i - firstPfRaiserId=actionTypeByNo[0][i][0] - for j in xrange(len(player_ids)): - if player_ids[j]==firstPfRaiserId: - firstPfRaiserNo=j + + for i, action in enumerate(actionTypeByNo[0]): + if action[1] == "bet": + firstPfRaiseByNo = i + firstPfRaiserId = action[0] + for j, pid in enumerate(player_ids): + if pid == firstPfRaiserId: + firstPfRaiserNo = j break break - for i in xrange(len(actionTypeByNo[0])): - if actionTypeByNo[0][i][1]=="call": - firstPfCallByNo=i - firstPfCallerId=actionTypeByNo[0][i][0] + for i, action in enumerate(actionTypeByNo[0]): + if action[1] == "call": + firstPfCallByNo = i + firstPfCallerId = action[0] break cutoffId=-1 @@ -1732,15 +1733,15 @@ sure to also change the following storage method and table_viewer.prepare_data i sbId=-1 bbId=-1 if base=="hold": - for player in xrange(len(positions)): - if positions==1: - cutoffId=player_ids[player] - if positions==0: - buttonId=player_ids[player] - if positions=='S': - sbId=player_ids[player] - if positions=='B': - bbId=player_ids[player] + for player, pos in enumerate(positions): + if pos == 1: + cutoffId = player_ids[player] + if pos == 0: + buttonId = player_ids[player] + if pos == 'S': + sbId = player_ids[player] + if pos == 'B': + bbId = player_ids[player] someoneStole=False From e4ac034774111671ae0fd46aa67596e9926263a2 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 18 Mar 2009 23:48:23 -0400 Subject: [PATCH 12/25] extensive use of any() in WTSD WMSD calcs --- pyfpdb/fpdb_simple.py | 81 ++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 7c78f4c3..d94e4658 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1777,30 +1777,29 @@ sure to also change the following storage method and table_viewer.prepare_data i #calculate VPIP and PFR street=0 heroPfRaiseCount=0 - for count in xrange(len(action_types[street][player])):#finally individual actions - currentAction=action_types[street][player][count] - if currentAction=="bet": - myStreet0Aggr=True - if (currentAction=="bet" or currentAction=="call"): - myStreet0VPI=True + for currentAction in action_types[street][player]: # finally individual actions + if currentAction == "bet": + myStreet0Aggr = True + if currentAction == "bet" or currentAction == "call": + myStreet0VPI = True #PF3B4BChance and PF3B4B pfFold=-1 pfRaise=-1 - if firstPfRaiseByNo!=-1: - for i in xrange(len(actionTypeByNo[0])): - if actionTypeByNo[0][i][0]==player_ids[player]: - if actionTypeByNo[0][i][1]=="bet" and pfRaise==-1 and i>firstPfRaiseByNo: - pfRaise=i - if actionTypeByNo[0][i][1]=="fold" and pfFold==-1: - pfFold=i - if pfFold==-1 or pfFold>firstPfRaiseByNo: - myStreet0_3B4BChance=True - if pfRaise>firstPfRaiseByNo: - myStreet0_3B4BDone=True + if firstPfRaiseByNo != -1: + for i, actionType in enumerate(actionTypeByNo[0]): + if actionType[0] == player_ids[player]: + if actionType[1] == "bet" and pfRaise == -1 and i > firstPfRaiseByNo: + pfRaise = i + if actionType[1] == "fold" and pfFold == -1: + pfFold = i + if pfFold == -1 or pfFold > firstPfRaiseByNo: + myStreet0_3B4BChance = True + if pfRaise > firstPfRaiseByNo: + myStreet0_3B4BDone = True #steal calculations - if base=="hold": + if base == "hold": if len(player_ids)>=5: #no point otherwise if positions[player]==1: if firstPfRaiserId==player_ids[player]: @@ -1828,44 +1827,38 @@ sure to also change the following storage method and table_viewer.prepare_data i #calculate saw* values - isAllIn=False - for i in xrange(len(allIns[0][player])): - if allIns[0][player][i]: - isAllIn=True + isAllIn = False + if any(i for i in allIns[0][player]): + isAllIn = True if (len(action_types[1][player])>0 or isAllIn): - myStreet1Seen=True - - for i in xrange(len(allIns[1][player])): - if allIns[1][player][i]: - isAllIn=True + myStreet1Seen = True + + if any(i for i in allIns[1][player]): + isAllIn = True if (len(action_types[2][player])>0 or isAllIn): - myStreet2Seen=True + myStreet2Seen = True - for i in xrange(len(allIns[2][player])): - if allIns[2][player][i]: - isAllIn=True + if any(i for i in allIns[2][player]): + isAllIn = True if (len(action_types[3][player])>0 or isAllIn): - myStreet3Seen=True + myStreet3Seen = True #print "base:", base if base=="hold": - mySawShowdown=True - for count in xrange(len(action_types[3][player])): - if action_types[3][player][count]=="fold": - mySawShowdown=False + mySawShowdown = True + if any(actiontype == "fold" for actiontype in action_types[3][player]): + mySawShowdown = False else: #print "in else" - for i in xrange(len(allIns[3][player])): - if allIns[3][player][i]: - isAllIn=True + if any(i for i in allIns[3][player]): + isAllIn = True if (len(action_types[4][player])>0 or isAllIn): #print "in if" - myStreet4Seen=True + myStreet4Seen = True - mySawShowdown=True - for count in xrange(len(action_types[4][player])): - if action_types[4][player][count]=="fold": - mySawShowdown=False + mySawShowdown = True + if any(actiontype == "fold" for actiontype in action_types[4][player]): + mySawShowdown = False #flop stuff From 375e0ed7c9a089a2a2a7c5f6dc01ec0f7baf4d6d Mon Sep 17 00:00:00 2001 From: eblade Date: Thu, 19 Mar 2009 03:30:44 -0400 Subject: [PATCH 13/25] fpdb_parse_logic: fix possible breakage i might've made to tournament parse fpdb_simple: more usage of 'any' operator where appropriate --- pyfpdb/fpdb_parse_logic.py | 3 +-- pyfpdb/fpdb_simple.py | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index a58aba78..7d518e94 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -141,8 +141,7 @@ def mainParser(backend, db, cursor, site, category, hand, config): , actionTypes, actionAmounts, antes) if isTourney: - ranks = [] - map(lambda x: 0, names) # create an array of 0's equal to the length of names + ranks = map(lambda x: 0, names) # create an array of 0's equal to the length of names payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee) if base == "hold": diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index d94e4658..a4c440c1 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1864,9 +1864,8 @@ sure to also change the following storage method and table_viewer.prepare_data i #flop stuff street=1 if myStreet1Seen: - for count in xrange(len(action_types[street][player])): - if action_types[street][player][count]=="bet": - myStreet1Aggr=True + if any(actiontype == "bet" for actiontype in action_types[street][player]): + myStreet1Aggr = True for otherPlayer in xrange(len(player_ids)): if player==otherPlayer: @@ -1882,9 +1881,8 @@ sure to also change the following storage method and table_viewer.prepare_data i #turn stuff - copy of flop with different vars street=2 if myStreet2Seen: - for count in xrange(len(action_types[street][player])): - if action_types[street][player][count]=="bet": - myStreet2Aggr=True + if any(actiontype == "bet" for actiontype in action_types[street][player]): + myStreet2Aggr = True for otherPlayer in xrange(len(player_ids)): if player==otherPlayer: @@ -1900,9 +1898,8 @@ sure to also change the following storage method and table_viewer.prepare_data i #river stuff - copy of flop with different vars street=3 if myStreet3Seen: - for count in xrange(len(action_types[street][player])): - if action_types[street][player][count]=="bet": - myStreet3Aggr=True + if any(actiontype == "bet" for actiontype in action_types[street][player]): + myStreet3Aggr = True for otherPlayer in xrange(len(player_ids)): if player==otherPlayer: @@ -1918,9 +1915,8 @@ sure to also change the following storage method and table_viewer.prepare_data i #stud river stuff - copy of flop with different vars street=4 if myStreet4Seen: - for count in xrange(len(action_types[street][player])): - if action_types[street][player][count]=="bet": - myStreet4Aggr=True + if any(actiontype == "bet" for actiontype in action_types[street][player]): + myStreet4Aggr=True for otherPlayer in xrange(len(player_ids)): if player==otherPlayer: @@ -1933,9 +1929,9 @@ sure to also change the following storage method and table_viewer.prepare_data i if action_types[street][player][countOtherFold]=="fold": myFoldToOtherRaisedStreet4=True - if winnings[player]!=0: + if winnings[player] != 0: if myStreet1Seen: - myWonWhenSeenStreet1=winnings[player]/float(totalWinnings) + myWonWhenSeenStreet1 = winnings[player] / float(totalWinnings) if mySawShowdown: myWonAtSD=myWonWhenSeenStreet1 From 593691301bb04ec7ba9b56fd6431500e58991c12 Mon Sep 17 00:00:00 2001 From: eblade Date: Thu, 19 Mar 2009 03:40:40 -0400 Subject: [PATCH 14/25] move some junk around classifyLines, as it will normally run into the first stuff first, allowing us to shorten the execution for smaller hands --- pyfpdb/fpdb_simple.py | 59 ++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index a4c440c1..e4b94138 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -411,20 +411,14 @@ def classifyLines(hand, category, lineTypes, lineStreets): lineTypes.append("cards") elif i == 0: lineTypes.append("header") + elif line.startswith("Table '"): + lineTypes.append("table") elif line.startswith("Seat ") and ( ("in chips" in line) or "($" in line): lineTypes.append("name") elif isActionLine(line): lineTypes.append("action") if " posts " in line or " posts the " in line: currentStreet="preflop" - elif isWinLine(line): - lineTypes.append("win") - elif line.startswith("Total pot ") and "Rake" in line: - lineTypes.append("rake") - done=True - elif "*** SHOW DOWN ***" in line or "*** SUMMARY ***" in line: - lineTypes.append("ignore") - #print "in classifyLine, showdown or summary" elif " antes " in line or " posts the ante " in line: lineTypes.append("ante") elif line.startswith("*** FLOP *** ["): @@ -450,11 +444,17 @@ def classifyLines(hand, category, lineTypes, lineStreets): currentStreet=3 elif line.startswith("*** 7") or line == "*** RIVER ***": lineTypes.append("ignore") - currentStreet=4 + currentStreet=4 + elif isWinLine(line): + lineTypes.append("win") + elif line.startswith("Total pot ") and "Rake" in line: + lineTypes.append("rake") + done=True + elif "*** SHOW DOWN ***" in line or "*** SUMMARY ***" in line: + lineTypes.append("ignore") + #print "in classifyLine, showdown or summary" elif " shows [" in line: lineTypes.append("cards") - elif line.startswith("Table '"): - lineTypes.append("table") else: raise FpdbError("unrecognised linetype in:"+hand[i]) lineStreets.append(currentStreet) @@ -511,11 +511,11 @@ def convertBlindBet(actionTypes, actionAmounts): def convertCardValues(arr): map(convertCardValuesBoard, arr) #end def convertCardValues + +card_map = { "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, "9" : 9, "T" : 10, "J" : 11, "Q" : 12, "K" : 13, "A" : 14} #converts the strings in the given array to ints (changes the passed array, no returning). see table design for conversion details def convertCardValuesBoard(arr): - # TODO: this could probably be useful in many places, it should be a constant somewhere maybe? - card_map = { "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, "9" : 9, "T" : 10, "J" : 11, "Q" : 12, "K" : 13, "A" : 14} for i in xrange(len(arr)): arr[i] = card_map[arr[i]] #end def convertCardValuesBoard @@ -523,10 +523,8 @@ def convertCardValuesBoard(arr): #this creates the 2D/3D arrays. manipulates the passed arrays instead of returning. def createArrays(category, seats, card_values, card_suits, antes, winnings, rakes, action_types, allIns, action_amounts, actionNos, actionTypeByNo): for i in xrange(seats):#create second dimension arrays - tmp=[] - card_values.append(tmp) - tmp=[] - card_suits.append(tmp) + card_values.append( [] ) + card_suits.append( [] ) antes.append(0) winnings.append(0) rakes.append(0) @@ -534,25 +532,16 @@ def createArrays(category, seats, card_values, card_suits, antes, winnings, rake streetCount = 4 if category == "holdem" or category == "omahahi" or category == "omahahilo" else 5 for i in xrange(streetCount): #build the first dimension array, for streets - tmp=[] - action_types.append(tmp) - tmp=[] - allIns.append(tmp) - tmp=[] - action_amounts.append(tmp) - tmp=[] - actionNos.append(tmp) - tmp=[] - actionTypeByNo.append(tmp) + action_types.append([]) + allIns.append([]) + action_amounts.append([]) + actionNos.append([]) + actionTypeByNo.append([]) for j in xrange (seats): #second dimension arrays: players - tmp=[] - action_types[i].append(tmp) - tmp=[] - allIns[i].append(tmp) - tmp=[] - action_amounts[i].append(tmp) - tmp=[] - actionNos[i].append(tmp) + action_types[i].append([]) + allIns[i].append([]) + action_amounts[i].append([]) + actionNos[i].append([]) # if (category=="holdem" or category=="omahahi" or category=="omahahilo"): # pass if category=="razz" or category=="studhi" or category=="studhilo":#need to fill card arrays. From f552ab24708534b13cce00dca673de0111366d15 Mon Sep 17 00:00:00 2001 From: eblade Date: Thu, 19 Mar 2009 03:52:18 -0400 Subject: [PATCH 15/25] more cleanup of junk --- pyfpdb/fpdb_simple.py | 45 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index e4b94138..fc6c13b2 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -584,36 +584,33 @@ def filterAnteBlindFold(site,hand): #todo: in tourneys this should not be removed but #print "start of filterAnteBlindFold" pre3rd=[] - for i in xrange (len(hand)): - if hand[i].startswith("*** 3") or hand[i].startswith("*** HOLE"): + for i, line in enumerate(hand): + if line.startswith("*** 3") or line.startswith("*** HOLE"): pre3rd = hand[0:i] foldeeName=None - for i in xrange (len(pre3rd)): - if pre3rd[i].endswith("folds") or pre3rd[i].endswith("is sitting out") or pre3rd[i].endswith(" stands up"): #found ante fold or timeout - pos = pre3rd[i].find (" folds") - foldeeName = pre3rd[i][0:pos] - if pos == -1 and " in chips)" not in pre3rd[i]: - pos=pre3rd[i].find (" is sitting out") - foldeeName=pre3rd[i][0:pos] + for line in pre3rd: + if line.endswith("folds") or line.endswith("is sitting out") or line.endswith(" stands up"): #found ante fold or timeout + pos = line.find(" folds") + foldeeName = line[0:pos] + if pos == -1 and " in chips)" not in line: + pos = line.find(" is sitting out") + foldeeName = line[0:pos] if pos == -1: - pos = pre3rd[i].find (" stands up") - foldeeName = pre3rd[i][0:pos] - if pos == -1: #this one is for PS tourney - pos1=pre3rd[i].find (": ")+2 - pos2=pre3rd[i].find (" (") - foldeeName=pre3rd[i][pos1:pos2] + pos = line.find(" stands up") + foldeeName = line[0:pos] + if pos == -1: + pos1 = line.find(": ") + 2 + pos2 = line.find(" (") + foldeeName = line[pos1:pos2] if foldeeName!=None: #print "filterAnteBlindFold, foldeeName:",foldeeName - toRemove=[] - for i in xrange(len(hand)): #using hand again to filter from all streets, just in case. - #todo: this will break it if sittin out BB wins a hand - if (hand[i].find(foldeeName)!=-1): - toRemove.append(hand[i]) - - for i in xrange(len(toRemove)): - hand.remove(toRemove[i]) + for i, line in enumerate(hand): + if foldeeName in line: + hand[i] = None + + hand = [line for line in hand if line] #end def filterAnteFold def stripEOLspaces(str): @@ -626,7 +623,7 @@ def stripEOLspaces(str): #removes useless lines as well as trailing spaces def filterCrap(site, hand, isTourney): #remove two trailing spaces at end of line - hand = map(stripEOLspaces, hand) + hand = [stripEOLspaces(line) for line in hand] #print "hand after trailing space removal in filterCrap:",hand #general variable position word filter/string filter From 0e89adc1db2465940250774836f500edb42b4e02 Mon Sep 17 00:00:00 2001 From: eblade Date: Thu, 19 Mar 2009 04:12:42 -0400 Subject: [PATCH 16/25] clean up some more ugly --- pyfpdb/HUD_main.py | 5 ++--- pyfpdb/Hud.py | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 666cf836..30a72096 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -123,7 +123,7 @@ class HUD_main(object): gtk.gdk.threads_enter() try: self.hud_dict[table_name].update(new_hand_id, config) - map(lambda aw: aw.update_gui(new_hand_id), self.hud_dict[table_name].aux_windows) + [aw.update_gui(new_hand_id) for aw in self.hud_dict[table_name].aux_windows] return False finally: gtk.gdk.threads_leave() @@ -172,8 +172,7 @@ class HUD_main(object): if temp_key in self.hud_dict: self.hud_dict[temp_key].stat_dict = stat_dict self.hud_dict[temp_key].cards = cards - for aw in self.hud_dict[temp_key].aux_windows: - aw.update_data(new_hand_id, self.db_connection) + [aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows] self.update_HUD(new_hand_id, temp_key, self.config) # Or create a new HUD diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 6d594b5b..20750b96 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -196,7 +196,7 @@ class Hud: s.window.destroy() self.stat_windows = {} # also kill any aux windows - map(lambda m: m.destroy(), self.aux_windows) + [aux.destroy() for aux in self.aux_windows] self.aux_windows = [] def reposition_windows(self, *args): @@ -217,8 +217,7 @@ class Hud: new_layout[self.stat_windows[sw].adj - 1] = new_loc self.config.edit_layout(self.table.site, self.max, locations = new_layout) # ask each aux to save its layout back to the config object - for aux in self.aux_windows: - aux.save_layout() + [aux.save_layout() for aux in self.aux_windows] # save the config object back to the file print "saving new xml file" self.config.save() @@ -351,6 +350,8 @@ class Hud: style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE) style |= win32con.WS_CLIPCHILDREN win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style) + break + window.set_title(real_name) class Stat_Window: @@ -575,6 +576,7 @@ class Popup_window: style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE) style |= win32con.WS_CLIPCHILDREN win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style) + break window.set_title(real_name) From 75a94299f984f369414bd7797595455f378d9916 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 19 Mar 2009 13:18:50 -0400 Subject: [PATCH 17/25] Make sure HUD_main gets community cards for AWs to use. --- pyfpdb/HUD_main.py | 4 +++- pyfpdb/Mucked.py | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 666cf836..aceab383 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -151,7 +151,9 @@ class HUD_main(object): try: (table_name, max, poker_game) = self.db_connection.get_table_name(new_hand_id) stat_dict = self.db_connection.get_stats_from_hand(new_hand_id) - cards = self.db_connection.get_cards(new_hand_id) + cards = self.db_connection.get_cards(new_hand_id) + comm_cards = self.db_connection.get_common_cards(new_hand_id) + cards['common'] = comm_cards['common'] except Exception, err: print "db error: skipping ", new_hand_id, err sys.stderr.write("Database error %s in hand %d. Skipping.\n" % (err, int(new_hand_id))) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 1d7e9597..a915facc 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -349,10 +349,6 @@ class Flop_Mucked(Aux_Window): self.m_windows[i].show_all() self.m_windows[i].hide() - def update_data(self, new_hand_id, db_connection): - cards = db_connection.get_common_cards(new_hand_id) - self.hud.cards['common'] = cards['common'] - def update_gui(self, new_hand_id): """Prepare and show the mucked cards.""" if self.displayed_cards: From 33055f7f864893eca23f93852be386b0eb094115 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 19 Mar 2009 16:10:18 -0400 Subject: [PATCH 18/25] Hello_menu demo added to Hello.py module. --- pyfpdb/Hello.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyfpdb/Hello.py b/pyfpdb/Hello.py index b5d1d366..41262d6c 100644 --- a/pyfpdb/Hello.py +++ b/pyfpdb/Hello.py @@ -99,3 +99,15 @@ class Hello_plus(Aux_Window): # hands played that was updated in the "update_data()" function. self.label.set_text("Hello %s\nYou have played %d hands\n on %s." % (self.hero, self.hands_played, self.site)) +class Hello_Menu(Aux_Window): + """A 'Hello World' Aux_Window demo.""" + def create(self): +# This demo puts a menu item on the HUD mainwindow. + self.item = gtk.MenuItem('Print cards') + self.hud.menu.append(self.item) + self.item.connect("activate", self.print_cards) + self.item.show() + + def print_cards(self, *args): +# callback for the menu item + print "cards =", self.hud.cards From 72c0cdfa527fe87aa7e45fbc7a4535eaa602bc37 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 19 Mar 2009 20:58:40 -0400 Subject: [PATCH 19/25] Needed to make previous commit work. --- pyfpdb/Mucked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index a915facc..abde491f 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -37,7 +37,7 @@ import Database class Aux_Window: def __init__(self, hud, params, config): - self.config = hud + self.hud = hud self.config = config def update_data(self, *parms): From d59016f249d9d7c159a9b364043820160b78e599 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 20 Mar 2009 19:28:57 -0400 Subject: [PATCH 20/25] Button clicking for FlopMucked. --- pyfpdb/Mucked.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index abde491f..334ba694 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -318,6 +318,7 @@ class Flop_Mucked(Aux_Window): self.params = params # dict aux params from config self.positions = {} # dict of window positions self.displayed_cards = False + self.timer_on = False # bool = Ture if the timeout for removing the cards is on self.card_images = self.get_card_images() def create(self): @@ -375,34 +376,60 @@ class Flop_Mucked(Aux_Window): self.displayed_cards = True if self.displayed_cards and float(self.params['timeout']) > 0: - gobject.timeout_add(int(1000*float(self.params['timeout'])), self.hide_mucked_cards) + self.timer_on = True + gobject.timeout_add(int(1000*float(self.params['timeout'])), self.timed_out) def destroy(self): """Destroy all of the mucked windows.""" for w in self.m_windows.values(): w.destroy() + def timed_out(self): +# this is the callback from the timeout + +# if timer_on is False the user has cancelled the timer with a click +# so just return False to cancel the timer + if not self.timer_on: + return False + else: + self.hide_mucked_cards() + return False + def hide_mucked_cards(self): """Hide the mucked card windows.""" -# this is the callback from the timeout for (i, w) in self.m_windows.iteritems(): self.positions[i] = w.get_position() w.hide() self.displayed_cards = False - return False # this tells the system to NOT run this timeout again def button_press_cb(self, widget, event, *args): """Handle button clicks in the event boxes.""" + +# shift-any button exposes all the windows and turns off the timer + if event.state & gtk.gdk.SHIFT_MASK: + self.timer_on = False + self.expose_all() + if event.button == 3: # right button event pass elif event.button == 2: # middle button event - self.hide_mucked_cards() + if self.timer_on == True: + self.timer_on = False + else: + self.timer_on = False + self.hide_mucked_cards() elif event.button == 1: # left button event window = widget.get_parent() window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time) + def expose_all(self): + for (i, cards) in self.hud.cards.iteritems(): + self.m_windows[i].present() + self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back + self.displayed_cards = True + def save_layout(self, *args): """Save new layout back to the aux element in the config file.""" new_locs = {} From 847fd5f6c18cc8e3bd90b9cdc5d75538156cfe89 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 20 Mar 2009 19:32:02 -0400 Subject: [PATCH 21/25] Tool tips for FlopMucked. --- pyfpdb/Mucked.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 334ba694..fe2baa71 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -25,6 +25,7 @@ Mucked cards display for FreePokerTools HUD. # Standard Library modules import sys +import pprint # pyGTK modules import pygtk @@ -375,6 +376,9 @@ class Flop_Mucked(Aux_Window): self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back self.displayed_cards = True + for stats in self.hud.stat_dict.itervalues(): + self.eb[stats['seat']].set_tooltip_text(stats['screen_name']) + if self.displayed_cards and float(self.params['timeout']) > 0: self.timer_on = True gobject.timeout_add(int(1000*float(self.params['timeout'])), self.timed_out) From 39db65b65dfe438744690124226f5baca142a3b4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 21 Mar 2009 11:38:17 -0400 Subject: [PATCH 22/25] Fix bug in defaults of import params + bug in printing same. --- pyfpdb/Configuration.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 81645694..19e62038 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -32,12 +32,12 @@ import shutil import xml.dom.minidom from xml.dom.minidom import Node -def fix_tf(x): +def fix_tf(x, default = True): if x == "1" or x == 1 or string.lower(x) == "true" or string.lower(x) == "t": return True if x == "0" or x == 0 or string.lower(x) == "false" or string.lower(x) == "f": return False - return False + return default class Layout: def __init__(self, node): @@ -212,18 +212,12 @@ class Import: self.interval = node.getAttribute("interval") self.callFpdbHud = node.getAttribute("callFpdbHud") self.hhArchiveBase = node.getAttribute("hhArchiveBase") - if node.hasAttribute("saveActions"): - self.saveActions = fix_tf(node.getAttribute("saveActions")) - else: - self.saveActions = True - if node.hasAttribute("fastStoreHudCache"): - self.fastStoreHudCache = fix_tf(node.getAttribute("fastStoreHudCache")) - else: - self.fastStoreHudCache = False + self.saveActions = fix_tf(node.getAttribute("saveActions"), True) + self.fastStoreHudCache = fix_tf(node.getAttribute("fastStoreHudCache"), True) def __str__(self): return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s\n saveActions = %s\n fastStoreHudCache = %s\n" \ - % (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.saveActions) + % (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.fastStoreHudCache) class Tv: def __init__(self, node): From 86d350984e07a87edf39e8a7640be1d44639f1a4 Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 22 Mar 2009 01:31:36 +0900 Subject: [PATCH 23/25] Dodgy 6 max fix to FTP converter --- pyfpdb/FulltiltToFpdb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index fb2bf6ea..b28d4065 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -117,6 +117,9 @@ follow : whether to tail -f the input""" hand.handid = m.group('HID') hand.tablename = m.group('TABLE') hand.starttime = time.strptime(m.group('DATETIME'), "%H:%M:%S ET - %Y/%m/%d") + if m.group('TABLEATTRIBUTES'): + m2 = re.search("(\d+) max", m.group('TABLEATTRIBUTES')) + hand.maxseats = int(m2.group(1)) # These work, but the info is already in the Hand class - should be used for tourneys though. # m.group('SB') # m.group('BB') From 8ebcd7b68a4f5b37ea1d7e593526e6d015330f5f Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 22 Mar 2009 02:17:48 +0900 Subject: [PATCH 24/25] Fix crash on Stars tourney import If importing a tourney and the line was marked as crap this test crashed the importer --- pyfpdb/fpdb_simple.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index fc6c13b2..b0263888 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -714,7 +714,7 @@ def filterCrap(site, hand, isTourney): hand[i] = False elif (hand[i].find(": ")!=-1 and site=="ftp" and hand[i].find("Seat ")==-1 and hand[i].find(": Table")==-1): #filter ftp chat hand[i] = False - if isTourney: + if isTourney and not hand[i] == False: if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))): hand[i] = False elif hand[i]: From 38b0fc71577182fcc8e0333e9f9ae175a9be020c Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 22 Mar 2009 02:20:56 +0900 Subject: [PATCH 25/25] Add all functional site importers to Bulk import gui --- pyfpdb/GuiBulkImport.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index 6745e9fc..84ef4645 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -176,7 +176,10 @@ class GuiBulkImport(): # ComboBox - filter self.cbfilter = gtk.combo_box_new_text() self.cbfilter.append_text("passthrough") - self.cbfilter.append_text("Everleaf") + self.cbfilter.append_text("BetfairToFpdb") + self.cbfilter.append_text("EverleafToFpdb") + self.cbfilter.append_text("FulltiltToFpdb") + self.cbfilter.append_text("PokerStarsToFpdb") self.cbfilter.set_active(0) self.table.attach(self.cbfilter, 3, 4, 2, 3, xpadding = 10, ypadding = 0, yoptions=gtk.SHRINK) self.cbfilter.show()