From 1939979e3c64e931e6a1be2fb6916d7e9ca4947e Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 14 Apr 2009 21:31:29 +0800 Subject: [PATCH] Make Grapher work with limits --- pyfpdb/Filters.py | 7 +++++++ pyfpdb/FpdbSQLQueries.py | 19 +++---------------- pyfpdb/GuiGraphViewer.py | 21 ++++++++++++++------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index 1e93127b..67e26443 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -125,6 +125,13 @@ class Filters(threading.Thread): def getHeroes(self): return self.heroes + def getLimits(self): + ltuple = [] + for l in self.limits: + if self.limits[l] == True: + ltuple.append(l) + return ltuple + def getDates(self): return self.__get_dates() diff --git a/pyfpdb/FpdbSQLQueries.py b/pyfpdb/FpdbSQLQueries.py index fe04aec6..fca17a5f 100644 --- a/pyfpdb/FpdbSQLQueries.py +++ b/pyfpdb/FpdbSQLQueries.py @@ -609,7 +609,7 @@ class FpdbSQLQueries: elif(self.dbname == 'SQLite'): self.query['getSiteId'] = """SELECT id from Sites where name = %s""" - if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'): + if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL') or (self.dbname == 'SQLite'): self.query['getRingProfitAllHandsPlayerIdSite'] = """ SELECT hp.handId, hp.winnings, coalesce(hp.ante,0) + SUM(ha.amount) , hp.winnings - (coalesce(hp.ante,0) + SUM(ha.amount)) @@ -617,28 +617,15 @@ class FpdbSQLQueries: INNER JOIN Players pl ON hp.playerId = pl.id INNER JOIN Hands h ON h.id = hp.handId INNER JOIN HandsActions ha ON ha.handPlayerId = hp.id + INNER JOIN Gametypes g ON h.gametypeId = g.id where pl.id in AND pl.siteId in AND h.handStart > '' AND h.handStart < '' + AND g.bigBlind in AND hp.tourneysPlayersId IS NULL GROUP BY hp.handId, hp.winnings, h.handStart, hp.ante ORDER BY h.handStart""" - elif(self.dbname == 'SQLite'): - #Probably doesn't work. - self.query['getRingProfitAllHandsPlayerIdSite'] = """ - SELECT hp.handId, hp.winnings, SUM(ha.amount), hp.winnings - SUM(ha.amount) - FROM HandsPlayers hp - INNER JOIN Players pl ON hp.playerId = pl.id - INNER JOIN Hands h ON h.id = hp.handId - INNER JOIN HandsActions ha ON ha.handPlayerId = hp.id - where pl.id in - AND pl.siteId in - AND h.handStart > '' - AND h.handStart < '' - AND hp.tourneysPlayersId IS NULL - GROUP BY hp.handId, hp.winnings, h.handStart - ORDER BY h.handStart""" if(self.dbname == 'MySQL InnoDB'): self.query['playerStats'] = """ diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 359161cf..9aaa4506 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -124,9 +124,10 @@ class GuiGraphViewer (threading.Thread): sitenos = [] playerids = [] - sites = self.filters.getSites() - heroes = self.filters.getHeroes() + sites = self.filters.getSites() + heroes = self.filters.getHeroes() siteids = self.filters.getSiteIds() + limits = self.filters.getLimits() # Which sites are selected? for site in sites: if sites[site] == True: @@ -141,18 +142,20 @@ class GuiGraphViewer (threading.Thread): print "No sites selected - defaulting to PokerStars" sitenos = [2] - if not playerids: print "No player ids found" return + if not limits: + print "No limits found" + return #Set graph properties self.ax = self.fig.add_subplot(111) #Get graph data from DB starttime = time() - line = self.getRingProfitGraph(playerids, sitenos) + line = self.getRingProfitGraph(playerids, sitenos, limits) print "Graph generated in: %s" %(time() - starttime) self.ax.set_title("Profit graph for ring games") @@ -182,7 +185,7 @@ class GuiGraphViewer (threading.Thread): self.exportButton.set_sensitive(True) #end of def showClicked - def getRingProfitGraph(self, names, sites): + def getRingProfitGraph(self, names, sites, limits): tmp = self.sql.query['getRingProfitAllHandsPlayerIdSite'] # print "DEBUG: getRingProfitGraph" start_date, end_date = self.filters.getDates() @@ -192,18 +195,22 @@ class GuiGraphViewer (threading.Thread): # [5L] into (5) not (5,) and [5L, 2829L] into (5, 2829) nametest = str(tuple(names)) sitetest = str(tuple(sites)) + limittest = str(tuple(limits)) nametest = nametest.replace("L", "") nametest = nametest.replace(",)",")") sitetest = sitetest.replace(",)",")") + limittest = limittest.replace("L", "") + limittest = limittest.replace(",)",")") #Must be a nicer way to deal with tuples of size 1 ie. (2,) - which makes sql barf tmp = tmp.replace("", nametest) tmp = tmp.replace("", sitetest) tmp = tmp.replace("", start_date) tmp = tmp.replace("", end_date) + tmp = tmp.replace("", limittest) -# print "DEBUG: sql query:" -# print tmp + #print "DEBUG: sql query:" + #print tmp self.cursor.execute(tmp) #returns (HandId,Winnings,Costs,Profit) winnings = self.db.cursor.fetchall()