Make GuiGraphViewer use the query file.
Make minor adjustment to Graph
This commit is contained in:
parent
1e7b584dba
commit
79651706f6
|
@ -580,6 +580,42 @@ class FpdbSQLQueries:
|
|||
elif(self.dbname == 'SQLite'):
|
||||
self.query['createHudCacheTable'] = """ """
|
||||
|
||||
################################
|
||||
# Queries used in GuiGraphViewer
|
||||
################################
|
||||
|
||||
|
||||
# Returns all cash game handIds and the money won(winnings is the final pot)
|
||||
# by the playerId for a single site.
|
||||
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
|
||||
self.query['getRingWinningsAllGamesPlayerIdSite'] = """SELECT handId, winnings FROM HandsPlayers
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
INNER JOIN Hands ON Hands.id = HandsPlayers.handId
|
||||
WHERE Players.name = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)
|
||||
ORDER BY handStart"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
#Probably doesn't work.
|
||||
self.query['getRingWinningsAllGamesPlayerIdSite'] = """SELECT handId, winnings FROM HandsPlayers
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
INNER JOIN Hands ON Hands.id = HandsPlayers.handId
|
||||
WHERE Players.name = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)
|
||||
ORDER BY handStart"""
|
||||
|
||||
# Returns the profit for a given ring game handId, Total pot - money invested by playerId
|
||||
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
|
||||
self.query['getRingProfitFromHandId'] = """SELECT SUM(amount) FROM HandsActions
|
||||
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
WHERE Players.name = %s AND HandsPlayers.handId = %s
|
||||
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
#Probably doesn't work.
|
||||
self.query['getRingProfitFromHandId'] = """SELECT SUM(amount) FROM HandsActions
|
||||
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
WHERE Players.name = %s AND HandsPlayers.handId = %s
|
||||
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
|
||||
|
||||
|
||||
if __name__== "__main__":
|
||||
from optparse import OptionParser
|
||||
|
|
|
@ -69,30 +69,12 @@ class GuiGraphViewer (threading.Thread):
|
|||
self.ax.set_xlabel("Hands", fontsize = 12)
|
||||
self.ax.set_ylabel("$", fontsize = 12)
|
||||
self.ax.grid(color='g', linestyle=':', linewidth=0.2)
|
||||
|
||||
self.cursor.execute("""SELECT handId, winnings FROM HandsPlayers
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
INNER JOIN Hands ON Hands.id = HandsPlayers.handId
|
||||
WHERE Players.name = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)
|
||||
ORDER BY siteHandNo""", (name, site))
|
||||
winnings = self.db.cursor.fetchall()
|
||||
|
||||
profit=range(len(winnings))
|
||||
for i in profit:
|
||||
self.cursor.execute("""SELECT SUM(amount) FROM HandsActions
|
||||
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
WHERE Players.name = %s AND HandsPlayers.handId = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)""", (name, winnings[i][0], site))
|
||||
spent = self.db.cursor.fetchone()
|
||||
profit[i]=(i, winnings[i][1]-spent[0])
|
||||
|
||||
y=map(lambda x:float(x[1]), profit)
|
||||
line = cumsum(y)
|
||||
line = line/100
|
||||
|
||||
self.ax.annotate ("All Hands, Site %s", (61,25), xytext =(0.1, 0.9) , textcoords ="axes fraction" ,)
|
||||
|
||||
#Now draw plot
|
||||
#Get graph data from DB
|
||||
line = self.getRingProfitGraph(name, site)
|
||||
|
||||
#Draw plot
|
||||
self.ax.plot(line,)
|
||||
|
||||
self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
|
||||
|
@ -100,13 +82,29 @@ class GuiGraphViewer (threading.Thread):
|
|||
self.canvas.show()
|
||||
#end of def showClicked
|
||||
|
||||
def __init__(self, db, settings, debug=True):
|
||||
def getRingProfitGraph(self, name, site):
|
||||
self.cursor.execute(self.sql.query['getRingWinningsAllGamesPlayerIdSite'], (name, site))
|
||||
winnings = self.db.cursor.fetchall()
|
||||
|
||||
profit=range(len(winnings))
|
||||
for i in profit:
|
||||
self.cursor.execute(self.sql.query['getRingProfitFromHandId'], (name, winnings[i][0], site))
|
||||
spent = self.db.cursor.fetchone()
|
||||
profit[i]=(i, winnings[i][1]-spent[0])
|
||||
|
||||
y=map(lambda x:float(x[1]), profit)
|
||||
line = cumsum(y)
|
||||
return line/100
|
||||
#end of def getRingProfitGraph
|
||||
|
||||
def __init__(self, db, settings, querylist, debug=True):
|
||||
"""Constructor for GraphViewer"""
|
||||
self.debug=debug
|
||||
#print "start of GraphViewer constructor"
|
||||
self.db=db
|
||||
self.cursor=db.cursor
|
||||
self.settings=settings
|
||||
self.sql=querylist
|
||||
|
||||
self.mainVBox = gtk.VBox(False, 0)
|
||||
self.mainVBox.show()
|
||||
|
|
|
@ -344,6 +344,9 @@ class fpdb:
|
|||
|
||||
response = diaDbVersionWarning.run()
|
||||
diaDbVersionWarning.destroy()
|
||||
|
||||
# Database connected to successfully, load queries to pass on to other classes
|
||||
self.querydict = FpdbSQLQueries.FpdbSQLQueries(self.db.get_backend_name())
|
||||
#end def load_profile
|
||||
|
||||
def not_implemented(self):
|
||||
|
@ -407,7 +410,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
|||
def tabGraphViewer(self, widget, data):
|
||||
"""opens a graph viewer tab"""
|
||||
#print "start of tabGraphViewer"
|
||||
new_gv_thread=GuiGraphViewer.GuiGraphViewer(self.db, self.settings)
|
||||
new_gv_thread=GuiGraphViewer.GuiGraphViewer(self.db, self.settings,self.querydict)
|
||||
self.threads.append(new_gv_thread)
|
||||
gv_tab=new_gv_thread.get_vbox()
|
||||
self.add_and_display_tab(gv_tab, "Graphs")
|
||||
|
|
Loading…
Reference in New Issue
Block a user