From 397f65478986cdb1c9ba551526d93fd57598334e Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 22 Oct 2009 14:09:36 +0800 Subject: [PATCH 1/7] GuiSession viewer update. Still broken, got the math right in preparation for candlestick graph --- pyfpdb/GuiSessionViewer.py | 74 ++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index 96586263..76ad682b 100755 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -23,7 +23,8 @@ import gtk import os from time import time, strftime, localtime try: - from numpy import diff, nonzero, sum + from numpy import diff, nonzero, sum, cumsum, max, mina + import matplotlib.finance # from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \ # DayLocator, MONDAY, timezone @@ -142,29 +143,6 @@ class GuiSessionViewer (threading.Thread): """returns the vbox of this thread""" return self.main_hbox - def generateGraph(self): - fig = figure() - fig.subplots_adjust(bottom=0.2) - ax = fig.add_subplot(111) - ax.xaxis.set_major_locator(mondays) - ax.xaxis.set_minor_locator(alldays) - ax.xaxis.set_major_formatter(weekFormatter) - #ax.xaxis.set_minor_formatter(dayFormatter) - #plot_day_summary(ax, quotes, ticksize=3) -# candlestick(ax, quotes, width=0.6) -# candlestick2(ax, opens, closes, highs, lows, width=4, colorup='k', colordown='r', alpha=0.75) -# Represent the open, close as a bar line and high low range as a vertical line. -# ax : an Axes instance to plot to -# width : the bar width in points -# colorup : the color of the lines where close >= open -# colordown : the color of the lines where close < open -# alpha : bar transparency -# return value is lineCollection, barCollection - ax.xaxis_date() - ax.autoscale_view() - setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right') - - show() def refreshStats(self, widget, data): @@ -242,6 +220,31 @@ class GuiSessionViewer (threading.Thread): print "Stats page displayed in %4.2f seconds" % (time() - starttime) #end def fillStatsFrame(self, vbox): + def generateGraph(self, vbox, data): + fig = figure() + fig.subplots_adjust(bottom=0.2) + ax = fig.add_subplot(111) + ax.xaxis.set_major_locator(mondays) + ax.xaxis.set_minor_locator(alldays) + ax.xaxis.set_major_formatter(weekFormatter) + #ax.xaxis.set_minor_formatter(dayFormatter) + #plot_day_summary(ax, quotes, ticksize=3) +# candlestick(ax, quotes, width=0.6) +# candlestick2(ax, opens, closes, highs, lows, width=4, colorup='k', colordown='r', alpha=0.75) +# Represent the open, close as a bar line and high low range as a vertical line. +# ax : an Axes instance to plot to +# width : the bar width in points +# colorup : the color of the lines where close >= open +# colordown : the color of the lines where close < open +# alpha : bar transparency +# return value is lineCollection, barCollection + ax.xaxis_date() + ax.autoscale_view() + setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right') + + show() + + def addTable(self, vbox, query, flags, playerids, sitenos, limits, seats): row = 0 sqlrow = 0 @@ -302,7 +305,7 @@ order by time # Take that list and create an array of the time between hands times = map(lambda x:long(x[0]), hands) handids = map(lambda x:int(x[1]), hands) - winnings = map(lambda x:int(x[4]), hands) + winnings = map(lambda x:float(x[4]), hands) print "DEBUG: len(times) %s" %(len(times)) diffs = diff(times) # This array is the difference in starttime between consecutive hands index = nonzero(diff(times) > THRESHOLD) # This array represents the indexes into 'times' for start/end times of sessions @@ -315,7 +318,13 @@ order by time last_idx = 0 lowidx = 0 uppidx = 0 + opens = [] + closes = [] + highs = [] + lows = [] results = [] + cum_sum = cumsum(winnings) + cum_sum = cum_sum/100 # Take all results and format them into a list for feeding into gui model. for i in range(len(index[0])): sid = i # Session id @@ -323,10 +332,16 @@ order by time stime = strftime("%d/%m/%Y %H:%M", localtime(times[last_idx])) # Formatted start time etime = strftime("%d/%m/%Y %H:%M", localtime(times[index[0][i]])) # Formatted end time hph = (times[index[0][i]] - times[last_idx])/60 # Hands per hour - won = sum(winnings[last_idx:index[0][i]]) - print "DEBUG: range: %s - %s" %(last_idx, index[0][i]) + won = sum(winnings[last_idx:index[0][i]])/100.0 + hwm = max(cum_sum[last_idx:index[0][i]]) + lwm = min(cum_sum[last_idx:index[0][i]]) + print "DEBUG: range: (%s, %s) - (min, max): (%s, %s)" %(last_idx, index[0][i], hwm, lwm) results.append([sid, hds, stime, etime, hph, won]) + opens.append((sum(winnings[:last_idx]))/100) + closes.append((sum(winnings[:index[0][i]]))/100) + highs.append(hwm) + lows.append(lwm) print "Hands in session %4s: %4s Start: %s End: %s HPH: %s Profit: %s" %(sid, hds, stime, etime, hph, won) total = total + (index[0][i] - last_idx) last_idx = index[0][i] + 1 @@ -334,6 +349,11 @@ order by time for row in results: iter = self.liststore.append(row) + print "DEBUG: highs = %s" % highs + print "DEBUG: lows = %s" % lows + print "DEBUG: opens = %s" % opens + print "DEBUG: closes = %s" % closes + vbox.show_all() def main(argv=None): From a2309f704c26fbea3d9f2ee11b3aa8fd60401849 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 23 Oct 2009 13:50:06 +0800 Subject: [PATCH 2/7] More GuiSessionViewer updates Getting closer to a decent layout --- pyfpdb/GuiGraphViewer.py | 28 ----- pyfpdb/GuiSessionViewer.py | 229 ++++++++++++++++++++++--------------- pyfpdb/fpdb.py | 2 +- 3 files changed, 135 insertions(+), 124 deletions(-) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index f91c9870..4011ba00 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -97,34 +97,6 @@ class GuiGraphViewer (threading.Thread): self.db.rollback() -################################# -# -# self.db.cursor.execute("""select UNIX_TIMESTAMP(handStart) as time, id from Hands ORDER BY time""") -# THRESHOLD = 1800 -# hands = self.db.cursor.fetchall() -# -# times = map(lambda x:long(x[0]), hands) -# handids = map(lambda x:int(x[1]), hands) -# print "DEBUG: len(times) %s" %(len(times)) -# diffs = diff(times) -# print "DEBUG: len(diffs) %s" %(len(diffs)) -# index = nonzero(diff(times) > THRESHOLD) -# print "DEBUG: len(index[0]) %s" %(len(index[0])) -# print "DEBUG: index %s" %(index) -# print "DEBUG: index[0][0] %s" %(index[0][0]) -# -# total = 0 -# -# last_idx = 0 -# for i in range(len(index[0])): -# print "Hands in session %4s: %4s Start: %s End: %s Total: %s" %(i, index[0][i] - last_idx, strftime("%d/%m/%Y %H:%M", localtime(times[last_idx])), strftime("%d/%m/%Y %H:%M", localtime(times[index[0][i]])), times[index[0][i]] - times[last_idx]) -# total = total + (index[0][i] - last_idx) -# last_idx = index[0][i] + 1 -# -# print "Total: ", total -################################# - - def get_vbox(self): """returns the vbox of this thread""" return self.mainHBox diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index 76ad682b..7bb87dae 100755 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -21,10 +21,17 @@ import pygtk pygtk.require('2.0') import gtk import os +import traceback from time import time, strftime, localtime try: + import matplotlib + matplotlib.use('GTK') + 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.finance import candlestick2 + from numpy import diff, nonzero, sum, cumsum, max, mina - import matplotlib.finance # from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \ # DayLocator, MONDAY, timezone @@ -49,6 +56,11 @@ class GuiSessionViewer (threading.Thread): self.MYSQL_INNODB = 2 self.PGSQL = 3 self.SQLITE = 4 + + self.fig = None + self.canvas = None + self.ax = None + self.graphBox = None # create new db connection to avoid conflicts with other threads self.db = Database.Database(self.conf, sql=self.sql) @@ -182,17 +194,27 @@ class GuiSessionViewer (threading.Thread): print "No limits found" return - self.createStatsTable(vbox, playerids, sitenos, limits, seats) + self.createStatsPane(vbox, playerids, sitenos, limits, seats) - def createStatsTable(self, vbox, playerids, sitenos, limits, seats): + def createStatsPane(self, vbox, playerids, sitenos, limits, seats): starttime = time() - # Display summary table at top of page - # 3rd parameter passes extra flags, currently includes: - # holecards - whether to display card breakdown (True/False) - flags = [False] - self.addTable(vbox, 'playerDetailedStats', flags, playerids, sitenos, limits, seats) + (results, opens, closes, highs, lows) = self.generateDatasets(playerids, sitenos, limits, seats) + print "DEBUG:" + print "highs = %s" % highs + print "lows = %s" % lows + print "opens = %s" % opens + print "closes = %s" % closes + print "len(highs): %s == len(lows): %s" %(len(highs), len(lows)) + print "len(opens): %s == len(closes): %s" %(len(opens), len(closes)) + + + self.graphBox = gtk.VBox(False, 0) + self.graphBox.show() + self.generateGraph(opens[:5], closes[:5], highs[:5], lows[:5]) + + vbox.pack_start(self.graphBox) # Separator sep = gtk.HSeparator() vbox.pack_start(sep, expand=False, padding=3) @@ -212,82 +234,19 @@ class GuiSessionViewer (threading.Thread): vbox1.show() swin.add_with_viewport(vbox1) - # Detailed table - flags = [True] - self.addTable(vbox1, 'playerDetailedStats', flags, playerids, sitenos, limits, seats) + self.addTable(vbox1, results) self.db.rollback() print "Stats page displayed in %4.2f seconds" % (time() - starttime) #end def fillStatsFrame(self, vbox): - def generateGraph(self, vbox, data): - fig = figure() - fig.subplots_adjust(bottom=0.2) - ax = fig.add_subplot(111) - ax.xaxis.set_major_locator(mondays) - ax.xaxis.set_minor_locator(alldays) - ax.xaxis.set_major_formatter(weekFormatter) - #ax.xaxis.set_minor_formatter(dayFormatter) - #plot_day_summary(ax, quotes, ticksize=3) -# candlestick(ax, quotes, width=0.6) -# candlestick2(ax, opens, closes, highs, lows, width=4, colorup='k', colordown='r', alpha=0.75) -# Represent the open, close as a bar line and high low range as a vertical line. -# ax : an Axes instance to plot to -# width : the bar width in points -# colorup : the color of the lines where close >= open -# colordown : the color of the lines where close < open -# alpha : bar transparency -# return value is lineCollection, barCollection - ax.xaxis_date() - ax.autoscale_view() - setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right') - - show() - - - def addTable(self, vbox, query, flags, playerids, sitenos, limits, seats): - row = 0 - sqlrow = 0 - colalias,colshow,colheading,colxalign,colformat = 0,1,2,3,4 - if not flags: holecards = False - else: holecards = flags[0] - - # pre-fetch some constant values: - cols_to_show = [x for x in self.columns if x[colshow]] - - self.liststore = gtk.ListStore(*([str] * len(cols_to_show))) - - view = gtk.TreeView(model=self.liststore) - view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH) - vbox.add(view) - textcell = gtk.CellRendererText() - textcell50 = gtk.CellRendererText() - textcell50.set_property('xalign', 0.5) - numcell = gtk.CellRendererText() - numcell.set_property('xalign', 1.0) - listcols = [] - - # Create header row eg column: ("game", True, "Game", 0.0, "%s") - for col, column in enumerate(cols_to_show): - s = column[colheading] - listcols.append(gtk.TreeViewColumn(s)) - view.append_column(listcols[col]) - if column[colformat] == '%s': - if column[colxalign] == 0.0: - listcols[col].pack_start(textcell, expand=True) - listcols[col].add_attribute(textcell, 'text', col) - else: - listcols[col].pack_start(textcell50, expand=True) - listcols[col].add_attribute(textcell50, 'text', col) - listcols[col].set_expand(True) - else: - listcols[col].pack_start(numcell, expand=True) - listcols[col].add_attribute(numcell, 'text', col) - listcols[col].set_expand(True) - + def generateDatasets(self, playerids, sitenos, limits, seats): # Get a list of all handids and their timestampts # FIXME: Will probably want to be able to filter this list eventually # FIXME: Join on handsplayers for Hero to get other useful stuff like total profit? + + + # Postgres version requires - EXTRACT(epoch from h.handStart) q = """ select UNIX_TIMESTAMP(h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit from HandsPlayers hp @@ -329,30 +288,110 @@ order by time for i in range(len(index[0])): sid = i # Session id hds = index[0][i] - last_idx # Number of hands in session - stime = strftime("%d/%m/%Y %H:%M", localtime(times[last_idx])) # Formatted start time - etime = strftime("%d/%m/%Y %H:%M", localtime(times[index[0][i]])) # Formatted end time - hph = (times[index[0][i]] - times[last_idx])/60 # Hands per hour - won = sum(winnings[last_idx:index[0][i]])/100.0 - hwm = max(cum_sum[last_idx:index[0][i]]) - lwm = min(cum_sum[last_idx:index[0][i]]) - print "DEBUG: range: (%s, %s) - (min, max): (%s, %s)" %(last_idx, index[0][i], hwm, lwm) + if hds > 0: + stime = strftime("%d/%m/%Y %H:%M", localtime(times[last_idx])) # Formatted start time + etime = strftime("%d/%m/%Y %H:%M", localtime(times[index[0][i]])) # Formatted end time + hph = (times[index[0][i]] - times[last_idx])/60 # Hands per hour + won = sum(winnings[last_idx:index[0][i]])/100.0 + hwm = max(cum_sum[last_idx:index[0][i]]) + lwm = min(cum_sum[last_idx:index[0][i]]) + #print "DEBUG: range: (%s, %s) - (min, max): (%s, %s)" %(last_idx, index[0][i], hwm, lwm) - results.append([sid, hds, stime, etime, hph, won]) - opens.append((sum(winnings[:last_idx]))/100) - closes.append((sum(winnings[:index[0][i]]))/100) - highs.append(hwm) - lows.append(lwm) - print "Hands in session %4s: %4s Start: %s End: %s HPH: %s Profit: %s" %(sid, hds, stime, etime, hph, won) - total = total + (index[0][i] - last_idx) - last_idx = index[0][i] + 1 + results.append([sid, hds, stime, etime, hph, won]) + opens.append((sum(winnings[:last_idx]))/100) + closes.append((sum(winnings[:index[0][i]]))/100) + highs.append(hwm) + lows.append(lwm) + #print "Hands in session %4s: %4s Start: %s End: %s HPH: %s Profit: %s" %(sid, hds, stime, etime, hph, won) + total = total + (index[0][i] - last_idx) + last_idx = index[0][i] + 1 + return (results, opens, closes, highs, lows) + + def clearGraphData(self): + + 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] + print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) + raise + + + def generateGraph(self, opens, closes, highs, lows): + self.clearGraphData() + + highs = [7.0999999999999996, -48.200000000000003, -79.400000000000006, -75.549999999999997, -66.700000000000003, -72.549999999999997, -64.799999999999997, -75.150000000000006, -61.350000000000001, -32.049999999999997, -19.899999999999999, -49.5, -172.75, -176.0, -230.56, -243.41] + lows = [-75.0, -84.900000000000006, -104.7, -131.0, -95.650000000000006, -136.65000000000001, -127.7, -113.59999999999999, -158.19999999999999, -66.349999999999994, -72.599999999999994, -171.84999999999999, -203.0, -257.94999999999999, -251.99000000000001, -246.56] + opens = [0.0, -64.349999999999994, -105.55, -79.400000000000006, -78.25, -75.700000000000003, -83.599999999999994, -81.950000000000003, -100.59999999999999, -60.299999999999997, -36.299999999999997, -49.600000000000001, -172.5, -197.55000000000001, -251.59999999999999, -246.93000000000001] + closes = [-64.450000000000003, -83.099999999999994, -79.400000000000006, -78.25, -75.700000000000003, -83.599999999999994, -81.950000000000003, -100.59999999999999, -61.350000000000001, -32.799999999999997, -49.950000000000003, -171.75, -197.55000000000001, -251.59999999999999, -247.84999999999999, -245.87] + + + self.ax = self.fig.add_subplot(111) + + self.ax.set_title("Session candlestick graph") + + #Set axis labels and grid overlay properites + self.ax.set_xlabel("Sessions", fontsize = 12) + self.ax.set_ylabel("$", fontsize = 12) + self.ax.grid(color='g', linestyle=':', linewidth=0.2) + + candlestick2(self.ax, opens, closes, highs, lows, width=0.50, colordown='r', colorup='g', alpha=1.00) + self.graphBox.add(self.canvas) + self.canvas.show() + self.canvas.draw() + + def addTable(self, vbox, results): + row = 0 + sqlrow = 0 + colalias,colshow,colheading,colxalign,colformat = 0,1,2,3,4 + + # pre-fetch some constant values: + cols_to_show = [x for x in self.columns if x[colshow]] + + self.liststore = gtk.ListStore(*([str] * len(cols_to_show))) for row in results: iter = self.liststore.append(row) - print "DEBUG: highs = %s" % highs - print "DEBUG: lows = %s" % lows - print "DEBUG: opens = %s" % opens - print "DEBUG: closes = %s" % closes + view = gtk.TreeView(model=self.liststore) + view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH) + vbox.add(view) + textcell = gtk.CellRendererText() + textcell50 = gtk.CellRendererText() + textcell50.set_property('xalign', 0.5) + numcell = gtk.CellRendererText() + numcell.set_property('xalign', 1.0) + listcols = [] + + # Create header row eg column: ("game", True, "Game", 0.0, "%s") + for col, column in enumerate(cols_to_show): + s = column[colheading] + listcols.append(gtk.TreeViewColumn(s)) + view.append_column(listcols[col]) + if column[colformat] == '%s': + if column[colxalign] == 0.0: + listcols[col].pack_start(textcell, expand=True) + listcols[col].add_attribute(textcell, 'text', col) + else: + listcols[col].pack_start(textcell50, expand=True) + listcols[col].add_attribute(textcell50, 'text', col) + listcols[col].set_expand(True) + else: + listcols[col].pack_start(numcell, expand=True) + listcols[col].add_attribute(numcell, 'text', col) + listcols[col].set_expand(True) vbox.show_all() diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 4f3210f4..d822f760 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -78,7 +78,7 @@ import FpdbSQLQueries import Configuration from Exceptions import * -VERSION = "0.11" +VERSION = "0.12" class fpdb: def tab_clicked(self, widget, tab_name): From 914f930c5b6dfc05bee19797be184d88b497a123 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 23 Oct 2009 15:01:02 +0800 Subject: [PATCH 3/7] GuiSessionViewer update. Getting closer - added player and date tests. Not convinced the data coming back is koshur though - got a $3600 day in the middle of my data --- pyfpdb/GuiSessionViewer.py | 56 +++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index 7bb87dae..140a134e 100755 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -79,17 +79,17 @@ class GuiSessionViewer (threading.Thread): filters_display = { "Heroes" : True, "Sites" : True, "Games" : False, - "Limits" : True, - "LimitSep" : True, - "LimitType" : True, + "Limits" : False, + "LimitSep" : False, + "LimitType" : False, "Type" : True, - "Seats" : True, - "SeatSep" : True, + "Seats" : False, + "SeatSep" : False, "Dates" : True, - "Groups" : True, - "GroupsAll" : True, + "Groups" : False, + "GroupsAll" : False, "Button1" : True, - "Button2" : True + "Button2" : False } self.filters = Filters.Filters(self.db, self.conf, self.sql, display = filters_display) @@ -201,18 +201,11 @@ class GuiSessionViewer (threading.Thread): (results, opens, closes, highs, lows) = self.generateDatasets(playerids, sitenos, limits, seats) - print "DEBUG:" - print "highs = %s" % highs - print "lows = %s" % lows - print "opens = %s" % opens - print "closes = %s" % closes - print "len(highs): %s == len(lows): %s" %(len(highs), len(lows)) - print "len(opens): %s == len(closes): %s" %(len(opens), len(closes)) self.graphBox = gtk.VBox(False, 0) self.graphBox.show() - self.generateGraph(opens[:5], closes[:5], highs[:5], lows[:5]) + self.generateGraph(opens, closes, highs, lows) vbox.pack_start(self.graphBox) # Separator @@ -254,9 +247,17 @@ from HandsPlayers hp inner join Gametypes gt on (gt.Id = h.gameTypeId) inner join Sites s on (s.Id = gt.siteId) inner join Players p on (p.Id = hp.playerId) -where hp.playerId in (2) +where hp.playerId in +and date_format(h.handStart, '%Y-%m-%d') order by time """ + start_date, end_date = self.filters.getDates() + q = q.replace("", " between '" + start_date + "' and '" + end_date + "'") + + nametest = str(tuple(playerids)) + nametest = nametest.replace("L", "") + nametest = nametest.replace(",)",")") + q = q.replace("", nametest) self.db.cursor.execute(q) THRESHOLD = 1800 hands = self.db.cursor.fetchall() @@ -333,11 +334,22 @@ order by time def generateGraph(self, opens, closes, highs, lows): self.clearGraphData() - highs = [7.0999999999999996, -48.200000000000003, -79.400000000000006, -75.549999999999997, -66.700000000000003, -72.549999999999997, -64.799999999999997, -75.150000000000006, -61.350000000000001, -32.049999999999997, -19.899999999999999, -49.5, -172.75, -176.0, -230.56, -243.41] - lows = [-75.0, -84.900000000000006, -104.7, -131.0, -95.650000000000006, -136.65000000000001, -127.7, -113.59999999999999, -158.19999999999999, -66.349999999999994, -72.599999999999994, -171.84999999999999, -203.0, -257.94999999999999, -251.99000000000001, -246.56] - opens = [0.0, -64.349999999999994, -105.55, -79.400000000000006, -78.25, -75.700000000000003, -83.599999999999994, -81.950000000000003, -100.59999999999999, -60.299999999999997, -36.299999999999997, -49.600000000000001, -172.5, -197.55000000000001, -251.59999999999999, -246.93000000000001] - closes = [-64.450000000000003, -83.099999999999994, -79.400000000000006, -78.25, -75.700000000000003, -83.599999999999994, -81.950000000000003, -100.59999999999999, -61.350000000000001, -32.799999999999997, -49.950000000000003, -171.75, -197.55000000000001, -251.59999999999999, -247.84999999999999, -245.87] - + #FIXME: Weird - first data entry is crashing this for me + opens = opens[1:] + closes = closes[1:] + highs = highs[1:] + lows = lows[1:] +# print "DEBUG:" +# print "highs = %s" % highs +# print "lows = %s" % lows +# print "opens = %s" % opens +# print "closes = %s" % closes +# print "len(highs): %s == len(lows): %s" %(len(highs), len(lows)) +# print "len(opens): %s == len(closes): %s" %(len(opens), len(closes)) +# +# for i in range(len(highs)): +# print "DEBUG: (%s, %s, %s, %s)" %(lows[i], opens[i], closes[i], highs[i]) +# print "DEBUG: diffs h/l: %s o/c: %s" %(lows[i] - highs[i], opens[i] - closes[i]) self.ax = self.fig.add_subplot(111) From 11f50765c9ac78f92bbb6e620f07710dbf71d582 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 24 Oct 2009 12:16:26 +0100 Subject: [PATCH 4/7] fix main --- pyfpdb/Stats.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Stats.py b/pyfpdb/Stats.py index 614f48ed..3a08e470 100755 --- a/pyfpdb/Stats.py +++ b/pyfpdb/Stats.py @@ -657,9 +657,9 @@ def ffreq4(stat_dict, player): if __name__== "__main__": c = Configuration.Config() - db_connection = Database.Database(c, 'fpdb', 'holdem') + db_connection = Database.Database(c) h = db_connection.get_last_hand() - stat_dict = db_connection.get_stats_from_hand(h) + stat_dict = db_connection.get_stats_from_hand(h, "ring") for player in stat_dict.keys(): print "player = ", player, do_stat(stat_dict, player = player, stat = 'vpip') From d39a34686ef0ea6ee1098f7d07c495ae3a2bea29 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 24 Oct 2009 12:41:51 +0100 Subject: [PATCH 5/7] tidy up main() output --- pyfpdb/Stats.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyfpdb/Stats.py b/pyfpdb/Stats.py index 3a08e470..d54ccf12 100755 --- a/pyfpdb/Stats.py +++ b/pyfpdb/Stats.py @@ -93,7 +93,7 @@ def do_stat(stat_dict, player = 24, stat = 'vpip'): # functions that return individual stats def totalprofit(stat_dict, player): - """ Total Profit.""" + """ Total Profit.""" if stat_dict[player]['net'] != 0: stat = float(stat_dict[player]['net']) / 100 return (stat, '$%.2f' % stat, 'tp=$%.2f' % stat, 'totalprofit=$%.2f' % stat, str(stat), 'Total Profit') @@ -663,11 +663,9 @@ if __name__== "__main__": for player in stat_dict.keys(): print "player = ", player, do_stat(stat_dict, player = player, stat = 'vpip') - print "player = ", player, do_stat(stat_dict, player = player, stat = 'vpip_0') print "player = ", player, do_stat(stat_dict, player = player, stat = 'pfr') - print "player = ", player, do_stat(stat_dict, player = player, stat = 'pfr_0') print "player = ", player, do_stat(stat_dict, player = player, stat = 'wtsd') - print "player = ", player, do_stat(stat_dict, player = player, stat = 'profit100_0') + print "player = ", player, do_stat(stat_dict, player = player, stat = 'profit100') print "player = ", player, do_stat(stat_dict, player = player, stat = 'saw_f') print "player = ", player, do_stat(stat_dict, player = player, stat = 'n') print "player = ", player, do_stat(stat_dict, player = player, stat = 'fold_f') @@ -675,14 +673,13 @@ if __name__== "__main__": print "player = ", player, do_stat(stat_dict, player = player, stat = 'steal') print "player = ", player, do_stat(stat_dict, player = player, stat = 'f_SB_steal') print "player = ", player, do_stat(stat_dict, player = player, stat = 'f_BB_steal') - print "player = ", player, do_stat(stat_dict, player = player, stat = 'three_B_0') + print "player = ", player, do_stat(stat_dict, player = player, stat = 'three_B') print "player = ", player, do_stat(stat_dict, player = player, stat = 'WMsF') print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq1') print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq2') print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq3') print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq4') print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq_123') - print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq_123_0') print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb1') print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb2') print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb3') @@ -694,13 +691,15 @@ if __name__== "__main__": print "\n" print "\n\nLegal stats:" + print "(add _0 to name to display with 0 decimal places, _1 to display with 1, etc)\n" for attr in dir(): if attr.startswith('__'): continue if attr in ("Configuration", "Database", "GInitiallyUnowned", "gtk", "pygtk", "player", "c", "db_connection", "do_stat", "do_tip", "stat_dict", - "h"): continue + "h", "re", "re_Percent", "re_Places"): continue print "%-14s %s" % (attr, eval("%s.__doc__" % (attr))) # print " " % (attr) + print db_connection.close_connection From b1d65dbadd5ce5a93ca98669773c0d076bb58838 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 24 Oct 2009 20:01:24 +0100 Subject: [PATCH 6/7] default all values in hud_params when not passed into get_stats_from_hand --- pyfpdb/Database.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index bb9739ec..1533c05c 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -427,7 +427,8 @@ class Database: print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) def get_stats_from_hand( self, hand, type # type is "ring" or "tour" - , hud_params = {'aggregate_tour':False, 'aggregate_ring':False, 'hud_style':'A', 'agg_bb_mult':100} + , hud_params = {'aggregate_tour':False, 'aggregate_ring':False, 'hud_style':'A', 'hud_days':30, 'agg_bb_mult':100 + ,'h_aggregate_tour':False, 'h_aggregate_ring':False, 'h_hud_style':'S', 'h_hud_days':30, 'h_agg_bb_mult':100} , hero_id = -1 ): aggregate = hud_params['aggregate_tour'] if type == "tour" else hud_params['aggregate_ring'] From 0b049a128ba73179fdc62e4299528a9b02568742 Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 25 Oct 2009 20:51:46 +0800 Subject: [PATCH 7/7] Make green in PlayerStats darker --- pyfpdb/GuiPlayerStats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index dd3db0be..d82151c9 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -248,7 +248,7 @@ class GuiPlayerStats (threading.Thread): cell.set_property('text', str) cell.set_property('foreground', 'red') else: - cell.set_property('foreground', 'green') + cell.set_property('foreground', 'darkgreen') return