THP: Add support for Hands table

Will search for <filename>.hands in the same manner as it does for .hp files
This commit is contained in:
Worros 2010-12-10 23:59:27 +08:00
parent 702bbb4c71
commit d922984b91

View File

@ -29,6 +29,8 @@ import Database
import SQL import SQL
import fpdb_import import fpdb_import
import Options import Options
import datetime
import pytz
class FpdbError: class FpdbError:
@ -60,18 +62,7 @@ class FpdbError:
idx = f.find('regression') idx = f.find('regression')
print "(%3d) : %s" %(self.histogram[f], f[idx:]) print "(%3d) : %s" %(self.histogram[f], f[idx:])
def compare(leaf, importer, errors, site): def compare_handsplayers_file(filename, importer, errors):
filename = leaf
#print "DEBUG: fileanme: %s" % filename
# Test if this is a hand history file
if filename.endswith('.txt'):
# test if there is a .hp version of the file
importer.addBulkImportImportFileOrDir(filename, site=site)
(stored, dups, partial, errs, ttime) = importer.runImport()
if os.path.isfile(filename + '.hp') and errs < 1:
# Compare them
hashfilename = filename + '.hp' hashfilename = filename + '.hp'
in_fh = codecs.open(hashfilename, 'r', 'utf8') in_fh = codecs.open(hashfilename, 'r', 'utf8')
@ -101,8 +92,56 @@ def compare(leaf, importer, errors, site):
errors.error_report(filename, hand, stat, ghash, testhash, p) errors.error_report(filename, hand, stat, ghash, testhash, p)
except KeyError, e: except KeyError, e:
errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p) errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p)
def compare_hands_file(filename, importer, errors):
hashfilename = filename + '.hands'
in_fh = codecs.open(hashfilename, 'r', 'utf8')
whole_file = in_fh.read()
in_fh.close()
testhash = eval(whole_file)
hhc = importer.getCachedHHC()
handlist = hhc.getProcessedHands()
for hand in handlist:
ghash = hand.stats.getHands()
for datum in ghash:
#print "DEBUG: hand: '%s'" % datum
try:
if ghash[datum] == testhash[datum]:
# The stats match - continue
pass
else:
# Stats don't match.
if datum == "gametypeId":
# Not an error. gametypeIds are dependent on the order added to the db.
#print "DEBUG: Skipping mismatched gamtypeId"
pass
else:
errors.error_report(filename, hand, datum, ghash, testhash, None)
except KeyError, e:
errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p)
def compare(leaf, importer, errors, site):
filename = leaf
#print "DEBUG: fileanme: %s" % filename
# Test if this is a hand history file
if filename.endswith('.txt'):
# test if there is a .hp version of the file
importer.addBulkImportImportFileOrDir(filename, site=site)
(stored, dups, partial, errs, ttime) = importer.runImport()
if errs > 0: if errs > 0:
errors.error_report(filename, False, "Parse", False, False, False) errors.error_report(filename, False, "Parse", False, False, False)
else:
if os.path.isfile(filename + '.hp'):
compare_handsplayers_file(filename, importer, errors)
if os.path.isfile(filename + '.hands'):
compare_hands_file(filename, importer, errors)
importer.clearFileList() importer.clearFileList()