Fixups to GuiPlayerStats

Now sets up and obeys the radio buttons more correctly.

Also reads the names from the text box, and replaces <player_test> in
the sql query.
This commit is contained in:
Worros 2008-12-07 17:06:01 +09:00
parent 425997d66a
commit 977e954574
2 changed files with 32 additions and 15 deletions

View File

@ -576,7 +576,6 @@ class FpdbSQLQueries:
if(self.dbname == 'MySQL InnoDB'): if(self.dbname == 'MySQL InnoDB'):
self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)""" self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)"""
elif(self.dbname == 'PostgreSQL'): elif(self.dbname == 'PostgreSQL'):
# FIXME: This query has a different syntax
self.query['addTourneyIndex'] = """CREATE INDEX siteTourneyNo ON Tourneys (siteTourneyNo)""" self.query['addTourneyIndex'] = """CREATE INDEX siteTourneyNo ON Tourneys (siteTourneyNo)"""
elif(self.dbname == 'SQLite'): elif(self.dbname == 'SQLite'):
self.query['addHandsIndex'] = """ """ self.query['addHandsIndex'] = """ """
@ -584,7 +583,6 @@ class FpdbSQLQueries:
if(self.dbname == 'MySQL InnoDB'): if(self.dbname == 'MySQL InnoDB'):
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)""" self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
elif(self.dbname == 'PostgreSQL'): elif(self.dbname == 'PostgreSQL'):
# FIXME: This query has a different syntax
self.query['addHandsIndex'] = """CREATE INDEX siteHandNo ON Hands (siteHandNo)""" self.query['addHandsIndex'] = """CREATE INDEX siteHandNo ON Hands (siteHandNo)"""
elif(self.dbname == 'SQLite'): elif(self.dbname == 'SQLite'):
self.query['addHandsIndex'] = """ """ self.query['addHandsIndex'] = """ """
@ -592,7 +590,6 @@ class FpdbSQLQueries:
if(self.dbname == 'MySQL InnoDB'): if(self.dbname == 'MySQL InnoDB'):
self.query['addPlayersIndex'] = """ALTER TABLE Players ADD INDEX name(name)""" self.query['addPlayersIndex'] = """ALTER TABLE Players ADD INDEX name(name)"""
elif(self.dbname == 'PostgreSQL'): elif(self.dbname == 'PostgreSQL'):
# FIXME: This query has a different syntax
self.query['addPlayersIndex'] = """CREATE INDEX name ON Players (name)""" self.query['addPlayersIndex'] = """CREATE INDEX name ON Players (name)"""
elif(self.dbname == 'SQLite'): elif(self.dbname == 'SQLite'):
self.query['addPlayersIndex'] = """ """ self.query['addPlayersIndex'] = """ """
@ -633,6 +630,11 @@ class FpdbSQLQueries:
WHERE Players.name = %s AND HandsPlayers.handId = %s WHERE Players.name = %s AND HandsPlayers.handId = %s
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)""" AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getPlayerId'] = """SELECT id from Players where name = %s"""
elif(self.dbname == 'SQLite'):
self.query['getPlayerId'] = """SELECT id from Players where name = %s"""
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'): if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getRingProfitAllHandsPlayerIdSite'] = """ self.query['getRingProfitAllHandsPlayerIdSite'] = """
SELECT hp.handId, hp.winnings, SUM(ha.amount), hp.winnings - SUM(ha.amount) SELECT hp.handId, hp.winnings, SUM(ha.amount), hp.winnings - SUM(ha.amount)
@ -702,8 +704,7 @@ class FpdbSQLQueries:
from Gametypes gt from Gametypes gt
inner join Sites s on s.Id = gt.siteId inner join Sites s on s.Id = gt.siteId
inner join HudCache hc on hc.gameTypeId = gt.Id inner join HudCache hc on hc.gameTypeId = gt.Id
where gt.limittype = 'nl' where hc.playerId in <player_test>
and hc.playerId in (3) # use <player_test> here?
# use <gametype_test> here ? # use <gametype_test> here ?
group by hc.gametypeId group by hc.gametypeId
) stats ) stats
@ -716,7 +717,7 @@ class FpdbSQLQueries:
from HandsPlayers hp from HandsPlayers hp
inner join Hands h ON h.id = hp.handId inner join Hands h ON h.id = hp.handId
inner join HandsActions ha ON ha.handPlayerId = hp.id inner join HandsActions ha ON ha.handPlayerId = hp.id
where hp.playerId in (3) # use <player_test> here? where hp.playerId in <player_test>
# use <gametype_test> here ? # use <gametype_test> here ?
and hp.tourneysPlayersId IS NULL and hp.tourneysPlayersId IS NULL
group by hp.handId, h.gameTypeId, hp.position, hp.winnings group by hp.handId, h.gameTypeId, hp.position, hp.winnings

View File

@ -31,7 +31,9 @@ class GuiPlayerStats (threading.Thread):
return self.main_hbox return self.main_hbox
def toggleCallback(self, widget, data=None): def toggleCallback(self, widget, data=None):
print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()]) # print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
self.activesite = data
print "DEBUG: activesite set to %s" %(self.activesite)
def refreshStats(self, widget, data): def refreshStats(self, widget, data):
try: self.stats_table.destroy() try: self.stats_table.destroy()
@ -39,7 +41,14 @@ class GuiPlayerStats (threading.Thread):
self.fillStatsFrame(self.stats_frame) self.fillStatsFrame(self.stats_frame)
def fillStatsFrame(self, vbox): def fillStatsFrame(self, vbox):
self.cursor.execute(self.sql.query['playerStats']) # Get currently active site and grab playerid
tmp = self.sql.query['playerStats']
result = self.cursor.execute(self.sql.query['getPlayerId'], self.heroes[self.activesite])
result = self.db.cursor.fetchall()
pid = result[0][0]
tmp = tmp.replace("<player_test>", "(" + str(pid) + ")")
self.cursor.execute(tmp)
result = self.db.cursor.fetchall() result = self.db.cursor.fetchall()
cols = 18 cols = 18
rows = len(result)+1 # +1 for title row rows = len(result)+1 # +1 for title row
@ -61,7 +70,6 @@ class GuiPlayerStats (threading.Thread):
for row in range(rows-1): for row in range(rows-1):
for col in range(cols): for col in range(cols):
print "result[%s][%s]: %s" %(row-1, col, result[row-1][col])
if(row%2 == 0): if(row%2 == 0):
bgcolor = "white" bgcolor = "white"
else: else:
@ -92,10 +100,15 @@ class GuiPlayerStats (threading.Thread):
hbox.show() hbox.show()
def createPlayerLine(self, hbox, site, player): def createPlayerLine(self, hbox, site, player):
if(self.buttongroup == None):
button = gtk.RadioButton(None, site + " id:") button = gtk.RadioButton(None, site + " id:")
button.set_active(True)
self.buttongroup = button
self.activesite = site
else:
button = gtk.RadioButton(self.buttongroup, site + " id:")
hbox.pack_start(button, True, True, 0) hbox.pack_start(button, True, True, 0)
button.connect("toggled", self.toggleCallback, site) button.connect("toggled", self.toggleCallback, site)
# button.set_active(True)
button.show() button.show()
pname = gtk.Entry() pname = gtk.Entry()
@ -119,6 +132,9 @@ class GuiPlayerStats (threading.Thread):
self.sql = querylist self.sql = querylist
self.activesite = None
self.buttongroup = None
self.heroes = {} self.heroes = {}
self.stat_table = None self.stat_table = None
self.stats_frame = None self.stats_frame = None
@ -138,11 +154,11 @@ class GuiPlayerStats (threading.Thread):
statsFrame = gtk.Frame("Stats:") statsFrame = gtk.Frame("Stats:")
statsFrame.set_label_align(0.0, 0.0) statsFrame.set_label_align(0.0, 0.0)
statsFrame.show() statsFrame.show()
vbox = gtk.VBox(False, 0) self.stats_frame = gtk.VBox(False, 0)
vbox.show() self.stats_frame.show()
self.fillStatsFrame(vbox) self.fillStatsFrame(self.stats_frame)
statsFrame.add(vbox) statsFrame.add(self.stats_frame)
self.main_hbox.pack_start(playerFrame) self.main_hbox.pack_start(playerFrame)
self.main_hbox.pack_start(statsFrame) self.main_hbox.pack_start(statsFrame)