2008-09-20 06:56:16 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
#Copyright 2008 Steffen Jobbagy-Felso
|
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
#GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
#You should have received a copy of the GNU Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#In the "official" distribution you can find the license in
|
|
|
|
#agpl-3.0.txt in the docs folder of the package.
|
|
|
|
|
|
|
|
import threading
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import os
|
2008-09-26 03:54:08 +02:00
|
|
|
#import pokereval
|
2008-09-20 06:56:16 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
from matplotlib.figure import Figure
|
|
|
|
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
|
|
|
|
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar
|
2008-09-26 02:05:00 +02:00
|
|
|
from numpy import arange, cumsum
|
|
|
|
from pylab import *
|
2008-09-20 06:56:16 +02:00
|
|
|
except:
|
2008-10-06 05:26:59 +02:00
|
|
|
print "Failed to load libs for graphing, graphing will not function. Please install numpy and matplotlib if you want to use graphs."
|
|
|
|
print "This is of no consequence for other parts of the program, e.g. import and HUD are NOT affected by this problem."
|
2008-09-20 06:56:16 +02:00
|
|
|
|
|
|
|
import fpdb_import
|
|
|
|
import fpdb_db
|
|
|
|
|
|
|
|
class GuiGraphViewer (threading.Thread):
|
|
|
|
def get_vbox(self):
|
|
|
|
"""returns the vbox of this thread"""
|
2008-09-21 15:24:43 +02:00
|
|
|
return self.mainVBox
|
2008-09-20 06:56:16 +02:00
|
|
|
#end def get_vbox
|
|
|
|
|
2008-09-21 15:24:43 +02:00
|
|
|
def showClicked(self, widget, data):
|
2008-09-24 05:01:38 +02:00
|
|
|
try: self.canvas.destroy()
|
|
|
|
except AttributeError: pass
|
|
|
|
|
2008-10-17 18:35:59 +02:00
|
|
|
name=self.nameEntry.get_text()
|
2008-09-20 06:56:16 +02:00
|
|
|
|
2008-10-17 18:35:59 +02:00
|
|
|
site=self.siteEntry.get_text()
|
2008-09-22 00:38:22 +02:00
|
|
|
|
|
|
|
if site=="PS":
|
|
|
|
site=2
|
2008-10-14 16:35:05 +02:00
|
|
|
sitename="PokerStars: "
|
2008-09-26 03:54:08 +02:00
|
|
|
elif site=="FTP":
|
|
|
|
site=1
|
2008-10-14 16:35:05 +02:00
|
|
|
sitename="Full Tilt: "
|
2008-09-22 00:38:22 +02:00
|
|
|
else:
|
|
|
|
print "invalid text in site selection in graph, defaulting to PS"
|
2008-09-26 03:54:08 +02:00
|
|
|
site=2
|
2008-09-22 00:38:22 +02:00
|
|
|
|
2008-09-20 06:56:16 +02:00
|
|
|
self.fig = Figure(figsize=(5,4), dpi=100)
|
2008-09-26 02:05:00 +02:00
|
|
|
|
|
|
|
#Set graph properties
|
2008-09-20 06:56:16 +02:00
|
|
|
self.ax = self.fig.add_subplot(111)
|
|
|
|
|
2008-09-26 02:05:00 +02:00
|
|
|
#
|
|
|
|
self.ax.set_title("Profit graph for ring games")
|
|
|
|
|
|
|
|
#Set axis labels and grid overlay properites
|
|
|
|
self.ax.set_xlabel("Hands", fontsize = 12)
|
|
|
|
self.ax.set_ylabel("$", fontsize = 12)
|
|
|
|
self.ax.grid(color='g', linestyle=':', linewidth=0.2)
|
2008-10-14 16:35:05 +02:00
|
|
|
text = "All Hands, " + sitename + str(name)
|
|
|
|
|
|
|
|
self.ax.annotate (text, (61,25), xytext =(0.1, 0.9) , textcoords ="axes fraction" ,)
|
2008-09-20 06:56:16 +02:00
|
|
|
|
2008-10-08 13:53:25 +02:00
|
|
|
#Get graph data from DB
|
|
|
|
line = self.getRingProfitGraph(name, site)
|
|
|
|
|
|
|
|
#Draw plot
|
2008-09-20 06:56:16 +02:00
|
|
|
self.ax.plot(line,)
|
|
|
|
|
|
|
|
self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
|
2008-09-21 15:24:43 +02:00
|
|
|
self.mainVBox.pack_start(self.canvas)
|
2008-09-20 06:56:16 +02:00
|
|
|
self.canvas.show()
|
2008-09-22 04:31:33 +02:00
|
|
|
#end of def showClicked
|
2008-09-20 06:56:16 +02:00
|
|
|
|
2008-10-08 13:53:25 +02:00
|
|
|
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
|
|
|
|
|
2008-10-25 08:57:29 +02:00
|
|
|
def __init__(self, db, settings, querylist, config, debug=True):
|
2008-09-22 04:31:33 +02:00
|
|
|
"""Constructor for GraphViewer"""
|
2008-09-21 15:24:43 +02:00
|
|
|
self.debug=debug
|
2008-09-22 04:31:33 +02:00
|
|
|
#print "start of GraphViewer constructor"
|
2008-09-21 15:24:43 +02:00
|
|
|
self.db=db
|
|
|
|
self.cursor=db.cursor
|
|
|
|
self.settings=settings
|
2008-10-08 13:53:25 +02:00
|
|
|
self.sql=querylist
|
2008-09-21 15:24:43 +02:00
|
|
|
|
|
|
|
self.mainVBox = gtk.VBox(False, 0)
|
|
|
|
self.mainVBox.show()
|
|
|
|
|
|
|
|
self.settingsHBox = gtk.HBox(False, 0)
|
|
|
|
self.mainVBox.pack_start(self.settingsHBox, False, True, 0)
|
|
|
|
self.settingsHBox.show()
|
|
|
|
|
|
|
|
self.nameLabel = gtk.Label("Name of the player to be graphed:")
|
|
|
|
self.settingsHBox.pack_start(self.nameLabel)
|
|
|
|
self.nameLabel.show()
|
|
|
|
|
2008-10-17 18:35:59 +02:00
|
|
|
self.nameEntry=gtk.Entry()
|
|
|
|
self.nameEntry.set_text("name")
|
|
|
|
self.settingsHBox.pack_start(self.nameEntry)
|
|
|
|
self.nameEntry.show()
|
2008-09-21 15:24:43 +02:00
|
|
|
|
2008-09-22 00:38:22 +02:00
|
|
|
self.siteLabel = gtk.Label("Site (PS or FTP):")
|
|
|
|
self.settingsHBox.pack_start(self.siteLabel)
|
|
|
|
self.siteLabel.show()
|
|
|
|
|
2008-10-17 18:35:59 +02:00
|
|
|
self.siteEntry=gtk.Entry()
|
|
|
|
self.siteEntry.set_text("PS")
|
|
|
|
self.settingsHBox.pack_start(self.siteEntry)
|
|
|
|
self.siteEntry.show()
|
2008-10-25 08:57:29 +02:00
|
|
|
|
|
|
|
#Note: Assumes PokerStars is in the config
|
|
|
|
self.nameEntry.set_text(config.supported_sites["PokerStars"].screen_name)
|
2008-09-22 00:38:22 +02:00
|
|
|
|
2008-09-21 15:24:43 +02:00
|
|
|
self.showButton=gtk.Button("Show/Refresh")
|
|
|
|
self.showButton.connect("clicked", self.showClicked, "show clicked")
|
2008-09-22 00:38:22 +02:00
|
|
|
self.settingsHBox.pack_start(self.showButton)
|
2008-09-21 15:24:43 +02:00
|
|
|
self.showButton.show()
|
|
|
|
#end of GuiGraphViewer.__init__
|