Grapher: Update to support mutiple sites and players

Makes sites actually selectable via checkboxes.

Removed the sitename from the graph string for the moment - How that
string is generated needs a major overhaul
This commit is contained in:
Worros 2008-12-19 16:52:32 +09:00
parent 7803f52307
commit 49aa8921e3
4 changed files with 63 additions and 26 deletions

View File

@ -635,6 +635,11 @@ class FpdbSQLQueries:
elif(self.dbname == 'SQLite'):
self.query['getPlayerId'] = """SELECT id from Players where name = %s"""
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
elif(self.dbname == 'SQLite'):
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
self.query['getRingProfitAllHandsPlayerIdSite'] = """
SELECT hp.handId, hp.winnings, coalesce(hp.ante,0) + SUM(ha.amount)
@ -643,8 +648,8 @@ class FpdbSQLQueries:
INNER JOIN Players pl ON hp.playerId = pl.id
INNER JOIN Hands h ON h.id = hp.handId
INNER JOIN HandsActions ha ON ha.handPlayerId = hp.id
WHERE pl.name = %s
AND pl.siteId = %s
where pl.id in <player_test>
AND pl.siteId in <site_test>
AND hp.tourneysPlayersId IS NULL
GROUP BY hp.handId, hp.winnings, h.handStart, hp.ante
ORDER BY h.handStart"""

View File

@ -50,22 +50,27 @@ class GuiGraphViewer (threading.Thread):
try: self.canvas.destroy()
except AttributeError: pass
# Whaich sites are selected?
# TODO:
# What hero names for the selected site?
# TODO:
sitenos = []
playerids = []
name = self.heroes[self.sites]
# Which sites are selected?
for site in self.sites:
if self.sites[site] == True:
sitenos.append(self.siteid[site])
self.cursor.execute(self.sql.query['getPlayerId'], (self.heroes[site],))
result = self.db.cursor.fetchall()
if len(result) == 1:
playerids.append(result[0][0])
if self.sites == "PokerStars":
site=2
sitename="PokerStars: "
elif self.sites=="Full Tilt":
site=1
sitename="Full Tilt: "
else:
print "invalid text in site selection in graph, defaulting to PS"
site=2
if sitenos == []:
#Should probably pop up here.
print "No sites selected - defaulting to PokerStars"
sitenos = [2]
if playerids == []:
print "No player ids found"
return
self.fig = Figure(figsize=(5,4), dpi=100)
@ -74,7 +79,7 @@ class GuiGraphViewer (threading.Thread):
#Get graph data from DB
starttime = time()
line = self.getRingProfitGraph(name, site)
line = self.getRingProfitGraph(playerids, sitenos)
print "Graph generated in: %s" %(time() - starttime)
self.ax.set_title("Profit graph for ring games")
@ -87,7 +92,8 @@ class GuiGraphViewer (threading.Thread):
#TODO: Do something useful like alert user
print "No hands returned by graph query"
else:
text = "All Hands, " + sitename + str(name) + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line))
# text = "All Hands, " + sitename + str(name) + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line))
text = "All Hands, " + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line))
self.ax.annotate(text,
xy=(10, -10),
@ -103,8 +109,26 @@ class GuiGraphViewer (threading.Thread):
self.canvas.show()
#end of def showClicked
def getRingProfitGraph(self, name, site):
self.cursor.execute(self.sql.query['getRingProfitAllHandsPlayerIdSite'], (name, site))
def getRingProfitGraph(self, names, sites):
tmp = self.sql.query['getRingProfitAllHandsPlayerIdSite']
# print "DEBUG: getRingProfitGraph"
#Buggered if I can find a way to do this 'nicely' take a list of intergers and longs
# and turn it into a tuple readale by sql.
# [5L] into (5) not (5,) and [5L, 2829L] into (5, 2829)
nametest = str(tuple(names))
sitetest = str(tuple(sites))
nametest = nametest.replace("L", "")
nametest = nametest.replace(",)",")")
sitetest = sitetest.replace(",)",")")
#Must be a nicer way to deal with tuples of size 1 ie. (2,) - which makes sql barf
tmp = tmp.replace("<player_test>", nametest)
tmp = tmp.replace("<site_test>", sitetest)
# print "DEBUG: sql query:"
# print tmp
self.cursor.execute(tmp)
#returns (HandId,Winnings,Costs,Profit)
winnings = self.db.cursor.fetchall()
@ -125,7 +149,6 @@ class GuiGraphViewer (threading.Thread):
pname.set_text(player)
pname.set_width_chars(20)
hbox.pack_start(pname, False, True, 0)
#TODO: Need to connect a callback here
pname.connect("changed", self.__set_hero_name, site)
#TODO: Look at GtkCompletion - to fill out usernames
pname.show()
@ -134,7 +157,7 @@ class GuiGraphViewer (threading.Thread):
def __set_hero_name(self, w, site):
self.heroes[site] = w.get_text()
print "DEBUG: settings heroes[%s]: %s"%(site, self.heroes[site])
# print "DEBUG: settings heroes[%s]: %s"%(site, self.heroes[site])
def createSiteLine(self, hbox, site):
cb = gtk.CheckButton(site)
@ -144,8 +167,9 @@ class GuiGraphViewer (threading.Thread):
def __set_site_select(self, w, site):
# This doesn't behave as intended - self.site only allows 1 site for the moment.
self.sites = site
print "self.sites set to %s" %(self.sites)
print w.get_active()
self.sites[site] = w.get_active()
print "self.sites[%s] set to %s" %(site, self.sites[site])
def fillPlayerFrame(self, vbox):
for site in self.conf.supported_sites.keys():
@ -162,6 +186,13 @@ class GuiGraphViewer (threading.Thread):
vbox.pack_start(hbox, False, True, 0)
hbox.show()
self.createSiteLine(hbox, site)
#Get db site id for filtering later
self.cursor.execute(self.sql.query['getSiteId'], (site))
result = self.db.cursor.fetchall()
if len(result) == 1:
self.siteid[site] = result[0][0]
else:
print "Either 0 or more than one site matched - EEK"
def fillDateFrame(self, vbox):
# Hat tip to Mika Bostrom - calendar code comes from PokerStats
@ -261,7 +292,8 @@ class GuiGraphViewer (threading.Thread):
self.sql=querylist
self.conf = config
self.sites = "PokerStars"
self.sites = {}
self.siteid = {}
self.heroes = {}
# For use in date ranges.

View File

@ -49,7 +49,7 @@
<location seat="2" x="10" y="288"> </location>
</layout>
</site>
<site enabled="True" site_name="Full Tilt" table_finder="FullTiltPoker.exe" screen_name="ENTER HERO NAME" site_path="~/.wine/drive_c/Program Files/Full Tilt Poker/" HH_path="~/.wine/drive_c/Program Files/Full Tilt Poker/HandHistory/abc/" decoder="fulltilt_decode_table" converter="passthrough" supported_games="holdem,razz,omahahi,omahahilo,studhi,studhilo">
<site enabled="True" site_name="Full Tilt Poker" table_finder="FullTiltPoker.exe" screen_name="ENTER HERO NAME" site_path="~/.wine/drive_c/Program Files/Full Tilt Poker/" HH_path="~/.wine/drive_c/Program Files/Full Tilt Poker/HandHistory/abc/" decoder="fulltilt_decode_table" converter="passthrough" supported_games="holdem,razz,omahahi,omahahilo,studhi,studhilo">
<layout fav_seat="0" height="547" max="8" width="794">
<location seat="1" x="640" y="64"> </location>
<location seat="2" x="650" y="230"> </location>

Binary file not shown.