Merge branch 'master' of git://git.assembla.com/fpdb-sql

This commit is contained in:
Worros 2009-06-20 00:41:24 +08:00
commit ccd2112c8a
4 changed files with 22 additions and 55 deletions

View File

@ -32,60 +32,20 @@ import string
# pyGTK modules # pyGTK modules
# FreePokerTools modules # FreePokerTools modules
import fpdb_db
import Configuration import Configuration
import SQL import SQL
import Card import Card
class Database: class Database:
def __init__(self, c, db_name, game): 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() 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.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() self.connection.rollback()
# To add to config: # To add to config:
@ -203,7 +163,7 @@ class Database:
def get_action_from_hand(self, hand_no): def get_action_from_hand(self, hand_no):
action = [ [], [], [], [], [] ] action = [ [], [], [], [], [] ]
c = self.connection.cursor() 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(): for row in c.fetchall():
street = row[0] street = row[0]
act = row[1:] act = row[1:]
@ -214,7 +174,7 @@ class Database:
"""Returns a hash of winners:amount won, given a hand number.""" """Returns a hash of winners:amount won, given a hand number."""
winners = {} winners = {}
c = self.connection.cursor() 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(): for row in c.fetchall():
winners[row[0]] = row[1] winners[row[0]] = row[1]
return winners return winners
@ -325,10 +285,10 @@ if __name__=="__main__":
for p in stat_dict.keys(): for p in stat_dict.keys():
print p, " ", stat_dict[p] print p, " ", stat_dict[p]
# print "nutOmatics stats:" #print "nutOmatics stats:"
# stat_dict = db_connection.get_stats_from_hand(h, hero) #stat_dict = db_connection.get_stats_from_hand(h, hero)
# for p in stat_dict.keys(): #for p in stat_dict.keys():
# print p, " ", stat_dict[p] # print p, " ", stat_dict[p]
print "cards =", db_connection.get_cards(u'1') print "cards =", db_connection.get_cards(u'1')
db_connection.close_connection db_connection.close_connection

View File

@ -231,7 +231,12 @@ def discover_nt_by_name(c, tablename):
titles = {} titles = {}
win32gui.EnumWindows(win_enum_handler, titles) win32gui.EnumWindows(win_enum_handler, titles)
for hwnd in titles: for hwnd in titles:
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 if not tablename in titles[hwnd]: continue
except:
continue
if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window
if 'HUD:' in titles[hwnd]: continue # FPDB HUD 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 if 'Chat:' in titles[hwnd]: continue # Some sites (FTP? PS? Others?) have seperable or seperately constructed chat windows

View File

@ -35,6 +35,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
#part 1: read hand no and check for duplicate #part 1: read hand no and check for duplicate
siteHandNo = fpdb_simple.parseSiteHandNo(hand[0]) siteHandNo = fpdb_simple.parseSiteHandNo(hand[0])
#print "siteHandNo =", siteHandNo
handStartTime = fpdb_simple.parseHandStartTime(hand[0]) handStartTime = fpdb_simple.parseHandStartTime(hand[0])
isTourney = fpdb_simple.isTourney(hand[0]) isTourney = fpdb_simple.isTourney(hand[0])
@ -127,6 +128,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
totalWinnings = sum(winnings) totalWinnings = sum(winnings)
# if hold'em, use positions and not antes, if stud do not use positions, use antes # 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": if base == "hold":
hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
, allIns, actionTypeByNo, winnings, totalWinnings, positions , allIns, actionTypeByNo, winnings, totalWinnings, positions

View File

@ -2393,7 +2393,7 @@ def storeHudCache2(backend, cursor, base, category, gametypeId, hand_start_time,
# Try to do the update first: # Try to do the update first:
num = cursor.execute("""UPDATE HudCache num = cursor.execute("""UPDATE HudCache
SET HDs=HDs+%s, street0VPI=street0VPI+%s, street0Aggr=street0Aggr+%s, 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, street1Seen=street1Seen+%s, street2Seen=street2Seen+%s, street3Seen=street3Seen+%s,
street4Seen=street4Seen+%s, sawShowdown=sawShowdown+%s, street4Seen=street4Seen+%s, sawShowdown=sawShowdown+%s,
street1Aggr=street1Aggr+%s, street2Aggr=street2Aggr+%s, street3Aggr=street3Aggr+%s, street1Aggr=street1Aggr+%s, street2Aggr=street2Aggr+%s, street3Aggr=street3Aggr+%s,