From ec62b1911d00992f2bf6969466734dad2f3de290 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 15 Dec 2010 14:27:50 +0800 Subject: [PATCH] SessionViewer: Fix total profit for single session Bound to be lots more bugs, but the total profit for a single session is now being calculated correctly. --- pyfpdb/GuiSessionViewer.py | 45 ++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index 6f0fd269..e559914a 100644 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -265,8 +265,9 @@ Thankyou #end def fillStatsFrame(self, vbox): def generateDatasets(self, playerids, sitenos, limits, seats): - THRESHOLD = 1800 # Minimum number of seconds between consecutive hands before being considered a new session - PADDING = 5 # Additional time in minutes to add to a session, session startup, shutdown etc (FiXME: user configurable) + 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 # Get a list of all handids and their timestampts #FIXME: Query still need to filter on blind levels @@ -288,6 +289,9 @@ Thankyou times = map(lambda x:long(x[0]), hands) handids = map(lambda x:int(x[1]), hands) winnings = map(lambda x:float(x[4]), hands) + #print "DEBUG: times : %s" % times + #print "DEBUG: handids : %s" % handids + #print "DEBUG: winnings: %s" % winnings #print "DEBUG: len(times) %s" %(len(times)) diffs = diff(times) # This array is the difference in starttime between consecutive hands diffs2 = append(diffs,THRESHOLD + 1) # Append an additional session to the end of the diffs, so the next line @@ -318,6 +322,7 @@ Thankyou cum_sum = cum_sum/100 sid = 1 # Take all results and format them into a list for feeding into gui model. + #print "DEBUG: range(len(index[0]): %s" % range(len(index[0])) for i in range(len(index[0])): hds = index[0][i] - first_idx + 1 # Number of hands in session if hds > 0: @@ -328,19 +333,21 @@ Thankyou minutesplayed = 1 minutesplayed = minutesplayed + PADDING hph = hds*60/minutesplayed # Hands per hour - won = sum(winnings[first_idx:index[0][i]])/100.0 - hwm = max(cum_sum[first_idx:index[0][i]]) - lwm = min(cum_sum[first_idx:index[0][i]]) + end_idx = first_idx+hds + won = sum(winnings[first_idx:end_idx])/100.0 + #print "DEBUG: winnings[%s:%s]: %s" % (first_idx, end_idx, winnings[first_idx:end_idx]) + hwm = max(cum_sum[first_idx:end_idx]) + lwm = min(cum_sum[first_idx:end_idx]) open = (sum(winnings[:first_idx]))/100 - close = (sum(winnings[:index[0][i]]))/100 - #print "DEBUG: range: (%s, %s) - (min, max): (%s, %s) - (open,close): (%s, %s)" %(first_idx, index[0][i], lwm, hwm, open, close) + close = (sum(winnings[:end_idx]))/100 + print "DEBUG: range: (%s, %s) - (min, max): (%s, %s) - (open,close): (%s, %s)" %(first_idx, index[0][i], lwm, hwm, open, close) results.append([sid, hds, stime, etime, hph, won]) opens.append(open) closes.append(close) highs.append(hwm) lows.append(lwm) - #print "DEBUG: Hands in session %4s: %4s Start: %s End: %s HPH: %s Profit: %s" %(sid, hds, stime, etime, hph, won) + print "DEBUG: Hands in session %4s: %4s Start: %s End: %s HPH: %s Profit: %s" %(sid, hds, stime, etime, hph, won) total = total + (index[0][i] - first_idx) first_idx = index[0][i] + 1 sid = sid+1 @@ -374,17 +381,17 @@ Thankyou def generateGraph(self, opens, closes, highs, lows): self.clearGraphData() -# 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]) + 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)