From dcaf6fed2759cfb19f4ea7e662e3a522b249f29e Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Wed, 17 Jun 2009 21:43:30 +0100 Subject: [PATCH 1/4] apologies - looks like I missed this out of my last release :-( --- pyfpdb/fpdb_parse_logic.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index 150707c1..ee5d9c40 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" @@ -34,6 +35,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config): #part 1: read hand no and check for duplicate siteHandNo = fpdb_simple.parseSiteHandNo(hand[0]) + #print "siteHandNo =", siteHandNo handStartTime = fpdb_simple.parseHandStartTime(hand[0]) isTourney = fpdb_simple.isTourney(hand[0]) @@ -126,6 +128,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config): totalWinnings = sum(winnings) # if hold'em, use positions and not antes, if stud do not use positions, use antes + # this is used for handsplayers inserts, so still needed even if hudcache update is being skipped if base == "hold": hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes , allIns, actionTypeByNo, winnings, totalWinnings, positions @@ -141,7 +144,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 +153,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 +165,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 +173,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 7664373648b4b865c9dfd61198f6ac75ba7f2a97 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Wed, 17 Jun 2009 23:03:43 +0100 Subject: [PATCH 2/4] use fpdb_db for db connection --- pyfpdb/Database.py | 66 +++++++++------------------------------------- 1 file changed, 13 insertions(+), 53 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 9582354a..e5fbda6d 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -32,62 +32,22 @@ import string # pyGTK modules # FreePokerTools modules +import fpdb_db import Configuration import SQL import Card class Database: def __init__(self, c, db_name, game): + self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql + self.fdb.do_connect(c) + self.connection = self.fdb.db + db_params = c.get_db_parameters() - if (string.lower(db_params['db-server']) == 'postgresql' or - string.lower(db_params['db-server']) == 'postgres'): - import psycopg2 # posgres via DB-API - import psycopg2.extensions - psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) - - try: - if db_params['db-host'] == 'localhost' or db_params['db-host'] == '127.0.0.1': - self.connection = psycopg2.connect(database = db_params['db-databaseName']) - else: - self.connection = psycopg2.connect(host = db_params['db-host'], - user = db_params['db-user'], - password = db_params['db-password'], - database = db_params['db-databaseName']) - except: - print "Error opening database connection %s. See error log file." % (file) - traceback.print_exc(file=sys.stderr) - print "press enter to continue" - sys.stdin.readline() - sys.exit() - - elif string.lower(db_params['db-server']) == 'mysql': - import MySQLdb # mysql bindings - try: - self.connection = MySQLdb.connect(host = db_params['db-host'], - user = db_params['db-user'], - passwd = db_params['db-password'], - db = db_params['db-databaseName']) - cur_iso = self.connection.cursor() - cur_iso.execute('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED') - cur_iso.close() - - except: - print "Error opening database connection %s. See error log file." % (file) - traceback.print_exc(file=sys.stderr) - print "press enter to continue" - sys.stdin.readline() - sys.exit() - - else: - print "Database = %s not recognized." % (c.supported_databases[db_name].db_server) - sys.stderr.write("Database not recognized, exiting.\n") - print "press enter to continue" - sys.exit() - self.type = db_params['db-type'] - self.sql = SQL.Sql(game = game, type = self.type) + self.sql = SQL.Sql(game = game, type = self.type, db_server = db_params['db-backend']) self.connection.rollback() - + # To add to config: self.hud_style = 'T' # A=All-time # S=Session @@ -211,7 +171,7 @@ class Database: def get_action_from_hand(self, hand_no): action = [ [], [], [], [], [] ] c = self.connection.cursor() - c.execute(self.sql.query['get_action_from_hand'], (hand_no, )) + c.execute(self.sql.query['get_action_from_hand'], (hand_no,)) for row in c.fetchall(): street = row[0] act = row[1:] @@ -222,7 +182,7 @@ class Database: """Returns a hash of winners:amount won, given a hand number.""" winners = {} c = self.connection.cursor() - c.execute(self.sql.query['get_winners_from_hand'], (hand, )) + c.execute(self.sql.query['get_winners_from_hand'], (hand,)) for row in c.fetchall(): winners[row[0]] = row[1] return winners @@ -333,10 +293,10 @@ if __name__=="__main__": for p in stat_dict.keys(): print p, " ", stat_dict[p] -# print "nutOmatics stats:" -# stat_dict = db_connection.get_stats_from_hand(h, hero) -# for p in stat_dict.keys(): -# print p, " ", stat_dict[p] + #print "nutOmatics stats:" + #stat_dict = db_connection.get_stats_from_hand(h, hero) + #for p in stat_dict.keys(): + # print p, " ", stat_dict[p] print "cards =", db_connection.get_cards(u'1') db_connection.close_connection From 8bbd21fa6a2d7215a4282e758ae8a4cac6ba4637 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Wed, 17 Jun 2009 23:05:20 +0100 Subject: [PATCH 3/4] hide error when a window has non UTF-8 char in title --- pyfpdb/Tables.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index 58da2690..5884e81e 100755 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -231,7 +231,12 @@ def discover_nt_by_name(c, tablename): titles = {} win32gui.EnumWindows(win_enum_handler, titles) for hwnd in titles: - if not tablename in titles[hwnd]: continue + print "Tbales.py: tablename =", tablename, "title =", titles[hwnd] + try: + # this can blow up in XP on some windows, eg firefox displaying http://docs.python.org/tutorial/classes.html + if not tablename in titles[hwnd]: continue + except: + continue if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window if 'HUD:' in titles[hwnd]: continue # FPDB HUD window if 'Chat:' in titles[hwnd]: continue # Some sites (FTP? PS? Others?) have seperable or seperately constructed chat windows From 2b240efd0a15d6e13fa3c8dcca358cab01184da4 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Thu, 18 Jun 2009 20:29:02 +0100 Subject: [PATCH 4/4] unimportant fix to storehudcache2 --- 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 31321aeb..b140a2a8 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -2381,7 +2381,7 @@ def storeHudCache2(backend, cursor, base, category, gametypeId, hand_start_time, # Try to do the update first: num = cursor.execute("""UPDATE HudCache SET HDs=HDs+%s, street0VPI=street0VPI+%s, street0Aggr=street0Aggr+%s, - street0_3B4BChance=street0_3B4BChance+%s, street0_3B4BDone=street0_3B4BDone+%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,