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

This commit is contained in:
Worros 2009-10-13 13:22:08 +08:00
commit e7a7229dc0
3 changed files with 130 additions and 35 deletions

View File

@ -54,7 +54,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:'
,'limitsFL':'FL', 'limitsNL':'NL'
,'limitsFL':'FL', 'limitsNL':'NL', 'ring':'Ring', 'tour':'Tourney'
}
# For use in date ranges.
@ -101,6 +101,9 @@ class Filters(threading.Thread):
self.cbAllLimits = None
self.cbFL = None
self.cbNL = None
self.rb = {} # radio buttons for ring/tour
self.type = None # ring/tour
self.types = {} # list of all ring/tour values
self.fillLimitsFrame(vbox, self.display)
limitsFrame.add(vbox)
@ -193,6 +196,9 @@ class Filters(threading.Thread):
ltuple.append(l)
return ltuple
def getType(self):
return(self.type)
def getSeats(self):
if 'from' in self.sbSeats:
self.seats['from'] = self.sbSeats['from'].get_value_as_int()
@ -282,13 +288,18 @@ class Filters(threading.Thread):
#print w.get_active()
self.limits[limit] = w.get_active()
print "self.limit[%s] set to %s" %(limit, self.limits[limit])
if str(limit).isdigit():
if limit.isdigit() or (len(limit) > 2 and limit[-2:] == 'nl'):
if self.limits[limit]:
if self.cbNoLimits != None:
self.cbNoLimits.set_active(False)
else:
if self.cbAllLimits != None:
self.cbAllLimits.set_active(False)
if not self.limits[limit]:
if limit.isdigit():
self.cbFL.set_active(False)
else:
self.cbNL.set_active(False)
elif limit == "all":
if self.limits[limit]:
#for cb in self.cbLimits.values():
@ -304,16 +315,72 @@ class Filters(threading.Thread):
self.cbNL.set_active(False)
self.cbFL.set_active(False)
elif limit == "fl":
if not self.limits[limit]:
# only toggle all fl limits off if they are all currently on
# this stops turning one off from cascading into 'fl' box off
# and then all fl limits being turned off
all_fl_on = True
for cb in self.cbLimits.values():
t = cb.get_children()[0].get_text()
if t.isdigit():
if not cb.get_active():
all_fl_on = False
found = {'ring':False, 'tour':False}
for cb in self.cbLimits.values():
#print "cb label: ", cb.children()[0].get_text()
if cb.get_children()[0].get_text().isdigit():
cb.set_active(self.limits[limit])
t = cb.get_children()[0].get_text()
if t.isdigit():
if self.limits[limit] or all_fl_on:
cb.set_active(self.limits[limit])
found[self.types[t]] = True
if self.limits[limit]:
if not found[self.type]:
if self.type == 'ring':
if 'tour' in self.rb:
self.rb['tour'].set_active(True)
elif self.type == 'tour':
if 'ring' in self.rb:
self.rb['ring'].set_active(True)
elif limit == "nl":
if not self.limits[limit]:
# only toggle all nl limits off if they are all currently on
# this stops turning one off from cascading into 'nl' box off
# and then all nl limits being turned off
all_nl_on = True
for cb in self.cbLimits.values():
t = cb.get_children()[0].get_text()
if "nl" in t and len(t) > 2:
if not cb.get_active():
all_nl_on = False
found = {'ring':False, 'tour':False}
for cb in self.cbLimits.values():
t = cb.get_children()[0].get_text()
if "nl" in t and len(t) > 2:
cb.set_active(self.limits[limit])
if self.limits[limit] or all_nl_on:
cb.set_active(self.limits[limit])
found[self.types[t]] = True
if self.limits[limit]:
if not found[self.type]:
if self.type == 'ring':
self.rb['tour'].set_active(True)
elif self.type == 'tour':
self.rb['ring'].set_active(True)
elif limit == "ring":
print "set", limit, "to", self.limits[limit]
if self.limits[limit]:
self.type = "ring"
for cb in self.cbLimits.values():
#print "cb label: ", cb.children()[0].get_text()
if self.types[cb.get_children()[0].get_text()] == 'tour':
cb.set_active(False)
elif limit == "tour":
print "set", limit, "to", self.limits[limit]
if self.limits[limit]:
self.type = "tour"
for cb in self.cbLimits.values():
#print "cb label: ", cb.children()[0].get_text()
if self.types[cb.get_children()[0].get_text()] == 'ring':
cb.set_active(False)
def __set_seat_select(self, w, seat):
#print "__set_seat_select: seat =", seat, "active =", w.get_active()
@ -358,15 +425,14 @@ class Filters(threading.Thread):
print "INFO: No games returned from database"
def fillLimitsFrame(self, vbox, display):
hbox = gtk.HBox(False, 0)
vbox.pack_start(hbox, False, False, 0)
top_hbox = gtk.HBox(False, 0)
vbox.pack_start(top_hbox, False, False, 0)
lbl_title = gtk.Label(self.filterText['limitstitle'])
lbl_title.set_alignment(xalign=0.0, yalign=0.5)
hbox.pack_start(lbl_title, expand=True, padding=3)
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, 'limits')
hbox.pack_start(showb, expand=False, padding=1)
vbox1 = gtk.VBox(False, 0)
vbox.pack_start(vbox1, False, False, 0)
@ -383,18 +449,23 @@ class Filters(threading.Thread):
hbox.pack_start(vbox2, False, False, 0)
vbox3 = gtk.VBox(False, 0)
hbox.pack_start(vbox3, False, False, 0)
found = {'nl':False, 'fl':False, 'ring':False, 'tour':False}
for i, line in enumerate(result):
hbox = gtk.HBox(False, 0)
if i <= len(result)/2:
vbox2.pack_start(hbox, False, False, 0)
else:
vbox3.pack_start(hbox, False, False, 0)
if line[0] == 'fl':
self.cbLimits[line[1]] = self.createLimitLine(hbox, str(line[1]), str(line[1]))
fl = True
if line[1] == 'fl':
name = str(line[2])
found['fl'] = True
else:
self.cbLimits[str(line[1])+line[0]] = self.createLimitLine(hbox, str(line[1])+line[0], str(line[1])+line[0])
nl = True
name = str(line[2])+line[1]
found['nl'] = True
self.cbLimits[name] = self.createLimitLine(hbox, name, name)
self.types[name] = line[0]
found[line[0]] = True # type is ring/tour
self.type = line[0] # if only one type, set it now
if "LimitSep" in display and display["LimitSep"] == True and len(result) >= 2:
hbox = gtk.HBox(True, 0)
vbox1.pack_start(hbox, False, False, 0)
@ -410,19 +481,37 @@ class Filters(threading.Thread):
vbox2.pack_start(hbox, False, False, 0)
self.cbNoLimits = self.createLimitLine(hbox, 'none', self.filterText['limitsnone'])
if "LimitType" in display and display["LimitType"] == True and len(result) >= 2:
if fl:
hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0)
self.cbFL = self.createLimitLine(hbox, 'fl', self.filterText['limitsFL'])
if nl:
hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0)
self.cbNL = self.createLimitLine(hbox, 'nl', self.filterText['limitsNL'])
dest = vbox3 # for ring/tour buttons
if "LimitType" in display and display["LimitType"] == True and found['nl'] and found['fl']:
#if found['fl']:
hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0)
self.cbFL = self.createLimitLine(hbox, 'fl', self.filterText['limitsFL'])
#if found['nl']:
hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0)
self.cbNL = self.createLimitLine(hbox, 'nl', self.filterText['limitsNL'])
dest = vbox2 # for ring/tour buttons
else:
print "INFO: No games returned from database"
if "Type" in display and display["Type"] == True and found['ring'] and found['tour']:
rb1 = gtk.RadioButton(None, self.filterText['ring'])
rb1.connect('clicked', self.__set_limit_select, 'ring')
rb2 = gtk.RadioButton(rb1, self.filterText['tour'])
rb2.connect('clicked', self.__set_limit_select, 'tour')
top_hbox.pack_start(rb1, False, False, 0) # (child, expand, fill, padding)
top_hbox.pack_start(rb2, True, True, 0) # child uses expand space if fill is true
self.rb['ring'] = rb1
self.rb['tour'] = rb2
#print "about to set ring to true"
rb1.set_active(True)
# set_active doesn't seem to call this for some reason so call manually:
self.__set_limit_select(rb1, 'ring')
self.type = 'ring'
top_hbox.pack_start(showb, expand=False, padding=1)
def fillSeatsFrame(self, vbox, display):
hbox = gtk.HBox(False, 0)
vbox.pack_start(hbox, False, False, 0)

View File

@ -60,6 +60,7 @@ class GuiPlayerStats (threading.Thread):
"Limits" : True,
"LimitSep" : True,
"LimitType" : True,
"Type" : True,
"Seats" : True,
"SeatSep" : True,
"Dates" : True,
@ -158,6 +159,7 @@ class GuiPlayerStats (threading.Thread):
heroes = self.filters.getHeroes()
siteids = self.filters.getSiteIds()
limits = self.filters.getLimits()
type = self.filters.getType()
seats = self.filters.getSeats()
groups = self.filters.getGroups()
dates = self.filters.getDates()
@ -186,16 +188,16 @@ class GuiPlayerStats (threading.Thread):
print "No limits found"
return
self.createStatsTable(vbox, playerids, sitenos, limits, seats, groups, dates)
self.createStatsTable(vbox, playerids, sitenos, limits, type, seats, groups, dates)
def createStatsTable(self, vbox, playerids, sitenos, limits, seats, groups, dates):
def createStatsTable(self, vbox, playerids, sitenos, limits, type, seats, groups, dates):
starttime = time()
# Display summary table at top of page
# 3rd parameter passes extra flags, currently includes:
# holecards - whether to display card breakdown (True/False)
flags = [False]
self.addTable(vbox, 'playerDetailedStats', flags, playerids, sitenos, limits, seats, groups, dates)
self.addTable(vbox, 'playerDetailedStats', flags, playerids, sitenos, limits, type, seats, groups, dates)
# Separator
sep = gtk.HSeparator()
@ -218,13 +220,13 @@ class GuiPlayerStats (threading.Thread):
# Detailed table
flags = [True]
self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, seats, groups, dates)
self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, type, seats, groups, dates)
self.db.rollback()
print "Stats page displayed in %4.2f seconds" % (time() - starttime)
#end def fillStatsFrame(self, vbox):
def addTable(self, vbox, query, flags, playerids, sitenos, limits, seats, groups, dates):
def addTable(self, vbox, query, flags, playerids, sitenos, limits, type, seats, groups, dates):
row = 0
sqlrow = 0
colalias,colshow,colheading,colxalign,colformat = 0,1,2,3,4
@ -232,7 +234,7 @@ class GuiPlayerStats (threading.Thread):
else: holecards = flags[0]
tmp = self.sql.query[query]
tmp = self.refineQuery(tmp, flags, playerids, sitenos, limits, seats, groups, dates)
tmp = self.refineQuery(tmp, flags, playerids, sitenos, limits, type, seats, groups, dates)
self.cursor.execute(tmp)
result = self.cursor.fetchall()
colnames = [desc[0].lower() for desc in self.cursor.description]
@ -318,9 +320,9 @@ class GuiPlayerStats (threading.Thread):
row += 1
vbox.show_all()
#end def addTable(self, query, vars, playerids, sitenos, limits, seats):
#end def addTable(self, query, vars, playerids, sitenos, limits, type, seats, groups, dates):
def refineQuery(self, query, flags, playerids, sitenos, limits, seats, groups, dates):
def refineQuery(self, query, flags, playerids, sitenos, limits, type, seats, groups, dates):
if not flags: holecards = False
else: holecards = flags[0]
@ -364,6 +366,10 @@ class GuiPlayerStats (threading.Thread):
bbtest = bbtest + blindtest + ' ) )'
else:
bbtest = bbtest + '(-1) ) )'
if type == 'ring':
bbtest = bbtest + " and gt.type = 'ring' "
elif type == 'tour':
bbtest = bbtest + " and gt.type = 'tour' "
query = query.replace("<gtbigBlind_test>", bbtest)
if holecards: # pinch level variables for hole card query

View File

@ -1720,9 +1720,9 @@ class Sql:
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
self.query['getGames'] = """SELECT DISTINCT category from Gametypes"""
self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
self.query['getLimits2'] = """SELECT DISTINCT limitType, bigBlind
self.query['getLimits2'] = """SELECT DISTINCT type, limitType, bigBlind
from Gametypes
ORDER by limitType DESC, bigBlind DESC"""
ORDER by type, limitType DESC, bigBlind DESC"""
if db_server == 'mysql':
self.query['playerDetailedStats'] = """