2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/python
|
2010-07-04 03:05:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-09-20 06:56:16 +02:00
|
|
|
|
2010-07-04 03:05:16 +02:00
|
|
|
#Copyright 2008-2010 Steffen Schaumburg
|
2008-09-20 06:56:16 +02:00
|
|
|
#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/>.
|
2010-07-04 03:05:16 +02:00
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
2008-09-20 06:56:16 +02:00
|
|
|
|
2010-09-23 07:11:06 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2008-09-20 06:56:16 +02:00
|
|
|
import threading
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import os
|
2009-10-25 12:22:49 +01:00
|
|
|
import sys
|
2009-08-08 07:56:53 +02:00
|
|
|
import traceback
|
2009-01-21 17:40:05 +01:00
|
|
|
from time import *
|
2010-06-28 00:21:40 +02:00
|
|
|
from datetime import datetime
|
2008-09-26 03:54:08 +02:00
|
|
|
#import pokereval
|
2008-09-20 06:56:16 +02:00
|
|
|
|
|
|
|
import fpdb_import
|
2009-07-19 22:19:58 +02:00
|
|
|
import Database
|
2010-07-17 03:39:31 +02:00
|
|
|
import Filters
|
2010-01-23 08:30:48 +01:00
|
|
|
import Charset
|
2008-09-20 06:56:16 +02:00
|
|
|
|
2010-08-28 22:49:59 +02:00
|
|
|
try:
|
2010-10-04 21:39:34 +02:00
|
|
|
calluse = not 'matplotlib' in sys.modules
|
2010-08-28 22:49:59 +02:00
|
|
|
import matplotlib
|
2010-10-04 21:39:34 +02:00
|
|
|
if calluse:
|
|
|
|
matplotlib.use('GTKCairo')
|
2010-08-28 22:49:59 +02:00
|
|
|
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:
|
|
|
|
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.""")
|
|
|
|
print "ImportError: %s" % inst.args
|
|
|
|
|
2008-09-20 06:56:16 +02:00
|
|
|
class GuiGraphViewer (threading.Thread):
|
2009-04-11 13:14:32 +02:00
|
|
|
|
2010-06-28 00:21:40 +02:00
|
|
|
def __init__(self, querylist, config, parent, debug=True):
|
2009-04-11 13:14:32 +02:00
|
|
|
"""Constructor for GraphViewer"""
|
2009-06-23 00:30:54 +02:00
|
|
|
self.sql = querylist
|
2009-04-11 13:14:32 +02:00
|
|
|
self.conf = config
|
2009-07-19 22:19:58 +02:00
|
|
|
self.debug = debug
|
2010-06-28 00:21:40 +02:00
|
|
|
self.parent = parent
|
2009-07-19 22:19:58 +02:00
|
|
|
#print "start of GraphViewer constructor"
|
|
|
|
self.db = Database.Database(self.conf, sql=self.sql)
|
|
|
|
|
2009-04-11 13:14:32 +02:00
|
|
|
|
2009-10-14 00:06:09 +02:00
|
|
|
filters_display = { "Heroes" : True,
|
|
|
|
"Sites" : True,
|
|
|
|
"Games" : True,
|
|
|
|
"Limits" : True,
|
|
|
|
"LimitSep" : True,
|
|
|
|
"LimitType" : True,
|
|
|
|
"Type" : False,
|
|
|
|
"UseType" : 'ring',
|
|
|
|
"Seats" : False,
|
|
|
|
"SeatSep" : False,
|
|
|
|
"Dates" : True,
|
2010-10-04 05:56:52 +02:00
|
|
|
"GraphOps" : True,
|
2009-10-14 00:06:09 +02:00
|
|
|
"Groups" : False,
|
2011-02-23 06:07:49 +01:00
|
|
|
"Button1" : True,
|
2009-10-14 00:06:09 +02:00
|
|
|
"Button2" : True
|
2009-04-17 06:44:43 +02:00
|
|
|
}
|
|
|
|
|
2010-07-17 03:39:31 +02:00
|
|
|
self.filters = Filters.Filters(self.db, self.conf, self.sql, display = filters_display)
|
2011-02-23 06:07:49 +01:00
|
|
|
self.filters.registerButton1Name(_("Refresh _Graph"))
|
2009-04-17 06:44:43 +02:00
|
|
|
self.filters.registerButton1Callback(self.generateGraph)
|
2011-02-23 06:07:49 +01:00
|
|
|
self.filters.registerButton2Name(_("_Export to File"))
|
2009-04-17 06:44:43 +02:00
|
|
|
self.filters.registerButton2Callback(self.exportGraph)
|
2009-04-11 13:14:32 +02:00
|
|
|
|
|
|
|
self.mainHBox = gtk.HBox(False, 0)
|
|
|
|
self.mainHBox.show()
|
|
|
|
|
|
|
|
self.leftPanelBox = self.filters.get_vbox()
|
|
|
|
|
|
|
|
self.hpane = gtk.HPaned()
|
|
|
|
self.hpane.pack1(self.leftPanelBox)
|
2009-08-06 21:36:11 +02:00
|
|
|
self.mainHBox.add(self.hpane)
|
|
|
|
# hierarchy: self.mainHBox / self.hpane / self.graphBox / self.canvas / self.fig / self.ax
|
|
|
|
|
|
|
|
self.graphBox = gtk.VBox(False, 0)
|
|
|
|
self.graphBox.show()
|
2009-04-11 13:14:32 +02:00
|
|
|
self.hpane.pack2(self.graphBox)
|
2009-05-10 23:30:26 +02:00
|
|
|
self.hpane.show()
|
2009-04-11 13:14:32 +02:00
|
|
|
|
|
|
|
self.fig = None
|
2009-04-17 06:44:43 +02:00
|
|
|
#self.exportButton.set_sensitive(False)
|
2009-04-11 13:14:32 +02:00
|
|
|
self.canvas = None
|
|
|
|
|
2009-05-10 23:30:26 +02:00
|
|
|
|
2009-07-19 22:19:58 +02:00
|
|
|
self.db.rollback()
|
2009-04-11 13:14:32 +02:00
|
|
|
|
2008-12-04 08:15:38 +01:00
|
|
|
def get_vbox(self):
|
|
|
|
"""returns the vbox of this thread"""
|
|
|
|
return self.mainHBox
|
|
|
|
#end def get_vbox
|
|
|
|
|
2009-03-07 10:23:30 +01:00
|
|
|
def clearGraphData(self):
|
|
|
|
|
2009-08-06 21:36:11 +02:00
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if self.canvas:
|
|
|
|
self.graphBox.remove(self.canvas)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if self.fig != None:
|
|
|
|
self.fig.clear()
|
|
|
|
self.fig = Figure(figsize=(5,4), dpi=100)
|
|
|
|
if self.canvas is not None:
|
|
|
|
self.canvas.destroy()
|
|
|
|
|
|
|
|
self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
|
|
|
|
except:
|
|
|
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
2010-08-14 06:23:30 +02:00
|
|
|
print _("***Error: ")+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
2009-08-06 21:36:11 +02:00
|
|
|
raise
|
2009-03-07 10:23:30 +01:00
|
|
|
|
2008-12-04 08:15:38 +01:00
|
|
|
def generateGraph(self, widget, data):
|
2009-08-06 21:36:11 +02:00
|
|
|
try:
|
|
|
|
self.clearGraphData()
|
|
|
|
|
|
|
|
sitenos = []
|
|
|
|
playerids = []
|
|
|
|
|
|
|
|
sites = self.filters.getSites()
|
|
|
|
heroes = self.filters.getHeroes()
|
|
|
|
siteids = self.filters.getSiteIds()
|
|
|
|
limits = self.filters.getLimits()
|
2010-01-22 18:36:21 +01:00
|
|
|
games = self.filters.getGames()
|
2010-10-03 10:27:56 +02:00
|
|
|
graphops = self.filters.getGraphOps()
|
2010-10-05 19:04:06 +02:00
|
|
|
names = ""
|
2010-01-22 18:36:21 +01:00
|
|
|
|
2009-10-14 00:06:09 +02:00
|
|
|
for i in ('show', 'none'):
|
|
|
|
if i in limits:
|
|
|
|
limits.remove(i)
|
2009-08-06 21:36:11 +02:00
|
|
|
# Which sites are selected?
|
|
|
|
for site in sites:
|
|
|
|
if sites[site] == True:
|
|
|
|
sitenos.append(siteids[site])
|
2010-10-06 04:53:07 +02:00
|
|
|
_hname = Charset.to_utf8(heroes[site])
|
2010-01-27 06:04:13 +01:00
|
|
|
result = self.db.get_player_id(self.conf, site, _hname)
|
|
|
|
if result is not None:
|
|
|
|
playerids.append(int(result))
|
2010-10-05 19:04:06 +02:00
|
|
|
names = names + "\n"+_hname + " on "+site
|
2009-08-06 21:36:11 +02:00
|
|
|
|
|
|
|
if not sitenos:
|
|
|
|
#Should probably pop up here.
|
2010-08-14 06:23:30 +02:00
|
|
|
print _("No sites selected - defaulting to PokerStars")
|
2009-11-25 21:55:58 +01:00
|
|
|
self.db.rollback()
|
2009-08-06 21:36:11 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if not playerids:
|
2010-08-14 06:23:30 +02:00
|
|
|
print _("No player ids found")
|
2009-11-25 21:55:58 +01:00
|
|
|
self.db.rollback()
|
2009-08-06 21:36:11 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if not limits:
|
2010-08-14 06:23:30 +02:00
|
|
|
print _("No limits found")
|
2009-11-25 21:55:58 +01:00
|
|
|
self.db.rollback()
|
2009-08-06 21:36:11 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
#Set graph properties
|
|
|
|
self.ax = self.fig.add_subplot(111)
|
|
|
|
|
|
|
|
#Get graph data from DB
|
|
|
|
starttime = time()
|
2010-10-03 10:27:56 +02:00
|
|
|
(green, blue, red) = self.getRingProfitGraph(playerids, sitenos, limits, games, graphops['dspin'])
|
2010-08-14 06:23:30 +02:00
|
|
|
print _("Graph generated in: %s") %(time() - starttime)
|
2009-08-06 21:36:11 +02:00
|
|
|
|
|
|
|
|
2010-10-03 10:27:56 +02:00
|
|
|
|
2009-08-06 21:36:11 +02:00
|
|
|
#Set axis labels and grid overlay properites
|
2010-08-14 06:23:30 +02:00
|
|
|
self.ax.set_xlabel(_("Hands"), fontsize = 12)
|
2010-10-03 10:27:56 +02:00
|
|
|
# SET LABEL FOR X AXIS
|
|
|
|
self.ax.set_ylabel(graphops['dspin'], fontsize = 12)
|
2009-08-06 21:36:11 +02:00
|
|
|
self.ax.grid(color='g', linestyle=':', linewidth=0.2)
|
2009-12-02 07:02:06 +01:00
|
|
|
if green == None or green == []:
|
2010-08-14 06:23:30 +02:00
|
|
|
self.ax.set_title(_("No Data for Player(s) Found"))
|
2010-01-27 18:37:23 +01:00
|
|
|
green = ([ 0., 0., 0., 0., 500., 1000., 900., 800.,
|
|
|
|
700., 600., 500., 400., 300., 200., 100., 0.,
|
|
|
|
500., 1000., 1000., 1000., 1000., 1000., 1000., 1000.,
|
|
|
|
1000., 1000., 1000., 1000., 1000., 1000., 875., 750.,
|
|
|
|
625., 500., 375., 250., 125., 0., 0., 0.,
|
|
|
|
0., 500., 1000., 900., 800., 700., 600., 500.,
|
|
|
|
400., 300., 200., 100., 0., 500., 1000., 1000.])
|
|
|
|
red = ([ 0., 0., 0., 0., 500., 1000., 900., 800.,
|
|
|
|
700., 600., 500., 400., 300., 200., 100., 0.,
|
|
|
|
0., 0., 0., 0., 0., 0., 125., 250.,
|
|
|
|
375., 500., 500., 500., 500., 500., 500., 500.,
|
|
|
|
500., 500., 375., 250., 125., 0., 0., 0.,
|
|
|
|
0., 500., 1000., 900., 800., 700., 600., 500.,
|
|
|
|
400., 300., 200., 100., 0., 500., 1000., 1000.])
|
|
|
|
blue = ([ 0., 0., 0., 0., 500., 1000., 900., 800.,
|
|
|
|
700., 600., 500., 400., 300., 200., 100., 0.,
|
|
|
|
0., 0., 0., 0., 0., 0., 125., 250.,
|
|
|
|
375., 500., 625., 750., 875., 1000., 875., 750.,
|
|
|
|
625., 500., 375., 250., 125., 0., 0., 0.,
|
|
|
|
0., 500., 1000., 900., 800., 700., 600., 500.,
|
|
|
|
400., 300., 200., 100., 0., 500., 1000., 1000.])
|
|
|
|
|
2011-02-23 06:07:49 +01:00
|
|
|
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]))
|
2010-01-27 18:37:23 +01:00
|
|
|
self.graphBox.add(self.canvas)
|
|
|
|
self.canvas.show()
|
|
|
|
self.canvas.draw()
|
2009-08-06 21:36:11 +02:00
|
|
|
|
|
|
|
#TODO: Do something useful like alert user
|
2010-01-27 18:37:23 +01:00
|
|
|
#print "No hands returned by graph query"
|
2009-08-06 21:36:11 +02:00
|
|
|
else:
|
2011-02-23 06:07:49 +01:00
|
|
|
self.ax.set_title(_("Profit graph for ring games"+names),fontsize=12)
|
2009-08-06 21:36:11 +02:00
|
|
|
|
|
|
|
#Draw plot
|
2011-02-23 06:07:49 +01:00
|
|
|
self.ax.plot(green, color='green', label=_('Hands: %d\nProfit (%s): %.2f') %(len(green),graphops['dspin'], green[-1]))
|
2010-10-04 05:56:52 +02:00
|
|
|
if graphops['showdown'] == 'ON':
|
2011-02-23 06:07:49 +01:00
|
|
|
self.ax.plot(blue, color='blue', label=_('Showdown (%s): %.2f') %(graphops['dspin'], blue[-1]))
|
2010-10-04 05:56:52 +02:00
|
|
|
if graphops['nonshowdown'] == 'ON':
|
2011-02-23 06:07:49 +01:00
|
|
|
self.ax.plot(red, color='red', label=_('Non-showdown (%s): %.2f') %(graphops['dspin'], red[-1]))
|
2010-10-03 10:27:56 +02:00
|
|
|
|
2009-12-03 21:20:42 +01:00
|
|
|
if sys.version[0:3] == '2.5':
|
2010-06-11 22:09:04 +02:00
|
|
|
self.ax.legend(loc='upper left', shadow=True, prop=FontProperties(size='smaller'))
|
2009-12-03 21:20:42 +01:00
|
|
|
else:
|
2010-06-11 22:09:04 +02:00
|
|
|
self.ax.legend(loc='upper left', fancybox=True, shadow=True, prop=FontProperties(size='smaller'))
|
2009-12-02 07:02:06 +01:00
|
|
|
|
2009-08-06 21:36:11 +02:00
|
|
|
self.graphBox.add(self.canvas)
|
|
|
|
self.canvas.show()
|
|
|
|
self.canvas.draw()
|
|
|
|
#self.exportButton.set_sensitive(True)
|
|
|
|
except:
|
|
|
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
2010-08-14 06:23:30 +02:00
|
|
|
print _("***Error: ")+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
2009-08-06 21:36:11 +02:00
|
|
|
|
2008-12-04 08:15:38 +01:00
|
|
|
#end of def showClicked
|
|
|
|
|
2010-10-03 10:27:56 +02:00
|
|
|
|
|
|
|
def getRingProfitGraph(self, names, sites, limits, games, units):
|
|
|
|
# tmp = self.sql.query['getRingProfitAllHandsPlayerIdSite']
|
2008-12-19 08:52:32 +01:00
|
|
|
# print "DEBUG: getRingProfitGraph"
|
2010-10-03 10:27:56 +02:00
|
|
|
|
|
|
|
if units == '$':
|
|
|
|
tmp = self.sql.query['getRingProfitAllHandsPlayerIdSiteInDollars']
|
|
|
|
elif units == 'BB':
|
|
|
|
tmp = self.sql.query['getRingProfitAllHandsPlayerIdSiteInBB']
|
|
|
|
|
|
|
|
|
2009-04-11 13:14:32 +02:00
|
|
|
start_date, end_date = self.filters.getDates()
|
2008-12-19 08:52:32 +01:00
|
|
|
|
2009-07-19 22:19:58 +02:00
|
|
|
#Buggered if I can find a way to do this 'nicely' take a list of integers and longs
|
2008-12-19 08:52:32 +01:00
|
|
|
# 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))
|
2009-10-14 00:06:09 +02:00
|
|
|
#nametest = nametest.replace("L", "")
|
|
|
|
|
2010-01-22 18:36:21 +01:00
|
|
|
q = []
|
|
|
|
for m in self.filters.display.items():
|
|
|
|
if m[0] == 'Games' and m[1]:
|
|
|
|
for n in games:
|
|
|
|
if games[n]:
|
|
|
|
q.append(n)
|
|
|
|
if len(q) > 0:
|
|
|
|
gametest = str(tuple(q))
|
|
|
|
gametest = gametest.replace("L", "")
|
|
|
|
gametest = gametest.replace(",)",")")
|
|
|
|
gametest = gametest.replace("u'","'")
|
|
|
|
gametest = "and gt.category in %s" % gametest
|
|
|
|
else:
|
|
|
|
gametest = "and gt.category IS NULL"
|
|
|
|
tmp = tmp.replace("<game_test>", gametest)
|
|
|
|
|
2009-10-14 00:06:09 +02:00
|
|
|
lims = [int(x) for x in limits if x.isdigit()]
|
2009-11-21 04:11:31 +01:00
|
|
|
potlims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'pl']
|
2009-10-14 00:06:09 +02:00
|
|
|
nolims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'nl']
|
2011-02-15 08:02:15 +01:00
|
|
|
capnolims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'cn']
|
2009-10-14 00:06:09 +02:00
|
|
|
limittest = "and ( (gt.limitType = 'fl' and gt.bigBlind in "
|
|
|
|
# and ( (limit and bb in()) or (nolimit and bb in ()) )
|
|
|
|
if lims:
|
|
|
|
blindtest = str(tuple(lims))
|
|
|
|
blindtest = blindtest.replace("L", "")
|
|
|
|
blindtest = blindtest.replace(",)",")")
|
|
|
|
limittest = limittest + blindtest + ' ) '
|
|
|
|
else:
|
|
|
|
limittest = limittest + '(-1) ) '
|
2009-11-21 04:11:31 +01:00
|
|
|
limittest = limittest + " or (gt.limitType = 'pl' and gt.bigBlind in "
|
|
|
|
if potlims:
|
|
|
|
blindtest = str(tuple(potlims))
|
|
|
|
blindtest = blindtest.replace("L", "")
|
|
|
|
blindtest = blindtest.replace(",)",")")
|
|
|
|
limittest = limittest + blindtest + ' ) '
|
|
|
|
else:
|
|
|
|
limittest = limittest + '(-1) ) '
|
2009-10-14 00:06:09 +02:00
|
|
|
limittest = limittest + " or (gt.limitType = 'nl' and gt.bigBlind in "
|
|
|
|
if nolims:
|
|
|
|
blindtest = str(tuple(nolims))
|
|
|
|
blindtest = blindtest.replace("L", "")
|
|
|
|
blindtest = blindtest.replace(",)",")")
|
2011-02-15 08:02:15 +01:00
|
|
|
limittest = limittest + blindtest + ' ) '
|
|
|
|
else:
|
|
|
|
limittest = limittest + '(-1) ) '
|
|
|
|
limittest = limittest + " or (gt.limitType = 'cn' and gt.bigBlind in "
|
|
|
|
if capnolims:
|
|
|
|
blindtest = str(tuple(capnolims))
|
|
|
|
blindtest = blindtest.replace("L", "")
|
|
|
|
blindtest = blindtest.replace(",)",")")
|
2009-10-14 00:06:09 +02:00
|
|
|
limittest = limittest + blindtest + ' ) )'
|
|
|
|
else:
|
|
|
|
limittest = limittest + '(-1) ) )'
|
2009-11-21 04:11:31 +01:00
|
|
|
|
2009-10-14 00:06:09 +02:00
|
|
|
if type == 'ring':
|
|
|
|
limittest = limittest + " and gt.type = 'ring' "
|
|
|
|
elif type == 'tour':
|
|
|
|
limittest = limittest + " and gt.type = 'tour' "
|
2008-12-19 08:52:32 +01:00
|
|
|
|
|
|
|
#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)
|
2008-12-19 09:21:58 +01:00
|
|
|
tmp = tmp.replace("<startdate_test>", start_date)
|
|
|
|
tmp = tmp.replace("<enddate_test>", end_date)
|
2009-04-14 15:31:29 +02:00
|
|
|
tmp = tmp.replace("<limit_test>", limittest)
|
2009-10-14 00:06:09 +02:00
|
|
|
tmp = tmp.replace(",)", ")")
|
2008-12-19 08:52:32 +01:00
|
|
|
|
2009-04-14 15:31:29 +02:00
|
|
|
#print "DEBUG: sql query:"
|
|
|
|
#print tmp
|
2009-06-23 00:30:54 +02:00
|
|
|
self.db.cursor.execute(tmp)
|
2008-12-04 08:15:38 +01:00
|
|
|
#returns (HandId,Winnings,Costs,Profit)
|
|
|
|
winnings = self.db.cursor.fetchall()
|
2009-07-19 22:19:58 +02:00
|
|
|
self.db.rollback()
|
2008-12-04 08:15:38 +01:00
|
|
|
|
2010-02-01 00:46:51 +01:00
|
|
|
if len(winnings) == 0:
|
2010-01-27 18:37:23 +01:00
|
|
|
return (None, None, None)
|
2008-12-11 15:55:03 +01:00
|
|
|
|
2009-12-02 07:02:06 +01:00
|
|
|
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)
|
2008-10-08 13:53:25 +02:00
|
|
|
#end of def getRingProfitGraph
|
|
|
|
|
2008-12-06 12:51:36 +01:00
|
|
|
def exportGraph (self, widget, data):
|
2009-03-05 13:31:56 +01:00
|
|
|
if self.fig is None:
|
|
|
|
return # Might want to disable export button until something has been generated.
|
2010-06-28 00:21:40 +02:00
|
|
|
|
2010-08-14 06:23:30 +02:00
|
|
|
dia_chooser = gtk.FileChooserDialog(title=_("Please choose the directory you wish to export to:"),
|
2010-06-28 00:21:40 +02:00
|
|
|
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
|
|
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OK,gtk.RESPONSE_OK))
|
|
|
|
dia_chooser.set_destroy_with_parent(True)
|
|
|
|
dia_chooser.set_transient_for(self.parent)
|
|
|
|
try:
|
|
|
|
dia_chooser.set_filename(self.exportFile) # use previously chosen export path as default
|
|
|
|
except:
|
|
|
|
pass
|
2008-12-06 12:51:36 +01:00
|
|
|
|
|
|
|
response = dia_chooser.run()
|
2010-06-28 00:21:40 +02:00
|
|
|
|
2010-07-03 00:13:36 +02:00
|
|
|
if response <> gtk.RESPONSE_OK:
|
2010-08-14 06:23:30 +02:00
|
|
|
print _('Closed, no graph exported')
|
2010-06-28 00:21:40 +02:00
|
|
|
dia_chooser.destroy()
|
|
|
|
return
|
|
|
|
|
|
|
|
# generate a unique filename for export
|
|
|
|
now = datetime.now()
|
|
|
|
now_formatted = now.strftime("%Y%m%d%H%M%S")
|
|
|
|
self.exportFile = dia_chooser.get_filename() + "/fpdb" + now_formatted + ".png"
|
2008-12-06 12:51:36 +01:00
|
|
|
dia_chooser.destroy()
|
2010-06-28 00:21:40 +02:00
|
|
|
|
|
|
|
#print "DEBUG: self.exportFile = %s" %(self.exportFile)
|
|
|
|
self.fig.savefig(self.exportFile, format="png")
|
|
|
|
|
|
|
|
#display info box to confirm graph created
|
|
|
|
diainfo = gtk.MessageDialog(parent=self.parent,
|
|
|
|
flags=gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
type=gtk.MESSAGE_INFO,
|
|
|
|
buttons=gtk.BUTTONS_OK,
|
2010-08-14 06:23:30 +02:00
|
|
|
message_format=_("Graph created"))
|
2010-06-28 00:21:40 +02:00
|
|
|
diainfo.format_secondary_text(self.exportFile)
|
|
|
|
diainfo.run()
|
|
|
|
diainfo.destroy()
|
|
|
|
|
|
|
|
#end of def exportGraph
|