intermediate commit on the way to tourney stats
This commit is contained in:
parent
dc67197e23
commit
b1e41a54ec
|
@ -2042,6 +2042,14 @@ class Database:
|
||||||
tourneysPlayersIds.append(self.get_last_insert_id(cursor))
|
tourneysPlayersIds.append(self.get_last_insert_id(cursor))
|
||||||
return tourneysPlayersIds
|
return tourneysPlayersIds
|
||||||
#end def createOrUpdateTourneysPlayers
|
#end def createOrUpdateTourneysPlayers
|
||||||
|
|
||||||
|
def getTourneyTypesIds(self):
|
||||||
|
c = self.connection.cursor()
|
||||||
|
c.execute(self.sql.query['getTourneyTypesIds'])
|
||||||
|
result = c.fetchall()
|
||||||
|
print "DB.getTourneyTypesIds result:",result
|
||||||
|
return result
|
||||||
|
#end def getTourneyTypesIds
|
||||||
#end class Database
|
#end class Database
|
||||||
|
|
||||||
# Class used to hold all the data needed to write a hand to the db
|
# Class used to hold all the data needed to write a hand to the db
|
||||||
|
|
|
@ -226,18 +226,22 @@ class Filters(threading.Thread):
|
||||||
|
|
||||||
def getNumHands(self):
|
def getNumHands(self):
|
||||||
return self.numHands
|
return self.numHands
|
||||||
|
#end def getNumHands
|
||||||
|
|
||||||
def getSites(self):
|
def getSites(self):
|
||||||
return self.sites
|
return self.sites
|
||||||
|
#end def getSites
|
||||||
|
|
||||||
def getGames(self):
|
def getGames(self):
|
||||||
return self.games
|
return self.games
|
||||||
|
|
||||||
def getSiteIds(self):
|
def getSiteIds(self):
|
||||||
return self.siteid
|
return self.siteid
|
||||||
|
#end def getSiteIds
|
||||||
|
|
||||||
def getHeroes(self):
|
def getHeroes(self):
|
||||||
return self.heroes
|
return self.heroes
|
||||||
|
#end def getHeroes
|
||||||
|
|
||||||
def getLimits(self):
|
def getLimits(self):
|
||||||
ltuple = []
|
ltuple = []
|
||||||
|
@ -255,12 +259,14 @@ class Filters(threading.Thread):
|
||||||
if 'to' in self.sbSeats:
|
if 'to' in self.sbSeats:
|
||||||
self.seats['to'] = self.sbSeats['to'].get_value_as_int()
|
self.seats['to'] = self.sbSeats['to'].get_value_as_int()
|
||||||
return self.seats
|
return self.seats
|
||||||
|
#end def getSeats
|
||||||
|
|
||||||
def getGroups(self):
|
def getGroups(self):
|
||||||
return self.groups
|
return self.groups
|
||||||
|
|
||||||
def getDates(self):
|
def getDates(self):
|
||||||
return self.__get_dates()
|
return self.__get_dates()
|
||||||
|
#end def getDates
|
||||||
|
|
||||||
def registerButton1Name(self, title):
|
def registerButton1Name(self, title):
|
||||||
self.Button1.set_label(title)
|
self.Button1.set_label(title)
|
||||||
|
@ -324,6 +330,7 @@ class Filters(threading.Thread):
|
||||||
except:
|
except:
|
||||||
self.numHands = 0
|
self.numHands = 0
|
||||||
#log.debug("setting numHands:", self.numHands)
|
#log.debug("setting numHands:", self.numHands)
|
||||||
|
#end def __set_num_hands
|
||||||
|
|
||||||
def createSiteLine(self, hbox, site):
|
def createSiteLine(self, hbox, site):
|
||||||
cb = gtk.CheckButton(site)
|
cb = gtk.CheckButton(site)
|
||||||
|
@ -354,6 +361,7 @@ class Filters(threading.Thread):
|
||||||
#print w.get_active()
|
#print w.get_active()
|
||||||
self.games[game] = w.get_active()
|
self.games[game] = w.get_active()
|
||||||
log.debug("self.games[%s] set to %s" %(game, self.games[game]))
|
log.debug("self.games[%s] set to %s" %(game, self.games[game]))
|
||||||
|
#end def __set_game_select
|
||||||
|
|
||||||
def __set_limit_select(self, w, limit):
|
def __set_limit_select(self, w, limit):
|
||||||
#print w.get_active()
|
#print w.get_active()
|
||||||
|
@ -600,6 +608,7 @@ class Filters(threading.Thread):
|
||||||
else:
|
else:
|
||||||
print "INFO: No games returned from database"
|
print "INFO: No games returned from database"
|
||||||
log.info("No games returned from database")
|
log.info("No games returned from database")
|
||||||
|
#end def fillGamesFrame
|
||||||
|
|
||||||
def fillLimitsFrame(self, vbox, display):
|
def fillLimitsFrame(self, vbox, display):
|
||||||
top_hbox = gtk.HBox(False, 0)
|
top_hbox = gtk.HBox(False, 0)
|
||||||
|
@ -899,6 +908,7 @@ class Filters(threading.Thread):
|
||||||
log.info("t1="+t1+" adj_t1="+adj_t1+'.')
|
log.info("t1="+t1+" adj_t1="+adj_t1+'.')
|
||||||
|
|
||||||
return (adj_t1, adj_t2)
|
return (adj_t1, adj_t2)
|
||||||
|
#end def __get_dates
|
||||||
|
|
||||||
def __get_date(self, widget, calendar, entry, win):
|
def __get_date(self, widget, calendar, entry, win):
|
||||||
# year and day are correct, month is 0..11
|
# year and day are correct, month is 0..11
|
||||||
|
|
|
@ -442,8 +442,7 @@ class GuiPlayerStats (threading.Thread):
|
||||||
sqlrow += 1
|
sqlrow += 1
|
||||||
row += 1
|
row += 1
|
||||||
vbox.show_all()
|
vbox.show_all()
|
||||||
|
#end def addGrid
|
||||||
#end def addGrid(self, query, vars, playerids, sitenos, limits, type, seats, groups, dates):
|
|
||||||
|
|
||||||
def refineQuery(self, query, flags, playerids, sitenos, limits, type, seats, groups, dates, games):
|
def refineQuery(self, query, flags, playerids, sitenos, limits, type, seats, groups, dates, games):
|
||||||
having = ''
|
having = ''
|
||||||
|
@ -609,7 +608,7 @@ class GuiPlayerStats (threading.Thread):
|
||||||
|
|
||||||
#print "query =\n", query
|
#print "query =\n", query
|
||||||
return(query)
|
return(query)
|
||||||
#end def refineQuery(self, query, playerids, sitenos, limits):
|
#end def refineQuery
|
||||||
|
|
||||||
def showDetailFilter(self, widget, data):
|
def showDetailFilter(self, widget, data):
|
||||||
detailDialog = gtk.Dialog(title="Detailed Filters", parent=self.main_window
|
detailDialog = gtk.Dialog(title="Detailed Filters", parent=self.main_window
|
||||||
|
|
|
@ -22,12 +22,12 @@ pygtk.require('2.0')
|
||||||
import gtk
|
import gtk
|
||||||
#import os
|
#import os
|
||||||
#import sys
|
#import sys
|
||||||
#from time import time, strftime
|
from time import time, strftime
|
||||||
|
|
||||||
#import Card
|
#import Card
|
||||||
#import fpdb_import
|
#import fpdb_import
|
||||||
#import Database
|
#import Database
|
||||||
#import Charset
|
import Charset
|
||||||
import TourneyFilters
|
import TourneyFilters
|
||||||
|
|
||||||
class GuiTourneyPlayerStats (threading.Thread):
|
class GuiTourneyPlayerStats (threading.Thread):
|
||||||
|
@ -41,7 +41,7 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
self.liststore = [] # gtk.ListStore[] stores the contents of the grids
|
self.liststore = [] # gtk.ListStore[] stores the contents of the grids
|
||||||
self.listcols = [] # gtk.TreeViewColumn[][] stores the columns in the grids
|
self.listcols = [] # gtk.TreeViewColumn[][] stores the columns in the grids
|
||||||
|
|
||||||
filters_display = { "Heroes" : True,
|
filters_display = { "Heroes" : False,
|
||||||
"Sites" : True,
|
"Sites" : True,
|
||||||
#"Games" : True,
|
#"Games" : True,
|
||||||
#"Limits" : True,
|
#"Limits" : True,
|
||||||
|
@ -67,6 +67,23 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
#self.filters.registerButton1Callback(self.showDetailFilter)
|
#self.filters.registerButton1Callback(self.showDetailFilter)
|
||||||
self.filters.registerButton2Name("_Refresh Stats")
|
self.filters.registerButton2Name("_Refresh Stats")
|
||||||
self.filters.registerButton2Callback(self.refreshStats)
|
self.filters.registerButton2Callback(self.refreshStats)
|
||||||
|
|
||||||
|
# ToDo: store in config
|
||||||
|
# ToDo: create popup to adjust column config
|
||||||
|
# columns to display, keys match column name returned by sql, values in tuple are:
|
||||||
|
# is column displayed, column heading, xalignment, formatting, celltype
|
||||||
|
self.columns = [ ["tourneyTypeId", True, "TTypeId", 0.0, "%s", "str"]
|
||||||
|
, ["tourney", False, "Tourney", 0.0, "%s", "str"] # true not allowed for this line
|
||||||
|
#, ["pname", False, "Name", 0.0, "%s", "str"] # true not allowed for this line (set in code)
|
||||||
|
, ["tourneyCount", True, "#", 1.0, "%1.0f", "str"]
|
||||||
|
, ["1st", False, "1st", 1.0, "%3.1f", "str"]
|
||||||
|
, ["2nd", True, "2nd", 1.0, "%3.1f", "str"]
|
||||||
|
, ["3rd", True, "3rd", 1.0, "%3.1f", "str"]
|
||||||
|
, ["unknownRank", True, "unknown", 1.0, "%3.1f", "str"]
|
||||||
|
, ["itm", True, "ITM", 1.0, "%2.2f", "str"]
|
||||||
|
, ["roi", True, "ROI", 1.0, "%3.1f", "str"]
|
||||||
|
, ["profitPerTourney", True, "$/T", 1.0, "%3.1f", "str"]]
|
||||||
|
|
||||||
self.stats_frame = gtk.Frame()
|
self.stats_frame = gtk.Frame()
|
||||||
self.stats_frame.show()
|
self.stats_frame.show()
|
||||||
|
|
||||||
|
@ -82,8 +99,119 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
self.main_hbox.show()
|
self.main_hbox.show()
|
||||||
#end def __init__
|
#end def __init__
|
||||||
|
|
||||||
def createStatsTable(self, vbox, playerids, sitenos, limits, type, seats, groups, dates, games):
|
def addGrid(self, vbox, query, flags, tourneyTypes, playerids, sitenos, seats, dates):
|
||||||
starttime = time()
|
counter = 0
|
||||||
|
row = 0
|
||||||
|
sqlrow = 0
|
||||||
|
if not flags: holecards,grid = False,0
|
||||||
|
else: holecards,grid = flags[0],flags[2]
|
||||||
|
|
||||||
|
tmp = self.sql.query[query]
|
||||||
|
tmp = self.refineQuery(tmp, flags, tourneyTypes, playerids, sitenos, seats, dates)
|
||||||
|
self.cursor.execute(tmp)
|
||||||
|
result = self.cursor.fetchall()
|
||||||
|
colnames = [desc[0].lower() for desc in self.cursor.description]
|
||||||
|
|
||||||
|
# pre-fetch some constant values:
|
||||||
|
self.cols_to_show = [x for x in self.columns if x[colshow]]
|
||||||
|
hgametypeid_idx = colnames.index('hgametypeid')
|
||||||
|
|
||||||
|
assert len(self.liststore) == grid, "len(self.liststore)="+str(len(self.liststore))+" grid-1="+str(grid)
|
||||||
|
self.liststore.append( gtk.ListStore(*([str] * len(self.cols_to_show))) )
|
||||||
|
view = gtk.TreeView(model=self.liststore[grid])
|
||||||
|
view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
|
||||||
|
#vbox.pack_start(view, expand=False, padding=3)
|
||||||
|
vbox.add(view)
|
||||||
|
textcell = gtk.CellRendererText()
|
||||||
|
textcell50 = gtk.CellRendererText()
|
||||||
|
textcell50.set_property('xalign', 0.5)
|
||||||
|
numcell = gtk.CellRendererText()
|
||||||
|
numcell.set_property('xalign', 1.0)
|
||||||
|
assert len(self.listcols) == grid
|
||||||
|
self.listcols.append( [] )
|
||||||
|
|
||||||
|
# Create header row eg column: ("game", True, "Game", 0.0, "%s")
|
||||||
|
for col, column in enumerate(self.cols_to_show):
|
||||||
|
if column[colalias] == 'game' and holecards:
|
||||||
|
s = [x for x in self.columns if x[colalias] == 'hand'][0][colheading]
|
||||||
|
else:
|
||||||
|
s = column[colheading]
|
||||||
|
self.listcols[grid].append(gtk.TreeViewColumn(s))
|
||||||
|
view.append_column(self.listcols[grid][col])
|
||||||
|
if column[colformat] == '%s':
|
||||||
|
if column[colxalign] == 0.0:
|
||||||
|
self.listcols[grid][col].pack_start(textcell, expand=True)
|
||||||
|
self.listcols[grid][col].add_attribute(textcell, 'text', col)
|
||||||
|
cellrend = textcell
|
||||||
|
else:
|
||||||
|
self.listcols[grid][col].pack_start(textcell50, expand=True)
|
||||||
|
self.listcols[grid][col].add_attribute(textcell50, 'text', col)
|
||||||
|
cellrend = textcell50
|
||||||
|
self.listcols[grid][col].set_expand(True)
|
||||||
|
else:
|
||||||
|
self.listcols[grid][col].pack_start(numcell, expand=True)
|
||||||
|
self.listcols[grid][col].add_attribute(numcell, 'text', col)
|
||||||
|
self.listcols[grid][col].set_expand(True)
|
||||||
|
cellrend = numcell
|
||||||
|
#self.listcols[grid][col].set_alignment(column[colxalign]) # no effect?
|
||||||
|
self.listcols[grid][col].set_clickable(True)
|
||||||
|
self.listcols[grid][col].connect("clicked", self.sortcols, (col,grid))
|
||||||
|
if col == 0:
|
||||||
|
self.listcols[grid][col].set_sort_order(gtk.SORT_DESCENDING)
|
||||||
|
self.listcols[grid][col].set_sort_indicator(True)
|
||||||
|
if column[coltype] == 'cash':
|
||||||
|
self.listcols[grid][col].set_cell_data_func(numcell, self.ledger_style_render_func)
|
||||||
|
else:
|
||||||
|
self.listcols[grid][col].set_cell_data_func(cellrend, self.reset_style_render_func)
|
||||||
|
|
||||||
|
rows = len(result) # +1 for title row
|
||||||
|
|
||||||
|
while sqlrow < rows:
|
||||||
|
treerow = []
|
||||||
|
for col,column in enumerate(self.cols_to_show):
|
||||||
|
if column[colalias] in colnames:
|
||||||
|
value = result[sqlrow][colnames.index(column[colalias])]
|
||||||
|
if column[colalias] == 'plposition':
|
||||||
|
if value == 'B':
|
||||||
|
value = 'BB'
|
||||||
|
elif value == 'S':
|
||||||
|
value = 'SB'
|
||||||
|
elif value == '0':
|
||||||
|
value = 'Btn'
|
||||||
|
else:
|
||||||
|
if column[colalias] == 'game':
|
||||||
|
if holecards:
|
||||||
|
value = Card.twoStartCardString( result[sqlrow][hgametypeid_idx] )
|
||||||
|
else:
|
||||||
|
minbb = result[sqlrow][colnames.index('minbigblind')]
|
||||||
|
maxbb = result[sqlrow][colnames.index('maxbigblind')]
|
||||||
|
value = result[sqlrow][colnames.index('limittype')] + ' ' \
|
||||||
|
+ result[sqlrow][colnames.index('category')].title() + ' ' \
|
||||||
|
+ result[sqlrow][colnames.index('name')] + ' $'
|
||||||
|
if 100 * int(minbb/100.0) != minbb:
|
||||||
|
value += '%.2f' % (minbb/100.0)
|
||||||
|
else:
|
||||||
|
value += '%.0f' % (minbb/100.0)
|
||||||
|
if minbb != maxbb:
|
||||||
|
if 100 * int(maxbb/100.0) != maxbb:
|
||||||
|
value += ' - $' + '%.2f' % (maxbb/100.0)
|
||||||
|
else:
|
||||||
|
value += ' - $' + '%.0f' % (maxbb/100.0)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
if value and value != -999:
|
||||||
|
treerow.append(column[colformat] % value)
|
||||||
|
else:
|
||||||
|
treerow.append(' ')
|
||||||
|
iter = self.liststore[grid].append(treerow)
|
||||||
|
#print treerow
|
||||||
|
sqlrow += 1
|
||||||
|
row += 1
|
||||||
|
vbox.show_all()
|
||||||
|
#end def addGrid
|
||||||
|
|
||||||
|
def createStatsTable(self, vbox, tourneyTypes, playerids, sitenos, seats, dates):
|
||||||
|
startTime = time()
|
||||||
show_detail = True
|
show_detail = True
|
||||||
|
|
||||||
# Scrolled window for summary table
|
# Scrolled window for summary table
|
||||||
|
@ -97,9 +225,9 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
# holecards - whether to display card breakdown (True/False)
|
# holecards - whether to display card breakdown (True/False)
|
||||||
# numhands - min number hands required when displaying all players
|
# numhands - min number hands required when displaying all players
|
||||||
# gridnum - index for grid data structures
|
# gridnum - index for grid data structures
|
||||||
flags = [False, self.filters.getNumHands(), 0]
|
flags = [False, self.filters.getNumTourneys(), 0]
|
||||||
self.addGrid(swin, 'playerDetailedStats', flags, playerids
|
self.addGrid(swin, 'playerDetailedStats', flags, tourneyTypes, playerids
|
||||||
,sitenos, limits, type, seats, groups, dates, games)
|
,sitenos, seats, dates)
|
||||||
|
|
||||||
if 'allplayers' in groups and groups['allplayers']:
|
if 'allplayers' in groups and groups['allplayers']:
|
||||||
# can't currently do this combination so skip detailed table
|
# can't currently do this combination so skip detailed table
|
||||||
|
@ -123,20 +251,20 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
# Detailed table
|
# Detailed table
|
||||||
flags[0] = True
|
flags[0] = True
|
||||||
flags[2] = 1
|
flags[2] = 1
|
||||||
self.addGrid(swin, 'playerDetailedStats', flags, playerids
|
self.addGrid(swin, 'playerDetailedStats', flags, playerids, sitenos, seats, dates)
|
||||||
,sitenos, limits, type, seats, groups, dates, games)
|
|
||||||
|
|
||||||
self.db.rollback()
|
self.db.rollback()
|
||||||
print "Stats page displayed in %4.2f seconds" % (time() - starttime)
|
print "Stats page displayed in %4.2f seconds" % (time() - startTime)
|
||||||
#end def createStatsTable
|
#end def createStatsTable
|
||||||
|
|
||||||
def fillStatsFrame(self, vbox):
|
def fillStatsFrame(self, vbox):
|
||||||
|
tourneyTypes = self.filters.getTourneyTypes()
|
||||||
|
#tourneys = self.tourneys.getTourneys()
|
||||||
sites = self.filters.getSites()
|
sites = self.filters.getSites()
|
||||||
heroes = self.filters.getHeroes()
|
heroes = self.filters.getHeroes()
|
||||||
siteids = self.filters.getSiteIds()
|
siteids = self.filters.getSiteIds()
|
||||||
seats = self.filters.getSeats()
|
seats = self.filters.getSeats()
|
||||||
dates = self.filters.getDates()
|
dates = self.filters.getDates()
|
||||||
games = self.filters.getGames()
|
|
||||||
sitenos = []
|
sitenos = []
|
||||||
playerids = []
|
playerids = []
|
||||||
|
|
||||||
|
@ -156,11 +284,8 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
if not playerids:
|
if not playerids:
|
||||||
print "No player ids found"
|
print "No player ids found"
|
||||||
return
|
return
|
||||||
if not limits:
|
|
||||||
print "No limits found"
|
|
||||||
return
|
|
||||||
|
|
||||||
self.createStatsTable(vbox, playerids, sitenos, limits, type, seats, groups, dates, games)
|
self.createStatsTable(vbox, tourneyTypes, playerids, sitenos, seats, dates)
|
||||||
#end def fillStatsFrame
|
#end def fillStatsFrame
|
||||||
|
|
||||||
def get_vbox(self):
|
def get_vbox(self):
|
||||||
|
@ -168,6 +293,150 @@ class GuiTourneyPlayerStats (threading.Thread):
|
||||||
return self.main_hbox
|
return self.main_hbox
|
||||||
#end def get_vbox
|
#end def get_vbox
|
||||||
|
|
||||||
|
def refineQuery(self, query, flags, tourneyTypes, playerids, sitenos, seats, dates):
|
||||||
|
having = ''
|
||||||
|
holecards = flags[0]
|
||||||
|
numTourneys = flags[1]
|
||||||
|
|
||||||
|
#if 'allplayers' in groups and groups['allplayers']:
|
||||||
|
nametest = "(hp.playerId)"
|
||||||
|
pname = "p.name"
|
||||||
|
# set flag in self.columns to show player name column
|
||||||
|
[x for x in self.columns if x[0] == 'pname'][0][1] = True
|
||||||
|
if numTourneys:
|
||||||
|
having = ' and count(1) > %d ' % (numTourneys,)
|
||||||
|
query = query.replace("<player_test>", nametest)
|
||||||
|
query = query.replace("<playerName>", pname)
|
||||||
|
query = query.replace("<havingclause>", having)
|
||||||
|
|
||||||
|
gametest = ""
|
||||||
|
q = []
|
||||||
|
for m in self.filters.display.items():
|
||||||
|
if m[0] == 'Games' and m[1]:
|
||||||
|
for n in games:
|
||||||
|
if games[n]:
|
||||||
|
q.append(n)
|
||||||
|
if len(q) > 0:
|
||||||
|
gametest = str(tuple(q))
|
||||||
|
gametest = gametest.replace("L", "")
|
||||||
|
gametest = gametest.replace(",)",")")
|
||||||
|
gametest = gametest.replace("u'","'")
|
||||||
|
gametest = "and gt.category in %s" % gametest
|
||||||
|
else:
|
||||||
|
gametest = "and gt.category IS NULL"
|
||||||
|
query = query.replace("<game_test>", gametest)
|
||||||
|
|
||||||
|
sitetest = ""
|
||||||
|
q = []
|
||||||
|
for m in self.filters.display.items():
|
||||||
|
if m[0] == 'Sites' and m[1]:
|
||||||
|
for n in sitenos:
|
||||||
|
q.append(n)
|
||||||
|
if len(q) > 0:
|
||||||
|
sitetest = str(tuple(q))
|
||||||
|
sitetest = sitetest.replace("L", "")
|
||||||
|
sitetest = sitetest.replace(",)",")")
|
||||||
|
sitetest = sitetest.replace("u'","'")
|
||||||
|
sitetest = "and gt.siteId in %s" % sitetest
|
||||||
|
else:
|
||||||
|
sitetest = "and gt.siteId IS NULL"
|
||||||
|
query = query.replace("<site_test>", sitetest)
|
||||||
|
|
||||||
|
if seats:
|
||||||
|
query = query.replace('<seats_test>', 'between ' + str(seats['from']) + ' and ' + str(seats['to']))
|
||||||
|
if 'show' in seats and seats['show']:
|
||||||
|
query = query.replace('<groupbyseats>', ',h.seats')
|
||||||
|
query = query.replace('<orderbyseats>', ',h.seats')
|
||||||
|
else:
|
||||||
|
query = query.replace('<groupbyseats>', '')
|
||||||
|
query = query.replace('<orderbyseats>', '')
|
||||||
|
else:
|
||||||
|
query = query.replace('<seats_test>', 'between 0 and 100')
|
||||||
|
query = query.replace('<groupbyseats>', '')
|
||||||
|
query = query.replace('<orderbyseats>', '')
|
||||||
|
|
||||||
|
lims = [int(x) for x in limits if x.isdigit()]
|
||||||
|
potlims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'pl']
|
||||||
|
nolims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'nl']
|
||||||
|
bbtest = "and ( (gt.limitType = 'fl' and gt.bigBlind in "
|
||||||
|
# and ( (limit and bb in()) or (nolimit and bb in ()) )
|
||||||
|
if lims:
|
||||||
|
blindtest = str(tuple(lims))
|
||||||
|
blindtest = blindtest.replace("L", "")
|
||||||
|
blindtest = blindtest.replace(",)",")")
|
||||||
|
bbtest = bbtest + blindtest + ' ) '
|
||||||
|
else:
|
||||||
|
bbtest = bbtest + '(-1) ) '
|
||||||
|
bbtest = bbtest + " or (gt.limitType = 'pl' and gt.bigBlind in "
|
||||||
|
if potlims:
|
||||||
|
blindtest = str(tuple(potlims))
|
||||||
|
blindtest = blindtest.replace("L", "")
|
||||||
|
blindtest = blindtest.replace(",)",")")
|
||||||
|
bbtest = bbtest + blindtest + ' ) '
|
||||||
|
else:
|
||||||
|
bbtest = bbtest + '(-1) ) '
|
||||||
|
bbtest = bbtest + " or (gt.limitType = 'nl' and gt.bigBlind in "
|
||||||
|
if nolims:
|
||||||
|
blindtest = str(tuple(nolims))
|
||||||
|
blindtest = blindtest.replace("L", "")
|
||||||
|
blindtest = blindtest.replace(",)",")")
|
||||||
|
bbtest = bbtest + blindtest + ' ) )'
|
||||||
|
else:
|
||||||
|
bbtest = bbtest + '(-1) ) )'
|
||||||
|
if type == 'ring':
|
||||||
|
bbtest = bbtest + " and gt.type = 'ring' "
|
||||||
|
elif type == 'tour':
|
||||||
|
bbtest = " and gt.type = 'tour' "
|
||||||
|
query = query.replace("<gtbigBlind_test>", bbtest)
|
||||||
|
|
||||||
|
if holecards: # re-use level variables for hole card query
|
||||||
|
query = query.replace("<hgameTypeId>", "hp.startcards")
|
||||||
|
query = query.replace("<orderbyhgameTypeId>"
|
||||||
|
, ",case when floor((hp.startcards-1)/13) >= mod((hp.startcards-1),13) then hp.startcards + 0.1 "
|
||||||
|
+ " else 13*mod((hp.startcards-1),13) + floor((hp.startcards-1)/13) + 1 "
|
||||||
|
+ " end desc ")
|
||||||
|
else:
|
||||||
|
query = query.replace("<orderbyhgameTypeId>", "")
|
||||||
|
groupLevels = "show" not in str(limits)
|
||||||
|
if groupLevels:
|
||||||
|
query = query.replace("<hgameTypeId>", "p.name") # need to use p.name for sqlite posn stats to work
|
||||||
|
else:
|
||||||
|
query = query.replace("<hgameTypeId>", "h.gameTypeId")
|
||||||
|
|
||||||
|
# process self.detailFilters (a list of tuples)
|
||||||
|
flagtest = ''
|
||||||
|
#self.detailFilters = [('h.seats', 5, 6)] # for debug
|
||||||
|
if self.detailFilters:
|
||||||
|
for f in self.detailFilters:
|
||||||
|
if len(f) == 3:
|
||||||
|
# X between Y and Z
|
||||||
|
flagtest += ' and %s between %s and %s ' % (f[0], str(f[1]), str(f[2]))
|
||||||
|
query = query.replace("<flagtest>", flagtest)
|
||||||
|
|
||||||
|
# allow for differences in sql cast() function:
|
||||||
|
if self.db.backend == self.MYSQL_INNODB:
|
||||||
|
query = query.replace("<signed>", 'signed ')
|
||||||
|
else:
|
||||||
|
query = query.replace("<signed>", '')
|
||||||
|
|
||||||
|
# Filter on dates
|
||||||
|
query = query.replace("<datestest>", " between '" + dates[0] + "' and '" + dates[1] + "'")
|
||||||
|
|
||||||
|
# Group by position?
|
||||||
|
if groups['posn']:
|
||||||
|
#query = query.replace("<position>", "case hp.position when '0' then 'Btn' else hp.position end")
|
||||||
|
query = query.replace("<position>", "hp.position")
|
||||||
|
# set flag in self.columns to show posn column
|
||||||
|
[x for x in self.columns if x[0] == 'plposition'][0][1] = True
|
||||||
|
else:
|
||||||
|
query = query.replace("<position>", "gt.base")
|
||||||
|
# unset flag in self.columns to hide posn column
|
||||||
|
[x for x in self.columns if x[0] == 'plposition'][0][1] = False
|
||||||
|
|
||||||
|
#print "query =\n", query
|
||||||
|
return(query)
|
||||||
|
#end def refineQuery
|
||||||
|
|
||||||
def refreshStats(self, widget, data):
|
def refreshStats(self, widget, data):
|
||||||
self.last_pos = self.stats_vbox.get_position()
|
self.last_pos = self.stats_vbox.get_position()
|
||||||
try: self.stats_vbox.destroy()
|
try: self.stats_vbox.destroy()
|
||||||
|
|
|
@ -92,6 +92,8 @@ class Sql:
|
||||||
|
|
||||||
self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
|
self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
|
||||||
|
|
||||||
|
self.query['getTourneyTypesIds'] = "SELECT id FROM TourneyTypes"
|
||||||
|
|
||||||
################################
|
################################
|
||||||
# Create Settings
|
# Create Settings
|
||||||
################################
|
################################
|
||||||
|
@ -3834,9 +3836,16 @@ class Sql:
|
||||||
%s
|
%s
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Counts for DB stats window
|
||||||
|
################################
|
||||||
self.query['getHandCount'] = "SELECT COUNT(id) FROM Hands"
|
self.query['getHandCount'] = "SELECT COUNT(id) FROM Hands"
|
||||||
|
|
||||||
self.query['getTourneyCount'] = "SELECT COUNT(id) FROM Tourneys"
|
self.query['getTourneyCount'] = "SELECT COUNT(id) FROM Tourneys"
|
||||||
|
|
||||||
|
################################
|
||||||
|
# placeholders and substitution stuff
|
||||||
|
################################
|
||||||
if db_server == 'mysql':
|
if db_server == 'mysql':
|
||||||
self.query['placeholder'] = u'%s'
|
self.query['placeholder'] = u'%s'
|
||||||
elif db_server == 'postgresql':
|
elif db_server == 'postgresql':
|
||||||
|
|
|
@ -23,7 +23,7 @@ import gobject
|
||||||
#import os
|
#import os
|
||||||
#import sys
|
#import sys
|
||||||
#from optparse import OptionParser
|
#from optparse import OptionParser
|
||||||
#from time import *
|
from time import gmtime, mktime, strftime, strptime
|
||||||
#import pokereval
|
#import pokereval
|
||||||
|
|
||||||
import logging #logging has been set up in fpdb.py or HUD_main.py, use their settings:
|
import logging #logging has been set up in fpdb.py or HUD_main.py, use their settings:
|
||||||
|
@ -45,7 +45,13 @@ class TourneyFilters(threading.Thread):
|
||||||
self.display = display
|
self.display = display
|
||||||
|
|
||||||
self.filterText = {'playerstitle':'Hero:', 'sitestitle':'Sites:', 'seatstitle':'Number of Players:',
|
self.filterText = {'playerstitle':'Hero:', 'sitestitle':'Sites:', 'seatstitle':'Number of Players:',
|
||||||
'seatsbetween':'Between:', 'seatsand':'And:', 'datestitle':'Date:'}
|
'seatsbetween':'Between:', 'seatsand':'And:', 'datestitle':'Date:',
|
||||||
|
'tourneyTypesTitle':'Tourney Type'}
|
||||||
|
|
||||||
|
gen = self.conf.get_general_params()
|
||||||
|
self.day_start = 0
|
||||||
|
if 'day_start' in gen:
|
||||||
|
self.day_start = float(gen['day_start'])
|
||||||
|
|
||||||
# Outer Packing box
|
# Outer Packing box
|
||||||
self.mainVBox = gtk.VBox(False, 0)
|
self.mainVBox = gtk.VBox(False, 0)
|
||||||
|
@ -79,19 +85,44 @@ class TourneyFilters(threading.Thread):
|
||||||
self.end_date.set_text('')
|
self.end_date.set_text('')
|
||||||
#end def __clear_dates
|
#end def __clear_dates
|
||||||
|
|
||||||
|
def __get_dates(self):
|
||||||
|
# self.day_start gives user's start of day in hours
|
||||||
|
offset = int(self.day_start * 3600) # calc day_start in seconds
|
||||||
|
|
||||||
|
t1 = self.start_date.get_text()
|
||||||
|
t2 = self.end_date.get_text()
|
||||||
|
|
||||||
|
if t1 == '':
|
||||||
|
t1 = '1970-01-02'
|
||||||
|
if t2 == '':
|
||||||
|
t2 = '2020-12-12'
|
||||||
|
|
||||||
|
s1 = strptime(t1, "%Y-%m-%d") # make time_struct
|
||||||
|
s2 = strptime(t2, "%Y-%m-%d")
|
||||||
|
e1 = mktime(s1) + offset # s1 is localtime, but returned time since epoch is UTC, then add the
|
||||||
|
e2 = mktime(s2) + offset # s2 is localtime, but returned time since epoch is UTC
|
||||||
|
e2 = e2 + 24 * 3600 - 1 # date test is inclusive, so add 23h 59m 59s to e2
|
||||||
|
|
||||||
|
adj_t1 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e1)) # make adjusted string including time
|
||||||
|
adj_t2 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e2))
|
||||||
|
log.info("t1="+t1+" adj_t1="+adj_t1+'.')
|
||||||
|
|
||||||
|
return (adj_t1, adj_t2)
|
||||||
|
#end def __get_dates
|
||||||
|
|
||||||
def __refresh(self, widget, entry):
|
def __refresh(self, widget, entry):
|
||||||
for w in self.mainVBox.get_children():
|
for w in self.mainVBox.get_children():
|
||||||
w.destroy()
|
w.destroy()
|
||||||
self.make_filter()
|
self.make_filter()
|
||||||
#end def __refresh
|
#end def __refresh
|
||||||
|
|
||||||
def __set_hero_name(self, w, site):
|
def __set_num_tourneys(self, w, val):
|
||||||
_name = w.get_text()
|
try:
|
||||||
#get_text() returns a str but we want internal variables to be unicode:
|
self.numTourneys = int(w.get_text())
|
||||||
_guiname = unicode(_name)
|
except:
|
||||||
self.heroes[site] = _guiname
|
self.numTourneys = 0
|
||||||
#log.debug("setting heroes[%s]: %s"%(site, self.heroes[site]))
|
print "setting numTourneys:", self.numTourneys
|
||||||
#end def __set_hero_name
|
#end def __set_num_tourneys
|
||||||
|
|
||||||
def __set_seat_select(self, w, seat):
|
def __set_seat_select(self, w, seat):
|
||||||
#print "__set_seat_select: seat =", seat, "active =", w.get_active()
|
#print "__set_seat_select: seat =", seat, "active =", w.get_active()
|
||||||
|
@ -105,6 +136,12 @@ class TourneyFilters(threading.Thread):
|
||||||
log.debug("self.sites[%s] set to %s" %(site, self.sites[site]))
|
log.debug("self.sites[%s] set to %s" %(site, self.sites[site]))
|
||||||
#end def __set_site_select
|
#end def __set_site_select
|
||||||
|
|
||||||
|
def __set_tourney_type_select(self, w, tourneyType):
|
||||||
|
#print w.get_active()
|
||||||
|
self.tourneyTypes[tourneyType] = w.get_active()
|
||||||
|
log.debug("self.tourney_types[%s] set to %s" %(tourneyType, self.tourneyTypes[tourneyType]))
|
||||||
|
#end def __set_tourney_type_select
|
||||||
|
|
||||||
def __toggle_box(self, widget, entry):
|
def __toggle_box(self, widget, entry):
|
||||||
if self.boxes[entry].props.visible:
|
if self.boxes[entry].props.visible:
|
||||||
self.boxes[entry].hide()
|
self.boxes[entry].hide()
|
||||||
|
@ -123,7 +160,7 @@ class TourneyFilters(threading.Thread):
|
||||||
pname.set_text(player)
|
pname.set_text(player)
|
||||||
pname.set_width_chars(20)
|
pname.set_width_chars(20)
|
||||||
hbox.pack_start(pname, False, True, 0)
|
hbox.pack_start(pname, False, True, 0)
|
||||||
pname.connect("changed", self.__set_hero_name, site)
|
#pname.connect("changed", self.__set_hero_name, site)
|
||||||
|
|
||||||
# Added EntryCompletion but maybe comboBoxEntry is more flexible? (e.g. multiple choices)
|
# Added EntryCompletion but maybe comboBoxEntry is more flexible? (e.g. multiple choices)
|
||||||
completion = gtk.EntryCompletion()
|
completion = gtk.EntryCompletion()
|
||||||
|
@ -137,7 +174,7 @@ class TourneyFilters(threading.Thread):
|
||||||
_nt = (_n, )
|
_nt = (_n, )
|
||||||
liststore.append(_nt)
|
liststore.append(_nt)
|
||||||
|
|
||||||
self.__set_hero_name(pname, site)
|
#self.__set_hero_name(pname, site)
|
||||||
#end def createPlayerLine
|
#end def createPlayerLine
|
||||||
|
|
||||||
def createSiteLine(self, hbox, site):
|
def createSiteLine(self, hbox, site):
|
||||||
|
@ -147,6 +184,13 @@ class TourneyFilters(threading.Thread):
|
||||||
hbox.pack_start(cb, False, False, 0)
|
hbox.pack_start(cb, False, False, 0)
|
||||||
#end def createSiteLine
|
#end def createSiteLine
|
||||||
|
|
||||||
|
def createTourneyTypeLine(self, hbox, tourneyType):
|
||||||
|
cb = gtk.CheckButton(str(tourneyType))
|
||||||
|
cb.connect('clicked', self.__set_tourney_type_select, tourneyType)
|
||||||
|
hbox.pack_start(cb, False, False, 0)
|
||||||
|
cb.set_active(True)
|
||||||
|
#end def createTourneyTypeLine
|
||||||
|
|
||||||
def fillDateFrame(self, vbox):
|
def fillDateFrame(self, vbox):
|
||||||
# Hat tip to Mika Bostrom - calendar code comes from PokerStats
|
# Hat tip to Mika Bostrom - calendar code comes from PokerStats
|
||||||
top_hbox = gtk.HBox(False, 0)
|
top_hbox = gtk.HBox(False, 0)
|
||||||
|
@ -217,6 +261,24 @@ class TourneyFilters(threading.Thread):
|
||||||
_pname = Charset.to_gui(player)
|
_pname = Charset.to_gui(player)
|
||||||
self.createPlayerLine(hBox, site, _pname)
|
self.createPlayerLine(hBox, site, _pname)
|
||||||
|
|
||||||
|
hbox = gtk.HBox(False, 0)
|
||||||
|
vbox1.pack_start(hbox, False, False, 0)
|
||||||
|
#cb = gtk.CheckButton(self.filterText['groupsall'])
|
||||||
|
#cb.connect('clicked', self.__set_group_select, 'allplayers')
|
||||||
|
#hbox.pack_start(cb, False, False, 0)
|
||||||
|
#self.sbGroups['allplayers'] = cb
|
||||||
|
#self.groups['allplayers'] = False
|
||||||
|
|
||||||
|
#lbl = gtk.Label('Min # Hands:')
|
||||||
|
#lbl.set_alignment(xalign=1.0, yalign=0.5)
|
||||||
|
#hbox.pack_start(lbl, expand=True, padding=3)
|
||||||
|
|
||||||
|
#phands = gtk.Entry()
|
||||||
|
#phands.set_text('0')
|
||||||
|
#phands.set_width_chars(8)
|
||||||
|
#hbox.pack_start(phands, False, False, 0)
|
||||||
|
#phands.connect("changed", self.__set_num_hands, site)
|
||||||
|
|
||||||
top_hbox.pack_start(showb, expand=False, padding=1)
|
top_hbox.pack_start(showb, expand=False, padding=1)
|
||||||
#end def fillPlayerFrame
|
#end def fillPlayerFrame
|
||||||
|
|
||||||
|
@ -279,12 +341,72 @@ class TourneyFilters(threading.Thread):
|
||||||
self.createSiteLine(hbox, site)
|
self.createSiteLine(hbox, site)
|
||||||
#end def fillSitesFrame
|
#end def fillSitesFrame
|
||||||
|
|
||||||
|
def fillTourneyTypesFrame(self, vbox):
|
||||||
|
top_hbox = gtk.HBox(False, 0)
|
||||||
|
vbox.pack_start(top_hbox, False, False, 0)
|
||||||
|
lbl_title = gtk.Label(self.filterText['tourneyTypesTitle'])
|
||||||
|
lbl_title.set_alignment(xalign=0.0, yalign=0.5)
|
||||||
|
top_hbox.pack_start(lbl_title, expand=True, padding=3)
|
||||||
|
showb = gtk.Button(label="hide", stock=None, use_underline=True)
|
||||||
|
showb.set_alignment(xalign=1.0, yalign=0.5)
|
||||||
|
showb.connect('clicked', self.__toggle_box, 'tourneyTypes')
|
||||||
|
top_hbox.pack_start(showb, expand=False, padding=1)
|
||||||
|
|
||||||
|
vbox1 = gtk.VBox(False, 0)
|
||||||
|
vbox.pack_start(vbox1, False, False, 0)
|
||||||
|
self.boxes['tourneyTypes'] = vbox1
|
||||||
|
|
||||||
|
result = self.db.getTourneyTypesIds()
|
||||||
|
if len(result) >= 1:
|
||||||
|
for line in result:
|
||||||
|
hbox = gtk.HBox(False, 0)
|
||||||
|
vbox1.pack_start(hbox, False, True, 0)
|
||||||
|
self.createTourneyTypeLine(hbox, line[0])
|
||||||
|
else:
|
||||||
|
print "INFO: No tourney types returned from database"
|
||||||
|
log.info("No tourney types returned from database")
|
||||||
|
#end def fillTourneyTypesFrame
|
||||||
|
|
||||||
|
def getDates(self):
|
||||||
|
return self.__get_dates()
|
||||||
|
#end def getDates
|
||||||
|
|
||||||
|
def getHeroes(self):
|
||||||
|
return self.heroes
|
||||||
|
#end def getHeroes
|
||||||
|
|
||||||
|
def getNumTourneys(self):
|
||||||
|
return self.numTourneys
|
||||||
|
#end def getNumTourneys
|
||||||
|
|
||||||
|
def getSeats(self):
|
||||||
|
if 'from' in self.sbSeats:
|
||||||
|
self.seats['from'] = self.sbSeats['from'].get_value_as_int()
|
||||||
|
if 'to' in self.sbSeats:
|
||||||
|
self.seats['to'] = self.sbSeats['to'].get_value_as_int()
|
||||||
|
return self.seats
|
||||||
|
#end def getSeats
|
||||||
|
|
||||||
|
def getSiteIds(self):
|
||||||
|
return self.siteid
|
||||||
|
#end def getSiteIds
|
||||||
|
|
||||||
|
def getSites(self):
|
||||||
|
return self.sites
|
||||||
|
#end def getSites
|
||||||
|
|
||||||
|
def getTourneyTypes(self):
|
||||||
|
return self.tourneyTypes
|
||||||
|
#end def getTourneyTypes
|
||||||
|
|
||||||
def get_vbox(self):
|
def get_vbox(self):
|
||||||
"""returns the vbox of this thread"""
|
"""returns the vbox of this thread"""
|
||||||
return self.mainVBox
|
return self.mainVBox
|
||||||
#end def get_vbox
|
#end def get_vbox
|
||||||
|
|
||||||
def make_filter(self):
|
def make_filter(self):
|
||||||
|
self.tourneyTypes = {}
|
||||||
|
#self.tourneys = {}
|
||||||
self.sites = {}
|
self.sites = {}
|
||||||
self.seats = {}
|
self.seats = {}
|
||||||
self.siteid = {}
|
self.siteid = {}
|
||||||
|
@ -324,6 +446,15 @@ class TourneyFilters(threading.Thread):
|
||||||
self.fillSitesFrame(vbox)
|
self.fillSitesFrame(vbox)
|
||||||
sitesFrame.add(vbox)
|
sitesFrame.add(vbox)
|
||||||
|
|
||||||
|
# Tourney types
|
||||||
|
tourneyTypesFrame = gtk.Frame()
|
||||||
|
tourneyTypesFrame.set_label_align(0.0, 0.0)
|
||||||
|
tourneyTypesFrame.show()
|
||||||
|
vbox = gtk.VBox(False, 0)
|
||||||
|
|
||||||
|
self.fillTourneyTypesFrame(vbox)
|
||||||
|
tourneyTypesFrame.add(vbox)
|
||||||
|
|
||||||
# Seats
|
# Seats
|
||||||
seatsFrame = gtk.Frame()
|
seatsFrame = gtk.Frame()
|
||||||
seatsFrame.show()
|
seatsFrame.show()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user