From 1cc8304a21afeac4ccf8530ede898e2fe62f281c Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Fri, 27 May 2011 16:12:04 -0700 Subject: [PATCH] Add new filter 'Currency'. I occasionally play for play money, but don't want the thousands of play money chips I win dominating the real money graphs. Default to including every currency type except for 'play'. Use the Currency filter in the session viewer and the ring game graph viewer. --- pyfpdb/Filters.py | 103 ++++++++++++++++++++++++++++++++++++++++++++- pyfpdb/GuiGraphViewer.py | 16 ++++++- pyfpdb/GuiSessionViewer.py | 23 ++++++++-- pyfpdb/SQL.py | 7 +++ 4 files changed, 142 insertions(+), 7 deletions(-) diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index 34354858..a1b50745 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -62,14 +62,21 @@ class Filters(threading.Thread): ,"studhilo" : _("7 Card Stud Hi/Lo") } + self.currencyName = {"USD" : _("US Dollars") + ,"EUR" : _("Euros") + ,"T$" : _("Tournament Dollars") + ,"play": _("Play Money") + } + # text used on screen stored here so that it can be configured self.filterText = {'limitsall':_('All'), 'limitsnone':_('None'), 'limitsshow':_('Show _Limits') ,'gamesall':_('All'), 'gamesnone':_('None') + ,'currenciesall':_('All'), 'currenciesnone':_('None') ,'seatsbetween':_('Between:'), 'seatsand':_('And:'), 'seatsshow':_('Show Number of _Players') ,'playerstitle':_('Hero:'), 'sitestitle':(_('Sites')+':'), 'gamestitle':(_('Games')+':') ,'limitstitle':_('Limits:'), 'seatstitle':_('Number of Players:') ,'groupstitle':_('Grouping:'), 'posnshow':_('Show Position Stats') - ,'datestitle':_('Date:') + ,'datestitle':_('Date:'), 'currenciestitle':(_('Currencies')+':') ,'groupsall':_('All Players') ,'limitsFL':'FL', 'limitsNL':'NL', 'limitsPL':'PL', 'limitsCN':'CAP', 'ring':_('Ring'), 'tour':_('Tourney') } @@ -110,6 +117,7 @@ class Filters(threading.Thread): self.boxes = {} self.toggles = {} self.graphops = {} + self.currencies = {} for site in self.conf.get_supported_sites(): #Get db site id for filtering later @@ -164,6 +172,18 @@ class Filters(threading.Thread): self.fillGamesFrame(vbox) gamesFrame.add(vbox) + # Currencies + currenciesFrame = gtk.Frame() + currenciesFrame.set_label_align(0.0, 0.0) + currenciesFrame.show() + vbox = gtk.VBox(False, 0) + self.cbCurrencies = {} + self.cbNoCurrencies = None + self.cbAllCurrencies = None + + self.fillCurrenciesFrame(vbox) + currenciesFrame.add(vbox) + # Limits limitsFrame = gtk.Frame() limitsFrame.show() @@ -230,6 +250,7 @@ class Filters(threading.Thread): self.mainVBox.pack_start(playerFrame, expand) self.mainVBox.pack_start(sitesFrame, expand) self.mainVBox.pack_start(gamesFrame, expand) + self.mainVBox.pack_start(currenciesFrame, expand) self.mainVBox.pack_start(limitsFrame, expand) self.mainVBox.pack_start(seatsFrame, expand) self.mainVBox.pack_start(groupsFrame, expand) @@ -248,6 +269,8 @@ class Filters(threading.Thread): sitesFrame.hide() if "Games" not in self.display or self.display["Games"] == False: gamesFrame.hide() + if "Currencies" not in self.display or self.display["Currencies"] == False: + currenciesFrame.hide() if "Limits" not in self.display or self.display["Limits"] == False: limitsFrame.hide() if "Seats" not in self.display or self.display["Seats"] == False: @@ -302,6 +325,10 @@ class Filters(threading.Thread): return self.games #end def getGames + def getCurrencies(self): + return self.currencies + #end def getCurrencies + def getSiteIds(self): return self.siteid #end def getSiteIds @@ -435,6 +462,14 @@ class Filters(threading.Thread): cb.set_active(True) return(cb) + def createCurrencyLine(self, hbox, currency, ctext): + cb = gtk.CheckButton(ctext.replace("_", "__")) + cb.connect('clicked', self.__set_currency_select, currency) + hbox.pack_start(cb, False, False, 0) + if currency != "none" and currency != "all" and currency != "play": + cb.set_active(True) + return(cb) + def createLimitLine(self, hbox, limit, ltext): cb = gtk.CheckButton(str(ltext)) cb.connect('clicked', self.__set_limit_select, limit) @@ -468,6 +503,25 @@ class Filters(threading.Thread): self.cbAllGames.set_active(False) #end def __set_game_select + def __set_currency_select(self, w, currency): + if (currency == 'all'): + if (w.get_active()): + for cb in self.cbCurrencies.values(): + cb.set_active(True) + elif (currency == 'none'): + if (w.get_active()): + for cb in self.cbCurrencies.values(): + cb.set_active(False) + else: + self.currencies[currency] = w.get_active() + if (w.get_active()): # when we turn a currency on, turn 'none' off if it's on + if (self.cbNoCurrencies and self.cbNoCurrencies.get_active()): + self.cbNoCurrencies.set_active(False) + else: # when we turn a currency off, turn 'all' off if it's on + if (self.cbAllCurrencies and self.cbAllCurrencies.get_active()): + self.cbAllCurrencies.set_active(False) + #end def __set_currency_select + def __set_limit_select(self, w, limit): #print "__set_limit_select: limit =", limit, w.get_active() self.limits[limit] = w.get_active() @@ -823,6 +877,53 @@ class Filters(threading.Thread): log.info(_("No games returned from database")) #end def fillGamesFrame + def fillCurrenciesFrame(self, vbox): + top_hbox = gtk.HBox(False, 0) + vbox.pack_start(top_hbox, False, False, 0) + lbl_title = gtk.Label(self.filterText['currenciestitle']) + lbl_title.set_alignment(xalign=0.0, yalign=0.5) + top_hbox.pack_start(lbl_title, expand=True, padding=3) + showb = gtk.Button(label=_("hide"), stock=None, use_underline=True) + showb.set_alignment(xalign=1.0, yalign=0.5) + showb.connect('clicked', self.__toggle_box, 'Currencies') + self.toggles['Currencies'] = showb + top_hbox.pack_start(showb, expand=False, padding=1) + + vbox1 = gtk.VBox(False, 0) + vbox.pack_start(vbox1, False, False, 0) + self.boxes['Currencies'] = vbox1 + + self.cursor.execute(self.sql.query['getCurrencies']) + result = self.db.cursor.fetchall() + if len(result) >= 1: + for line in result: + hbox = gtk.HBox(False, 0) + vbox1.pack_start(hbox, False, True, 0) + if (self.currencyName.has_key(line[0])): + cname = self.currencyName[line[0]] + else: + cname = line[0] + self.cbCurrencies[line[0]] = self.createCurrencyLine(hbox, line[0], cname) + + if len(result) >= 2: + hbox = gtk.HBox(True, 0) + vbox1.pack_start(hbox, False, False, 0) + vbox2 = gtk.VBox(False, 0) + hbox.pack_start(vbox2, False, False, 0) + vbox3 = gtk.VBox(False, 0) + hbox.pack_start(vbox3, False, False, 0) + + hbox = gtk.HBox(False, 0) + vbox2.pack_start(hbox, False, False, 0) + self.cbAllCurrencies = self.createCurrencyLine(hbox, 'all', self.filterText['currenciesall']) + hbox = gtk.HBox(False, 0) + vbox3.pack_start(hbox, False, False, 0) + self.cbNoCurrencies = self.createCurrencyLine(hbox, 'none', self.filterText['currenciesnone']) + else: + print _("INFO: No currencies returned from database") + log.info(_("No currencies returned from database")) + #end def fillCurrenciesFrame + def fillLimitsFrame(self, vbox, display): top_hbox = gtk.HBox(False, 0) vbox.pack_start(top_hbox, False, False, 0) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 6501cbe2..36e5b93d 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -65,6 +65,7 @@ class GuiGraphViewer (threading.Thread): filters_display = { "Heroes" : True, "Sites" : True, "Games" : True, + "Currencies": True, "Limits" : True, "LimitSep" : True, "LimitType" : True, @@ -145,6 +146,7 @@ class GuiGraphViewer (threading.Thread): siteids = self.filters.getSiteIds() limits = self.filters.getLimits() games = self.filters.getGames() + currencies = self.filters.getCurrencies() graphops = self.filters.getGraphOps() names = "" @@ -182,7 +184,7 @@ class GuiGraphViewer (threading.Thread): #Get graph data from DB starttime = time() - (green, blue, red) = self.getRingProfitGraph(playerids, sitenos, limits, games, graphops['dspin']) + (green, blue, red) = self.getRingProfitGraph(playerids, sitenos, limits, games, currencies, graphops['dspin']) print _("Graph generated in: %s") %(time() - starttime) @@ -251,7 +253,7 @@ class GuiGraphViewer (threading.Thread): #end of def showClicked - def getRingProfitGraph(self, names, sites, limits, games, units): + def getRingProfitGraph(self, names, sites, limits, games, currencies, units): # tmp = self.sql.query['getRingProfitAllHandsPlayerIdSite'] # print "DEBUG: getRingProfitGraph" @@ -286,6 +288,16 @@ class GuiGraphViewer (threading.Thread): gametest = "and gt.category IS NULL" tmp = tmp.replace("", gametest) + q = [] + for n in currencies: + if currencies[n]: + q.append(n) + currencytest = str(tuple(q)) + currencytest = currencytest.replace(",)",")") + currencytest = currencytest.replace("u'","'") + currencytest = "AND gt.currency in %s" % currencytest + tmp = tmp.replace("", currencytest) + lims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'fl'] potlims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'pl'] nolims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'nl'] diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index 1fb67d24..6e4d3193 100644 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -83,6 +83,7 @@ class GuiSessionViewer (threading.Thread): filters_display = { "Heroes" : True, "Sites" : True, "Games" : True, + "Currencies": True, "Limits" : True, "LimitSep" : True, "LimitType" : True, @@ -178,6 +179,7 @@ class GuiSessionViewer (threading.Thread): heroes = self.filters.getHeroes() siteids = self.filters.getSiteIds() games = self.filters.getGames() + currencies = self.filters.getCurrencies() limits = self.filters.getLimits() seats = self.filters.getSeats() sitenos = [] @@ -203,6 +205,9 @@ class GuiSessionViewer (threading.Thread): if not games: print _("No games found") return + if not currencies: + print _("No currencies found") + return if not playerids: print _("No player ids found") return @@ -210,12 +215,12 @@ class GuiSessionViewer (threading.Thread): print _("No limits found") return - self.createStatsPane(vbox, playerids, sitenos, games, limits, seats) + self.createStatsPane(vbox, playerids, sitenos, games, currencies, limits, seats) - def createStatsPane(self, vbox, playerids, sitenos, games, limits, seats): + def createStatsPane(self, vbox, playerids, sitenos, games, currencies, limits, seats): starttime = time() - (results, quotes) = self.generateDatasets(playerids, sitenos, games, limits, seats) + (results, quotes) = self.generateDatasets(playerids, sitenos, games, currencies, limits, seats) if DEBUG: for x in quotes: @@ -243,7 +248,7 @@ class GuiSessionViewer (threading.Thread): print _("Stats page displayed in %4.2f seconds") % (time() - starttime) #end def fillStatsFrame(self, vbox): - def generateDatasets(self, playerids, sitenos, games, limits, seats): + def generateDatasets(self, playerids, sitenos, games, currencies, limits, seats): if (DEBUG): print "DEBUG: Starting generateDatasets" THRESHOLD = 1800 # Min # of secs between consecutive hands before being considered a new session PADDING = 5 # Additional time in minutes to add to a session, session startup, shutdown etc @@ -270,6 +275,16 @@ class GuiSessionViewer (threading.Thread): gametest = "AND gt.category IS NULL" q = q.replace("", gametest) + l = [] + for n in currencies: + if currencies[n]: + l.append(n) + currencytest = str(tuple(l)) + currencytest = currencytest.replace(",)",")") + currencytest = currencytest.replace("u'","'") + currencytest = "AND gt.currency in %s" % currencytest + q = q.replace("", currencytest) + lims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'fl'] potlims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'pl'] nolims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'nl'] diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 0dc7b695..948d6827 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -90,6 +90,8 @@ class Sql: self.query['getGames'] = """SELECT DISTINCT category from Gametypes""" + self.query['getCurrencies'] = """SELECT DISTINCT currency from Gametypes ORDER BY currency""" + self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC""" self.query['getTourneyTypesIds'] = "SELECT id FROM TourneyTypes" @@ -3811,6 +3813,7 @@ class Sql: AND h.startTime < '' + AND hp.tourneysPlayersId IS NULL GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit ORDER BY h.startTime""" @@ -3827,6 +3830,7 @@ class Sql: AND h.startTime < '' + AND hp.tourneysPlayersId IS NULL GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit ORDER BY h.startTime""" @@ -3873,6 +3877,7 @@ class Sql: + ORDER by time""" elif db_server == 'postgresql': self.query['sessionStats'] = """ @@ -3888,6 +3893,7 @@ class Sql: + ORDER by time""" elif db_server == 'sqlite': self.query['sessionStats'] = """ @@ -3903,6 +3909,7 @@ class Sql: + ORDER by time""" -- 2.11.4.GIT