Update to Session viewer
Fix a couple of crashers - Make sure last session in list is displayed correctly - Actually calculate hands/hour (Thanks Socratic) - Make graph display the correct number of sessions
This commit is contained in:
parent
5aadf643be
commit
c0ebc4b7cf
|
@ -184,7 +184,7 @@ class GuiSessionViewer (threading.Thread):
|
||||||
sitenos.append(siteids[site])
|
sitenos.append(siteids[site])
|
||||||
_q = self.sql.query['getPlayerId']
|
_q = self.sql.query['getPlayerId']
|
||||||
_name = Charset.to_utf8(heroes[site])
|
_name = Charset.to_utf8(heroes[site])
|
||||||
print 'DEBUG(_name) :: %s' % _name
|
#print 'DEBUG(_name) :: %s' % _name
|
||||||
self.cursor.execute(_q, (_name,)) # arg = tuple
|
self.cursor.execute(_q, (_name,)) # arg = tuple
|
||||||
result = self.db.cursor.fetchall()
|
result = self.db.cursor.fetchall()
|
||||||
if len(result) == 1:
|
if len(result) == 1:
|
||||||
|
@ -262,13 +262,20 @@ class GuiSessionViewer (threading.Thread):
|
||||||
times = map(lambda x:long(x[0]), hands)
|
times = map(lambda x:long(x[0]), hands)
|
||||||
handids = map(lambda x:int(x[1]), hands)
|
handids = map(lambda x:int(x[1]), hands)
|
||||||
winnings = map(lambda x:float(x[4]), hands)
|
winnings = map(lambda x:float(x[4]), hands)
|
||||||
print "DEBUG: len(times) %s" %(len(times))
|
#print "DEBUG: len(times) %s" %(len(times))
|
||||||
diffs = diff(times) # This array is the difference in starttime between consecutive hands
|
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
|
index = nonzero(diff(times) > THRESHOLD) # This array represents the indexes into 'times' for start/end times of sessions
|
||||||
# ie. times[index[0][0]] is the end of the first session
|
# ie. times[index[0][0]] is the end of the first session
|
||||||
#print "DEBUG: len(index[0]) %s" %(len(index[0]))
|
#print "DEBUG: len(index[0]) %s" %(len(index[0]))
|
||||||
#print "DEBUG: index %s" %(index)
|
if len(index[0]) > 0:
|
||||||
#print "DEBUG: index[0][0] %s" %(index[0][0])
|
#print "DEBUG: index[0][0] %s" %(index[0][0])
|
||||||
|
#print "DEBUG: index %s" %(index)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
index = [[0]]
|
||||||
|
#print "DEBUG: index %s" %(index)
|
||||||
|
#print "DEBUG: index[0][0] %s" %(index[0][0])
|
||||||
|
pass
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
last_idx = 0
|
last_idx = 0
|
||||||
|
@ -281,27 +288,57 @@ class GuiSessionViewer (threading.Thread):
|
||||||
results = []
|
results = []
|
||||||
cum_sum = cumsum(winnings)
|
cum_sum = cumsum(winnings)
|
||||||
cum_sum = cum_sum/100
|
cum_sum = cum_sum/100
|
||||||
|
sid = 0
|
||||||
# Take all results and format them into a list for feeding into gui model.
|
# Take all results and format them into a list for feeding into gui model.
|
||||||
for i in range(len(index[0])):
|
for i in range(len(index[0])):
|
||||||
sid = i # Session id
|
|
||||||
hds = index[0][i] - last_idx # Number of hands in session
|
hds = index[0][i] - last_idx # Number of hands in session
|
||||||
if hds > 0:
|
if hds > 0:
|
||||||
stime = strftime("%d/%m/%Y %H:%M", localtime(times[last_idx])) # Formatted start 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
|
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
|
minutesplayed = (times[index[0][i]] - times[last_idx])/60
|
||||||
|
if minutesplayed == 0:
|
||||||
|
minutesplayed = 1
|
||||||
|
hph = hds*60/minutesplayed # Hands per hour
|
||||||
won = sum(winnings[last_idx:index[0][i]])/100.0
|
won = sum(winnings[last_idx:index[0][i]])/100.0
|
||||||
hwm = max(cum_sum[last_idx:index[0][i]])
|
hwm = max(cum_sum[last_idx:index[0][i]])
|
||||||
lwm = min(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)
|
open = (sum(winnings[:last_idx]))/100
|
||||||
|
close = (sum(winnings[:index[0][i]]))/100
|
||||||
|
#print "DEBUG: range: (%s, %s) - (min, max): (%s, %s) - (open,close): (%s, %s)" %(last_idx, index[0][i], lwm, hwm, open, close)
|
||||||
|
|
||||||
results.append([sid, hds, stime, etime, hph, won])
|
results.append([sid, hds, stime, etime, hph, won])
|
||||||
opens.append((sum(winnings[:last_idx]))/100)
|
opens.append(open)
|
||||||
closes.append((sum(winnings[:index[0][i]]))/100)
|
closes.append(close)
|
||||||
highs.append(hwm)
|
highs.append(hwm)
|
||||||
lows.append(lwm)
|
lows.append(lwm)
|
||||||
#print "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] - last_idx)
|
total = total + (index[0][i] - last_idx)
|
||||||
last_idx = index[0][i] + 1
|
last_idx = index[0][i] + 1
|
||||||
|
sid = sid+1
|
||||||
|
else:
|
||||||
|
print "hds <= 0"
|
||||||
|
|
||||||
|
#The last session is between times[last_idx:-1]
|
||||||
|
hds = len(times) - last_idx
|
||||||
|
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][-1]])) # Formatted end time
|
||||||
|
minutesplayed = (times[-1] - times[last_idx])/60
|
||||||
|
if minutesplayed == 0:
|
||||||
|
minutesplayed = 1
|
||||||
|
hph = hds*60/minutesplayed # Hands per hour
|
||||||
|
won = sum(winnings[last_idx:-1])/100.0
|
||||||
|
hwm = max(cum_sum[last_idx:-1])
|
||||||
|
lwm = min(cum_sum[last_idx:-1])
|
||||||
|
open = (sum(winnings[:last_idx]))/100
|
||||||
|
close = (sum(winnings[:-1]))/100
|
||||||
|
#print "DEBUG: range: (%s, %s) - (min, max): (%s, %s) - (open,close): (%s, %s)" %(last_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 "Hands in session %4s: %4s Start: %s End: %s HPH: %s Profit: %s" %(sid, hds, stime, etime, hph, won)
|
||||||
|
|
||||||
return (results, opens, closes, highs, lows)
|
return (results, opens, closes, highs, lows)
|
||||||
|
|
||||||
|
@ -330,11 +367,6 @@ class GuiSessionViewer (threading.Thread):
|
||||||
def generateGraph(self, opens, closes, highs, lows):
|
def generateGraph(self, opens, closes, highs, lows):
|
||||||
self.clearGraphData()
|
self.clearGraphData()
|
||||||
|
|
||||||
#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 "DEBUG:"
|
||||||
# print "highs = %s" % highs
|
# print "highs = %s" % highs
|
||||||
# print "lows = %s" % lows
|
# print "lows = %s" % lows
|
||||||
|
|
Loading…
Reference in New Issue
Block a user