add all player (and min hands) ability to stats window

This commit is contained in:
sqlcoder 2009-10-18 22:56:10 +01:00
parent 6453154ef6
commit c1a998b7d8
3 changed files with 80 additions and 24 deletions

View File

@ -55,6 +55,7 @@ class Filters(threading.Thread):
,'seatsbetween':'Between:', 'seatsand':'And:', 'seatsshow':'Show Number of _Players'
,'limitstitle':'Limits:', 'seatstitle':'Number of Players:'
,'groupstitle':'Grouping:', 'posnshow':'Show Position Stats:'
,'groupsall':'All Players'
,'limitsFL':'FL', 'limitsNL':'NL', 'ring':'Ring', 'tour':'Tourney'
}
@ -64,6 +65,10 @@ class Filters(threading.Thread):
self.start_date.set_property('editable', False)
self.end_date.set_property('editable', False)
# For use in groups etc
self.sbGroups = {}
self.numHands = 0
# Outer Packing box
self.mainVBox = gtk.VBox(False, 0)
@ -71,7 +76,7 @@ class Filters(threading.Thread):
playerFrame.set_label_align(0.0, 0.0)
vbox = gtk.VBox(False, 0)
self.fillPlayerFrame(vbox)
self.fillPlayerFrame(vbox, self.display)
playerFrame.add(vbox)
self.boxes['player'] = vbox
@ -122,7 +127,6 @@ class Filters(threading.Thread):
groupsFrame = gtk.Frame()
groupsFrame.show()
vbox = gtk.VBox(False, 0)
self.sbGroups = {}
self.fillGroupsFrame(vbox, self.display)
groupsFrame.add(vbox)
@ -181,6 +185,9 @@ class Filters(threading.Thread):
return self.mainVBox
#end def get_vbox
def getNumHands(self):
return self.numHands
def getSites(self):
return self.sites
@ -256,6 +263,13 @@ class Filters(threading.Thread):
self.heroes[site] = w.get_text()
# print "DEBUG: setting heroes[%s]: %s"%(site, self.heroes[site])
def __set_num_hands(self, w, val):
try:
self.numHands = int(w.get_text())
except:
self.numHands = 0
print "DEBUG: setting numHands:", self.numHands
def createSiteLine(self, hbox, site):
cb = gtk.CheckButton(site)
cb.connect('clicked', self.__set_site_select, site)
@ -393,13 +407,32 @@ class Filters(threading.Thread):
self.groups[group] = w.get_active()
print "self.groups[%s] set to %s" %(group, self.groups[group])
def fillPlayerFrame(self, vbox):
def fillPlayerFrame(self, vbox, display):
for site in self.conf.get_supported_sites():
pathHBox = gtk.HBox(False, 0)
vbox.pack_start(pathHBox, False, True, 0)
hBox = gtk.HBox(False, 0)
vbox.pack_start(hBox, False, True, 0)
player = self.conf.supported_sites[site].screen_name
self.createPlayerLine(pathHBox, site, player)
self.createPlayerLine(hBox, site, player)
if "GroupsAll" in display and display["GroupsAll"] == True:
hbox = gtk.HBox(False, 0)
vbox.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)
def fillSitesFrame(self, vbox):
for site in self.conf.get_supported_sites():

View File

@ -65,6 +65,7 @@ class GuiPlayerStats (threading.Thread):
"SeatSep" : True,
"Dates" : True,
"Groups" : True,
"GroupsAll" : True,
"Button1" : True,
"Button2" : True
}
@ -198,7 +199,6 @@ class GuiPlayerStats (threading.Thread):
def createStatsTable(self, vbox, playerids, sitenos, limits, type, seats, groups, dates):
starttime = time()
#groups['allplayers'] = True # testing
# Scrolled window for summary table
swin = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
@ -214,35 +214,38 @@ class GuiPlayerStats (threading.Thread):
# Display summary table at top of page
# 3rd parameter passes extra flags, currently includes:
# holecards - whether to display card breakdown (True/False)
flags = [False]
# numhands - min number hands required when displaying all players
flags = [False, self.filters.getNumHands()]
self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, type, seats, groups, dates)
# Only display one section if all players being shown (query currently too slow for startcards)
if 'allplayers' in groups and groups['allplayers']:
return
#if 'allplayers' in groups and groups['allplayers'] and 1==2:
# return
# Separator
#sep = gtk.HSeparator()
#vbox.pack_start(sep, expand=False, padding=3)
#sep.show_now()
#vbox.show_now()
#heading = gtk.Label(self.filterText['handhead'])
#heading.show()
#vbox.pack_start(heading, expand=False, padding=3)
vbox2 = gtk.VBox(False, 0)
heading = gtk.Label(self.filterText['handhead'])
heading.show()
vbox2.pack_start(heading, expand=False, padding=3)
# Scrolled window for detailed table (display by hand)
swin = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin.show()
#vbox.pack_start(swin, expand=True, padding=3)
vbox.pack2(swin)
vbox2.pack_start(swin, expand=True, padding=3)
vbox.pack2(vbox2)
vbox2.show()
vbox1 = gtk.VBox(False, 0)
vbox1.show()
swin.add_with_viewport(vbox1)
# Detailed table
flags = [True]
flags[0] = True
self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, type, seats, groups, dates)
self.db.rollback()
@ -346,13 +349,29 @@ class GuiPlayerStats (threading.Thread):
#end def addTable(self, query, vars, playerids, sitenos, limits, type, seats, groups, dates):
def refineQuery(self, query, flags, playerids, sitenos, limits, type, seats, groups, dates):
if not flags: holecards = False
else: holecards = flags[0]
having = ''
if not flags:
holecards = False
numhands = 0
else:
holecards = flags[0]
numhands = flags[1]
if 'allplayers' in groups and groups['allplayers']:
nametest = "(select id from players)"
# set flag in self.columns to show player name column
[x for x in self.columns if x[0] == 'pname'][0][1] = True
nametest = "(hp.playerId)"
if holecards or groups['posn']:
pname = "'all players'"
# set flag in self.columns to not show player name column
[x for x in self.columns if x[0] == 'pname'][0][1] = False
# can't do this yet (re-write doing more maths in python instead of sql?)
if numhands:
nametest = "(-1)"
else:
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 numhands:
having = ' and count(1) > %d ' % (numhands,)
else:
if playerids:
nametest = str(tuple(playerids))
@ -360,7 +379,12 @@ class GuiPlayerStats (threading.Thread):
nametest = nametest.replace(",)",")")
else:
nametest = "1 = 2"
pname = "p.name"
# set flag in self.columns to not show player name column
[x for x in self.columns if x[0] == 'pname'][0][1] = False
query = query.replace("<player_test>", nametest)
query = query.replace("<playerName>", pname)
query = query.replace("<havingclause>", having)
if seats:
query = query.replace('<seats_test>', 'between ' + str(seats['from']) + ' and ' + str(seats['to']))

View File

@ -1807,7 +1807,7 @@ class Sql:
elif db_server == 'postgresql':
self.query['playerDetailedStats'] = """
select <hgameTypeId> AS hgametypeid
,p.name AS pname
,<playerName> AS pname
,gt.base
,gt.category
,upper(gt.limitType) AS limittype
@ -1867,15 +1867,14 @@ class Sql:
and to_char(h.handStart, 'YYYY-MM-DD') <datestest>
group by hgameTypeId
,pname
,hp.playerId
,gt.base
,gt.category
<groupbyseats>
,plposition
,upper(gt.limitType)
,s.name
having 1 = 1 <havingclause>
order by pname
,hp.playerId
,gt.base
,gt.category
<orderbyseats>