Merge branch 'session' of git://git.assembla.com/fpdboz

This commit is contained in:
Matt Turnbull 2009-01-21 21:16:33 +00:00
commit f048a763c0
3 changed files with 65 additions and 11 deletions

View File

@ -31,8 +31,8 @@ class GuiBulkImport (threading.Thread):
self.importer.addImportDirectory(self.path) self.importer.addImportDirectory(self.path)
self.importer.setCallHud(False) self.importer.setCallHud(False)
starttime = time() starttime = time()
self.importer.runImport() (stored, dups, partial, errs, ttime) = self.importer.runImport()
print "GuiBulkImport.import_dir done in %s" %(time() - starttime) print "GuiBulkImport.import_dir done: Stored: %d Dupllicates: %d Partial: %d Errors: %d in %s seconds - %d/sec" %(stored, dups, partial, errs, ttime, (stored/ttime))
def load_clicked(self, widget, data=None): def load_clicked(self, widget, data=None):
self.inputFile=self.chooser.get_filename() self.inputFile=self.chooser.get_filename()

View File

@ -20,7 +20,7 @@ import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import os import os
from time import time from time import *
#import pokereval #import pokereval
try: try:
@ -366,3 +366,31 @@ class GuiGraphViewer (threading.Thread):
self.leftPanelBox.show() self.leftPanelBox.show()
self.graphBox.show() self.graphBox.show()
#################################
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
#################################

View File

@ -113,10 +113,21 @@ class Importer:
#Run full import on filelist #Run full import on filelist
def runImport(self): def runImport(self):
fpdb_simple.prepareBulkImport(self.fdb) fpdb_simple.prepareBulkImport(self.fdb)
totstored = 0
totdups = 0
totpartial = 0
toterrors = 0
tottime = 0
for file in self.filelist: for file in self.filelist:
self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) (stored, duplicates, partial, errors, ttime) = self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
totstored += stored
totdups += duplicates
totpartial += partial
toterrors += errors
tottime += ttime
fpdb_simple.afterBulkImport(self.fdb) fpdb_simple.afterBulkImport(self.fdb)
fpdb_simple.analyzeDB(self.fdb) fpdb_simple.analyzeDB(self.fdb)
return (totstored, totdups, totpartial, toterrors, tottime)
#Run import on updated files, then store latest update time. #Run import on updated files, then store latest update time.
def runUpdated(self): def runUpdated(self):
@ -143,10 +154,11 @@ class Importer:
# This is now an internal function that should not be called directly. # This is now an internal function that should not be called directly.
def import_file_dict(self, file, site, filter): def import_file_dict(self, file, site, filter):
if(filter == "passthrough"): if(filter == "passthrough"):
self.import_fpdb_file(file, site) (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(file, site)
else: else:
#Load filter, and run filtered file though main importer #Load filter, and run filtered file though main importer
self.import_fpdb_file(file, site) (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(file, site)
return (stored, duplicates, partial, errors, ttime)
def import_fpdb_file(self, file, site): def import_fpdb_file(self, file, site):
@ -170,7 +182,7 @@ class Importer:
firstline = self.lines[0] firstline = self.lines[0]
except: except:
# print "import_fpdb_file", file, site, self.lines, "\n" # print "import_fpdb_file", file, site, self.lines, "\n"
return return (0,0,0,1,0)
if firstline.find("Tournament Summary")!=-1: if firstline.find("Tournament Summary")!=-1:
print "TODO: implement importing tournament summaries" print "TODO: implement importing tournament summaries"
@ -202,7 +214,12 @@ class Importer:
if (hand[i].endswith(" has been canceled")): #this is their typo. this is a typo, right? if (hand[i].endswith(" has been canceled")): #this is their typo. this is a typo, right?
cancelled=True cancelled=True
seat1=hand[i].find("Seat ") #todo: make this recover by skipping this line #FTP generates lines looking like:
#Seat 1: IOS Seat 2: kashman59 (big blind) showed [8c 9d] and won ($3.25) with a pair of Eights
#ie. Seat X multiple times on the same line in the summary section, when a new player sits down in the
#middle of the hand.
#TODO: Deal with this properly, either fix the file or make the parsing code work with this line.
seat1=hand[i].find("Seat ")
if (seat1!=-1): if (seat1!=-1):
if (hand[i].find("Seat ", seat1+3)!=-1): if (hand[i].find("Seat ", seat1+3)!=-1):
damaged=True damaged=True
@ -216,6 +233,14 @@ class Importer:
partial+=1 partial+=1
elif (cancelled or damaged): elif (cancelled or damaged):
partial+=1 partial+=1
if damaged:
print """
DEBUG: Partial hand triggered by a line containing 'Seat X:' twice. This is a
bug in the FTP software when a player sits down in the middle of a hand.
Adding a newline after the player name will fix the issue
"""
print "File: %s" %(file)
print "Line: %s" %(startpos)
else: #normal processing else: #normal processing
isTourney=fpdb_simple.isTourney(hand[0]) isTourney=fpdb_simple.isTourney(hand[0])
if not isTourney: if not isTourney:
@ -263,7 +288,8 @@ class Importer:
print "Total stored:", stored, "duplicates:", duplicates, "partial/damaged:", partial, "errors:", errors, " time:", (time() - starttime) print "Total stored:", stored, "duplicates:", duplicates, "partial/damaged:", partial, "errors:", errors, " time:", (time() - starttime)
sys.exit(0) sys.exit(0)
startpos=endpos startpos=endpos
print "Total stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors, " time:", (time() - starttime) ttime = time() - starttime
print "Total stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors, " time:", ttime
if stored==0: if stored==0:
if duplicates>0: if duplicates>0:
@ -277,7 +303,7 @@ class Importer:
#todo: this will cause return of an unstored hand number if the last hand was error or partial #todo: this will cause return of an unstored hand number if the last hand was error or partial
self.fdb.db.commit() self.fdb.db.commit()
self.handsId=handsId self.handsId=handsId
return handsId return (stored, duplicates, partial, errors, ttime)
def parseTourneyHistory(self): def parseTourneyHistory(self):
print "Tourney history parser stub" print "Tourney history parser stub"