From 395f19b5fb681b5f24dc7930fa929cc9b42de4be Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 2 Dec 2009 14:02:06 +0800 Subject: [PATCH] Add showdown/non-showdown winnings to Grapher --- pyfpdb/GuiGraphViewer.py | 23 ++++++++++++++++------- pyfpdb/SQL.py | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index b81f2d5e..816c25fc 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -31,6 +31,7 @@ try: from matplotlib.figure import Figure from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar + from matplotlib.font_manager import FontProperties from numpy import arange, cumsum from pylab import * except ImportError, inst: @@ -170,7 +171,7 @@ class GuiGraphViewer (threading.Thread): #Get graph data from DB starttime = time() - line = self.getRingProfitGraph(playerids, sitenos, limits) + (green, blue, red) = self.getRingProfitGraph(playerids, sitenos, limits) print "Graph generated in: %s" %(time() - starttime) self.ax.set_title("Profit graph for ring games") @@ -179,13 +180,13 @@ 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) - if line == None or line == []: + if green == None or green == []: #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, " + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line)) + text = "All Hands, " + "\nProfit: $" + str(green[-1]) + "\nTotal Hands: " + str(len(green)) self.ax.annotate(text, xy=(10, -10), @@ -194,7 +195,11 @@ class GuiGraphViewer (threading.Thread): fontsize=10) #Draw plot - self.ax.plot(line,) + self.ax.plot(green, color='green', label='Hands: %d\nProfit: $%.2f' %(len(green), green[-1])) + self.ax.plot(blue, color='blue', label='Showdown: $%.2f' %(blue[-1])) + self.ax.plot(red, color='red', label='Non-showdown: $%.2f' %(red[-1])) + self.ax.legend(loc='best', fancybox=True, shadow=True, prop=FontProperties(size='smaller')) + self.graphBox.add(self.canvas) self.canvas.show() @@ -270,9 +275,13 @@ class GuiGraphViewer (threading.Thread): if winnings == (): return None - y = map(lambda x:float(x[1]), winnings) - line = cumsum(y) - return line/100 + green = map(lambda x:float(x[1]), winnings) + blue = map(lambda x: float(x[1]) if x[2] == True else 0.0, winnings) + red = map(lambda x: float(x[1]) if x[2] == False else 0.0, winnings) + greenline = cumsum(green) + blueline = cumsum(blue) + redline = cumsum(red) + return (greenline/100, blueline/100, redline/100) #end of def getRingProfitGraph def exportGraph (self, widget, data): diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index e38bc122..85b5fd80 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -2561,7 +2561,7 @@ class Sql: # self.query['playerStatsByPosition'] = """ """ self.query['getRingProfitAllHandsPlayerIdSite'] = """ - SELECT hp.handId, hp.totalProfit + SELECT hp.handId, hp.totalProfit, hp.sawShowdown FROM HandsPlayers hp INNER JOIN Players pl ON (pl.id = hp.playerId) INNER JOIN Hands h ON (h.id = hp.handId)