Add showdown/non-showdown winnings to Grapher

This commit is contained in:
Worros 2009-12-02 14:02:06 +08:00
parent fc20330f2b
commit 395f19b5fb
2 changed files with 17 additions and 8 deletions

View File

@ -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):

View File

@ -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)