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

View File

@ -65,6 +65,7 @@ class GuiPlayerStats (threading.Thread):
"SeatSep" : True, "SeatSep" : True,
"Dates" : True, "Dates" : True,
"Groups" : True, "Groups" : True,
"GroupsAll" : True,
"Button1" : True, "Button1" : True,
"Button2" : True "Button2" : True
} }
@ -198,7 +199,6 @@ class GuiPlayerStats (threading.Thread):
def createStatsTable(self, vbox, playerids, sitenos, limits, type, seats, groups, dates): def createStatsTable(self, vbox, playerids, sitenos, limits, type, seats, groups, dates):
starttime = time() starttime = time()
#groups['allplayers'] = True # testing
# Scrolled window for summary table # Scrolled window for summary table
swin = gtk.ScrolledWindow(hadjustment=None, vadjustment=None) swin = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
@ -214,35 +214,38 @@ class GuiPlayerStats (threading.Thread):
# Display summary table at top of page # Display summary table at top of page
# 3rd parameter passes extra flags, currently includes: # 3rd parameter passes extra flags, currently includes:
# holecards - whether to display card breakdown (True/False) # 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) 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) # Only display one section if all players being shown (query currently too slow for startcards)
if 'allplayers' in groups and groups['allplayers']: #if 'allplayers' in groups and groups['allplayers'] and 1==2:
return # return
# Separator # Separator
#sep = gtk.HSeparator() #sep = gtk.HSeparator()
#vbox.pack_start(sep, expand=False, padding=3) #vbox.pack_start(sep, expand=False, padding=3)
#sep.show_now() #sep.show_now()
#vbox.show_now() #vbox.show_now()
#heading = gtk.Label(self.filterText['handhead']) vbox2 = gtk.VBox(False, 0)
#heading.show() heading = gtk.Label(self.filterText['handhead'])
#vbox.pack_start(heading, expand=False, padding=3) heading.show()
vbox2.pack_start(heading, expand=False, padding=3)
# Scrolled window for detailed table (display by hand) # Scrolled window for detailed table (display by hand)
swin = gtk.ScrolledWindow(hadjustment=None, vadjustment=None) swin = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin.show() swin.show()
#vbox.pack_start(swin, expand=True, padding=3) vbox2.pack_start(swin, expand=True, padding=3)
vbox.pack2(swin) vbox.pack2(vbox2)
vbox2.show()
vbox1 = gtk.VBox(False, 0) vbox1 = gtk.VBox(False, 0)
vbox1.show() vbox1.show()
swin.add_with_viewport(vbox1) swin.add_with_viewport(vbox1)
# Detailed table # Detailed table
flags = [True] flags[0] = True
self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, type, seats, groups, dates) self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, type, seats, groups, dates)
self.db.rollback() self.db.rollback()
@ -346,13 +349,29 @@ class GuiPlayerStats (threading.Thread):
#end def addTable(self, query, vars, playerids, sitenos, limits, type, seats, groups, dates): #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): def refineQuery(self, query, flags, playerids, sitenos, limits, type, seats, groups, dates):
if not flags: holecards = False having = ''
else: holecards = flags[0] if not flags:
holecards = False
numhands = 0
else:
holecards = flags[0]
numhands = flags[1]
if 'allplayers' in groups and groups['allplayers']: if 'allplayers' in groups and groups['allplayers']:
nametest = "(select id from players)" 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 # set flag in self.columns to show player name column
[x for x in self.columns if x[0] == 'pname'][0][1] = True [x for x in self.columns if x[0] == 'pname'][0][1] = True
if numhands:
having = ' and count(1) > %d ' % (numhands,)
else: else:
if playerids: if playerids:
nametest = str(tuple(playerids)) nametest = str(tuple(playerids))
@ -360,7 +379,12 @@ class GuiPlayerStats (threading.Thread):
nametest = nametest.replace(",)",")") nametest = nametest.replace(",)",")")
else: else:
nametest = "1 = 2" 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("<player_test>", nametest)
query = query.replace("<playerName>", pname)
query = query.replace("<havingclause>", having)
if seats: if seats:
query = query.replace('<seats_test>', 'between ' + str(seats['from']) + ' and ' + str(seats['to'])) 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': elif db_server == 'postgresql':
self.query['playerDetailedStats'] = """ self.query['playerDetailedStats'] = """
select <hgameTypeId> AS hgametypeid select <hgameTypeId> AS hgametypeid
,p.name AS pname ,<playerName> AS pname
,gt.base ,gt.base
,gt.category ,gt.category
,upper(gt.limitType) AS limittype ,upper(gt.limitType) AS limittype
@ -1867,15 +1867,14 @@ class Sql:
and to_char(h.handStart, 'YYYY-MM-DD') <datestest> and to_char(h.handStart, 'YYYY-MM-DD') <datestest>
group by hgameTypeId group by hgameTypeId
,pname ,pname
,hp.playerId
,gt.base ,gt.base
,gt.category ,gt.category
<groupbyseats> <groupbyseats>
,plposition ,plposition
,upper(gt.limitType) ,upper(gt.limitType)
,s.name ,s.name
having 1 = 1 <havingclause>
order by pname order by pname
,hp.playerId
,gt.base ,gt.base
,gt.category ,gt.category
<orderbyseats> <orderbyseats>