Make Grapher work with limits

This commit is contained in:
Worros 2009-04-14 21:31:29 +08:00
parent dd563aab39
commit 1939979e3c
3 changed files with 24 additions and 23 deletions

View File

@ -125,6 +125,13 @@ class Filters(threading.Thread):
def getHeroes(self): def getHeroes(self):
return self.heroes 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): def getDates(self):
return self.__get_dates() return self.__get_dates()

View File

@ -609,7 +609,7 @@ class FpdbSQLQueries:
elif(self.dbname == 'SQLite'): elif(self.dbname == 'SQLite'):
self.query['getSiteId'] = """SELECT id from Sites where name = %s""" 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'] = """ self.query['getRingProfitAllHandsPlayerIdSite'] = """
SELECT hp.handId, hp.winnings, coalesce(hp.ante,0) + SUM(ha.amount) SELECT hp.handId, hp.winnings, coalesce(hp.ante,0) + SUM(ha.amount)
, 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 Players pl ON hp.playerId = pl.id
INNER JOIN Hands h ON h.id = hp.handId INNER JOIN Hands h ON h.id = hp.handId
INNER JOIN HandsActions ha ON ha.handPlayerId = hp.id INNER JOIN HandsActions ha ON ha.handPlayerId = hp.id
INNER JOIN Gametypes g ON h.gametypeId = g.id
where pl.id in <player_test> where pl.id in <player_test>
AND pl.siteId in <site_test> AND pl.siteId in <site_test>
AND h.handStart > '<startdate_test>' AND h.handStart > '<startdate_test>'
AND h.handStart < '<enddate_test>' AND h.handStart < '<enddate_test>'
AND g.bigBlind in <limit_test>
AND hp.tourneysPlayersId IS NULL AND hp.tourneysPlayersId IS NULL
GROUP BY hp.handId, hp.winnings, h.handStart, hp.ante GROUP BY hp.handId, hp.winnings, h.handStart, hp.ante
ORDER BY h.handStart""" 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 <player_test>
AND pl.siteId in <site_test>
AND h.handStart > '<startdate_test>'
AND h.handStart < '<enddate_test>'
AND hp.tourneysPlayersId IS NULL
GROUP BY hp.handId, hp.winnings, h.handStart
ORDER BY h.handStart"""
if(self.dbname == 'MySQL InnoDB'): if(self.dbname == 'MySQL InnoDB'):
self.query['playerStats'] = """ self.query['playerStats'] = """

View File

@ -127,6 +127,7 @@ class GuiGraphViewer (threading.Thread):
sites = self.filters.getSites() sites = self.filters.getSites()
heroes = self.filters.getHeroes() heroes = self.filters.getHeroes()
siteids = self.filters.getSiteIds() siteids = self.filters.getSiteIds()
limits = self.filters.getLimits()
# Which sites are selected? # Which sites are selected?
for site in sites: for site in sites:
if sites[site] == True: if sites[site] == True:
@ -141,18 +142,20 @@ class GuiGraphViewer (threading.Thread):
print "No sites selected - defaulting to PokerStars" print "No sites selected - defaulting to PokerStars"
sitenos = [2] sitenos = [2]
if not playerids: if not playerids:
print "No player ids found" print "No player ids found"
return return
if not limits:
print "No limits found"
return
#Set graph properties #Set graph properties
self.ax = self.fig.add_subplot(111) self.ax = self.fig.add_subplot(111)
#Get graph data from DB #Get graph data from DB
starttime = time() starttime = time()
line = self.getRingProfitGraph(playerids, sitenos) line = self.getRingProfitGraph(playerids, sitenos, limits)
print "Graph generated in: %s" %(time() - starttime) print "Graph generated in: %s" %(time() - starttime)
self.ax.set_title("Profit graph for ring games") self.ax.set_title("Profit graph for ring games")
@ -182,7 +185,7 @@ class GuiGraphViewer (threading.Thread):
self.exportButton.set_sensitive(True) self.exportButton.set_sensitive(True)
#end of def showClicked #end of def showClicked
def getRingProfitGraph(self, names, sites): def getRingProfitGraph(self, names, sites, limits):
tmp = self.sql.query['getRingProfitAllHandsPlayerIdSite'] tmp = self.sql.query['getRingProfitAllHandsPlayerIdSite']
# print "DEBUG: getRingProfitGraph" # print "DEBUG: getRingProfitGraph"
start_date, end_date = self.filters.getDates() 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) # [5L] into (5) not (5,) and [5L, 2829L] into (5, 2829)
nametest = str(tuple(names)) nametest = str(tuple(names))
sitetest = str(tuple(sites)) sitetest = str(tuple(sites))
limittest = str(tuple(limits))
nametest = nametest.replace("L", "") nametest = nametest.replace("L", "")
nametest = nametest.replace(",)",")") nametest = nametest.replace(",)",")")
sitetest = sitetest.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 #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("<player_test>", nametest)
tmp = tmp.replace("<site_test>", sitetest) tmp = tmp.replace("<site_test>", sitetest)
tmp = tmp.replace("<startdate_test>", start_date) tmp = tmp.replace("<startdate_test>", start_date)
tmp = tmp.replace("<enddate_test>", end_date) tmp = tmp.replace("<enddate_test>", end_date)
tmp = tmp.replace("<limit_test>", limittest)
# print "DEBUG: sql query:" #print "DEBUG: sql query:"
# print tmp #print tmp
self.cursor.execute(tmp) self.cursor.execute(tmp)
#returns (HandId,Winnings,Costs,Profit) #returns (HandId,Winnings,Costs,Profit)
winnings = self.db.cursor.fetchall() winnings = self.db.cursor.fetchall()