Merge branch 'master' of git://git.assembla.com/fpdboz.git

Conflicts:
	pyfpdb/fpdb_simple.py
This commit is contained in:
eblade 2008-12-13 12:54:32 -05:00
commit a6544f5d10
5 changed files with 791 additions and 740 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,11 +47,12 @@ class GuiPlayerStats (threading.Thread):
result = self.cursor.execute(self.sql.query['getPlayerId'], (self.heroes[self.activesite],)) result = self.cursor.execute(self.sql.query['getPlayerId'], (self.heroes[self.activesite],))
result = self.db.cursor.fetchall() result = self.db.cursor.fetchall()
if not result == (): if not result == ():
pid = result[0][0]
pid = result[0][0] pid = result[0][0]
tmp = tmp.replace("<player_test>", "(" + str(pid) + ")") tmp = tmp.replace("<player_test>", "(" + str(pid) + ")")
self.cursor.execute(tmp) self.cursor.execute(tmp)
result = self.db.cursor.fetchall() result = self.db.cursor.fetchall()
cols = 20 cols = 16
rows = len(result)+1 # +1 for title row rows = len(result)+1 # +1 for title row
self.stats_table = gtk.Table(rows, cols, False) self.stats_table = gtk.Table(rows, cols, False)
self.stats_table.set_col_spacings(4) self.stats_table.set_col_spacings(4)
@ -59,7 +60,7 @@ class GuiPlayerStats (threading.Thread):
vbox.add(self.stats_table) vbox.add(self.stats_table)
# Create header row # Create header row
titles = ("GID", "base", "Style", "Site", "$BB", "Hands", "VPIP", "PFR", "saw_f", "sawsd", "wtsdwsf", "wmsd", "FlAFq", "TuAFq", "RvAFq", "PFAFq", "Net($)", "BB/100", "$/hand", "Variance") titles = ("Game", "Hands", "VPIP", "PFR", "saw_f", "sawsd", "wtsdwsf", "wmsd", "FlAFq", "TuAFq", "RvAFq", "PFAFq", "Net($)", "BB/100", "$/hand", "Variance")
col = 0 col = 0
row = 0 row = 0
@ -77,13 +78,16 @@ class GuiPlayerStats (threading.Thread):
bgcolor = "lightgrey" bgcolor = "lightgrey"
eb = gtk.EventBox() eb = gtk.EventBox()
eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(bgcolor)) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(bgcolor))
l = gtk.Label(result[row-1][col]) l = gtk.Label(result[row][col])
if col == 0:
l.set_alignment(xalign=0.0, yalign=0.5)
else:
l.set_alignment(xalign=1.0, yalign=0.5)
eb.add(l) eb.add(l)
self.stats_table.attach(eb, col, col+1, row+1, row+2) self.stats_table.attach(eb, col, col+1, row+1, row+2)
l.show() l.show()
eb.show() eb.show()
def fillPlayerFrame(self, vbox): def fillPlayerFrame(self, vbox):
for site in self.conf.supported_sites.keys(): for site in self.conf.supported_sites.keys():
hbox = gtk.HBox(False, 0) hbox = gtk.HBox(False, 0)

View File

@ -36,6 +36,7 @@ import math
import os import os
import datetime import datetime
import re import re
import fpdb_db
import fpdb_simple import fpdb_simple
import fpdb_parse_logic import fpdb_parse_logic
from time import time from time import time
@ -47,7 +48,7 @@ class Importer:
self.settings=settings self.settings=settings
self.caller=caller self.caller=caller
self.config = config self.config = config
self.db = None self.fdb = None
self.cursor = None self.cursor = None
self.filelist = {} self.filelist = {}
self.dirlist = {} self.dirlist = {}
@ -64,35 +65,12 @@ class Importer:
if not self.settings.has_key('handCount'): if not self.settings.has_key('handCount'):
#TODO: Is this value in the xml file? #TODO: Is this value in the xml file?
self.settings['handCount'] = 0 self.settings['handCount'] = 0
self.dbConnect() self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
self.fdb.connect(self.settings['db-backend'],
# XXX: Why is this here, when fpdb_db.connect() already does the self.settings['db-host'],
# same? self.settings['db-databaseName'],
def dbConnect(self): self.settings['db-user'],
#connect to DB self.settings['db-password'])
if self.settings['db-backend'] == 2:
if not mysqlLibFound:
raise fpdb_simple.FpdbError("interface library MySQLdb not found but MySQL selected as backend - please install the library or change the config file")
self.db = MySQLdb.connect(self.settings['db-host'], self.settings['db-user'],
self.settings['db-password'], self.settings['db-databaseName'])
elif self.settings['db-backend'] == 3:
if not pgsqlLibFound:
raise fpdb_simple.FpdbError("interface library psycopg2 not found but PostgreSQL selected as backend - please install the library or change the config file")
print self.settings
if self.settings.has_key('db-host') and \
self.settings.has_key('db-user'):
self.db = psycopg2.connect(host = self.settings['db-host'],
user = self.settings['db-user'],
password = self.settings['db-password'],
database = self.settings['db-databaseName'])
else:
dbname = self.settings['db-databaseName']
self.db = psycopg2.connect(database = dbname)
elif self.settings['db-backend'] == 4:
pass
else:
pass
self.cursor = self.db.cursor()
#Set functions #Set functions
def setCallHud(self, value): def setCallHud(self, value):
@ -247,12 +225,11 @@ class Importer:
self.hand=hand self.hand=hand
try: try:
handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.db handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
,self.cursor, site, category, hand) ,self.fdb.cursor, site, category, hand)
self.db.commit() self.fdb.db.commit()
stored+=1 stored+=1
self.db.commit()
if self.callHud: if self.callHud:
#print "call to HUD here. handsId:",handsId #print "call to HUD here. handsId:",handsId
#pipe the Hands.id out to the HUD #pipe the Hands.id out to the HUD
@ -264,17 +241,17 @@ class Importer:
self.printEmailErrorMessage(errors, file, hand) self.printEmailErrorMessage(errors, file, hand)
if (self.settings['failOnError']): if (self.settings['failOnError']):
self.db.commit() #dont remove this, in case hand processing was cancelled. self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
raise raise
except (fpdb_simple.FpdbError), fe: except (fpdb_simple.FpdbError), fe:
errors+=1 errors+=1
self.printEmailErrorMessage(errors, file, hand) self.printEmailErrorMessage(errors, file, hand)
#fe.printStackTrace() #todo: get stacktrace #fe.printStackTrace() #todo: get stacktrace
self.db.rollback() self.fdb.db.rollback()
if (self.settings['failOnError']): if (self.settings['failOnError']):
self.db.commit() #dont remove this, in case hand processing was cancelled. self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
raise raise
if (self.settings['minPrint']!=0): if (self.settings['minPrint']!=0):
if ((stored+duplicates+partial+errors)%self.settings['minPrint']==0): if ((stored+duplicates+partial+errors)%self.settings['minPrint']==0):
@ -299,7 +276,7 @@ class Importer:
print "failed to read a single hand from file:", inputFile print "failed to read a single hand from file:", inputFile
handsId=0 handsId=0
#todo: this will cause return of an unstored hand number if the last hand was error or partial #todo: this will cause return of an unstored hand number if the last hand was error or partial
self.db.commit() self.fdb.db.commit()
self.handsId=handsId self.handsId=handsId
return handsId return handsId
#end def import_file_dict #end def import_file_dict

View File

@ -135,11 +135,11 @@ def mainParser(backend, db, cursor, site, category, hand):
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
, actionTypes, actionAmounts) , actionTypes, actionAmounts, None)
else: else:
hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
, allIns, actionTypeByNo, winnings, totalWinnings, None , allIns, actionTypeByNo, winnings, totalWinnings, None
, actionTypes, actionAmounts) , actionTypes, actionAmounts, antes)
if isTourney: if isTourney:
ranks=[] ranks=[]
@ -185,7 +185,7 @@ def mainParser(backend, db, cursor, site, category, hand):
, seatNos) , seatNos)
else: else:
raise fpdb_simple.FpdbError ("unrecognised category") raise fpdb_simple.FpdbError ("unrecognised category")
db.commit() db.commit()
return result return result
#end def mainParser #end def mainParser

8
pyfpdb/fpdb_simple.py Executable file → Normal file
View File

@ -771,7 +771,7 @@ def parseCardLine(site, category, street, line, names, cardValues, cardSuits, bo
print "line:",line,"cardValues[playerNo]:",cardValues[playerNo] print "line:",line,"cardValues[playerNo]:",cardValues[playerNo]
raise FpdbError("read too many/too few holecards in parseCardLine") raise FpdbError("read too many/too few holecards in parseCardLine")
elif (category=="razz" or category=="studhi" or category=="studhilo"): elif (category=="razz" or category=="studhi" or category=="studhilo"):
if (line.find("shows")==-1 and line.find("mucked")==-1): if (line.find("shows")==-1):
#print "parseCardLine(in stud if), street:", street #print "parseCardLine(in stud if), street:", street
if line[pos+2]=="]": #-> not (hero and 3rd street) if line[pos+2]=="]": #-> not (hero and 3rd street)
cardValues[playerNo][street+2]=line[pos:pos+1] cardValues[playerNo][street+2]=line[pos:pos+1]
@ -1426,7 +1426,7 @@ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
#end def store_hands_players_stud_tourney #end def store_hands_players_stud_tourney
def generateHudCacheData(player_ids, base, category, action_types, allIns, actionTypeByNo def generateHudCacheData(player_ids, base, category, action_types, allIns, actionTypeByNo
,winnings, totalWinnings, positions, actionTypes, actionAmounts): ,winnings, totalWinnings, positions, actionTypes, actionAmounts, antes):
"""calculates data for the HUD during import. IMPORTANT: if you change this method make """calculates data for the HUD during import. IMPORTANT: if you change this method make
sure to also change the following storage method and table_viewer.prepare_data if necessary sure to also change the following storage method and table_viewer.prepare_data if necessary
""" """
@ -1953,7 +1953,9 @@ sure to also change the following storage method and table_viewer.prepare_data i
#print "b4 totprof calc, len(playerIds)=", len(player_ids) #print "b4 totprof calc, len(playerIds)=", len(player_ids)
for pl in range (len(player_ids)): for pl in range (len(player_ids)):
#print "pl=", pl #print "pl=", pl
myTotalProfit=winnings[pl] # still need to deduct costs myTotalProfit=winnings[pl] # still need to deduct other costs
if antes:
myTotalProfit=winnings[pl] - antes[pl]
for i in range (len(actionTypes)): #iterate through streets for i in range (len(actionTypes)): #iterate through streets
#for j in range (len(actionTypes[i])): #iterate through names (using pl loop above) #for j in range (len(actionTypes[i])): #iterate through names (using pl loop above)
for k in range (len(actionTypes[i][pl])): #iterate through individual actions of that player on that street for k in range (len(actionTypes[i][pl])): #iterate through individual actions of that player on that street