2010-08-30 17:24:28 +02:00
|
|
|
#!/usr/bin/env python
|
2010-08-23 07:28:30 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-08-30 17:24:28 +02:00
|
|
|
#
|
|
|
|
# Copyright 2010, Carl Gherardi
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
########################################################################
|
|
|
|
|
2010-08-19 12:30:12 +02:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import codecs
|
|
|
|
import pprint
|
|
|
|
import PokerStarsToFpdb
|
|
|
|
from Hand import *
|
|
|
|
import Configuration
|
|
|
|
import Database
|
|
|
|
import SQL
|
|
|
|
import fpdb_import
|
|
|
|
|
|
|
|
|
2010-08-24 05:09:13 +02:00
|
|
|
class FpdbError:
|
2010-08-28 10:43:05 +02:00
|
|
|
def __init__(self, sitename):
|
|
|
|
self.site = sitename
|
2010-08-24 05:09:13 +02:00
|
|
|
self.errorcount = 0
|
2010-08-24 05:55:30 +02:00
|
|
|
self.histogram = {}
|
2010-08-24 05:09:13 +02:00
|
|
|
|
|
|
|
def error_report(self, filename, hand, stat, ghash, testhash, player):
|
|
|
|
print "Regression Test Error:"
|
|
|
|
print "\tFile: %s" % filename
|
|
|
|
print "\tStat: %s" % stat
|
|
|
|
print "\tPlayer: %s" % player
|
2010-08-24 05:55:30 +02:00
|
|
|
if filename in self.histogram:
|
|
|
|
self.histogram[filename] += 1
|
|
|
|
else:
|
|
|
|
self.histogram[filename] = 1
|
2010-08-24 05:09:13 +02:00
|
|
|
self.errorcount += 1
|
|
|
|
|
2010-08-24 05:55:30 +02:00
|
|
|
def print_histogram(self):
|
2010-08-28 10:43:05 +02:00
|
|
|
print "%s:" % self.site
|
2010-08-24 05:55:30 +02:00
|
|
|
for f in self.histogram:
|
|
|
|
idx = f.find('regression')
|
|
|
|
print "(%3d) : %s" %(self.histogram[f], f[idx:])
|
|
|
|
|
2010-08-28 11:20:50 +02:00
|
|
|
def compare(leaf, importer, errors, site):
|
2010-08-19 12:30:12 +02:00
|
|
|
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
|
2010-08-28 11:20:50 +02:00
|
|
|
importer.addBulkImportImportFileOrDir(filename, site=site)
|
2010-08-19 12:30:12 +02:00
|
|
|
(stored, dups, partial, errs, ttime) = importer.runImport()
|
2010-09-02 07:42:40 +02:00
|
|
|
|
|
|
|
if os.path.isfile(filename + '.hp') and errs < 1:
|
2010-08-19 12:30:12 +02:00
|
|
|
# Compare them
|
|
|
|
hashfilename = filename + '.hp'
|
|
|
|
|
|
|
|
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()
|
|
|
|
#We _really_ only want to deal with a single hand here.
|
|
|
|
for hand in handlist:
|
|
|
|
ghash = hand.stats.getHandsPlayers()
|
|
|
|
for p in ghash:
|
2010-08-19 13:11:46 +02:00
|
|
|
#print "DEBUG: player: '%s'" % p
|
2010-08-19 12:30:12 +02:00
|
|
|
pstat = ghash[p]
|
|
|
|
teststat = testhash[p]
|
2010-08-19 13:11:46 +02:00
|
|
|
|
2010-08-19 12:30:12 +02:00
|
|
|
for stat in pstat:
|
2010-08-19 13:11:46 +02:00
|
|
|
#print "pstat[%s][%s]: %s == %s" % (p, stat, pstat[stat], teststat[stat])
|
2010-08-19 12:30:12 +02:00
|
|
|
if pstat[stat] == teststat[stat]:
|
|
|
|
# The stats match - continue
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# Stats don't match - Doh!
|
2010-08-24 05:09:13 +02:00
|
|
|
errors.error_report(filename, hand, stat, ghash, testhash, p)
|
2010-09-02 07:42:40 +02:00
|
|
|
if errs > 0:
|
|
|
|
errors.error_report(filename, False, "Parse", False, False, False)
|
2010-08-19 12:30:12 +02:00
|
|
|
|
|
|
|
importer.clearFileList()
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-28 11:20:50 +02:00
|
|
|
def walk_testfiles(dir, function, importer, errors, site):
|
2010-08-19 12:30:12 +02:00
|
|
|
"""Walks a directory, and executes a callback on each file """
|
|
|
|
dir = os.path.abspath(dir)
|
|
|
|
for file in [file for file in os.listdir(dir) if not file in [".",".."]]:
|
|
|
|
nfile = os.path.join(dir,file)
|
|
|
|
if os.path.isdir(nfile):
|
2010-08-28 11:20:50 +02:00
|
|
|
walk_testfiles(nfile, compare, importer, errors, site)
|
2010-08-19 12:30:12 +02:00
|
|
|
else:
|
2010-08-28 11:20:50 +02:00
|
|
|
compare(nfile, importer, errors, site)
|
2010-08-19 12:30:12 +02:00
|
|
|
|
|
|
|
def main(argv=None):
|
|
|
|
if argv is None:
|
|
|
|
argv = sys.argv[1:]
|
|
|
|
|
|
|
|
config = Configuration.Config(file = "HUD_config.test.xml")
|
|
|
|
db = Database.Database(config)
|
|
|
|
sql = SQL.Sql(db_server = 'sqlite')
|
|
|
|
settings = {}
|
|
|
|
settings.update(config.get_db_parameters())
|
|
|
|
settings.update(config.get_import_parameters())
|
|
|
|
settings.update(config.get_default_paths())
|
|
|
|
db.recreate_tables()
|
|
|
|
importer = fpdb_import.Importer(False, settings, config)
|
|
|
|
importer.setDropIndexes("don't drop")
|
|
|
|
importer.setFailOnError(True)
|
|
|
|
importer.setThreads(-1)
|
|
|
|
importer.setCallHud(False)
|
|
|
|
importer.setFakeCacheHHC(True)
|
2010-08-24 05:09:13 +02:00
|
|
|
|
2010-08-28 10:43:05 +02:00
|
|
|
PokerStarsErrors = FpdbError('PokerStars')
|
|
|
|
FTPErrors = FpdbError('Full Tilt Poker')
|
|
|
|
PartyPokerErrors = FpdbError('Party Poker')
|
|
|
|
BetfairErrors = FpdbError('Betfair')
|
2010-09-02 07:52:54 +02:00
|
|
|
OnGameErrors = FpdbError('Betfair')
|
2010-08-19 12:30:12 +02:00
|
|
|
|
2010-08-28 11:20:50 +02:00
|
|
|
walk_testfiles("regression-test-files/cash/Stars/", compare, importer, PokerStarsErrors, "PokerStars")
|
2010-09-02 07:52:54 +02:00
|
|
|
walk_testfiles("regression-test-files/tour/Stars/", compare, importer, PokerStarsErrors, "PokerStars")
|
2010-08-28 11:20:50 +02:00
|
|
|
walk_testfiles("regression-test-files/cash/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
|
2010-09-02 07:52:54 +02:00
|
|
|
walk_testfiles("regression-test-files/tour/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
|
2010-08-28 11:20:50 +02:00
|
|
|
#walk_testfiles("regression-test-files/cash/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
|
2010-09-02 07:52:54 +02:00
|
|
|
walk_testfiles("regression-test-files/tour/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
|
2010-08-28 11:20:50 +02:00
|
|
|
walk_testfiles("regression-test-files/cash/Betfair/", compare, importer, BetfairErrors, "Betfair")
|
2010-09-02 07:52:54 +02:00
|
|
|
walk_testfiles("regression-test-files/cash/OnGame/", compare, importer, OnGameErrors, "OnGame")
|
2010-08-28 10:43:05 +02:00
|
|
|
|
|
|
|
totalerrors = PokerStarsErrors.errorcount + FTPErrors.errorcount + PartyPokerErrors.errorcount + BetfairErrors.errorcount
|
2010-08-24 05:09:13 +02:00
|
|
|
|
|
|
|
print "---------------------"
|
2010-08-28 10:43:05 +02:00
|
|
|
print "Total Errors: %d" % totalerrors
|
2010-08-24 05:09:13 +02:00
|
|
|
print "---------------------"
|
2010-08-28 10:43:05 +02:00
|
|
|
PokerStarsErrors.print_histogram()
|
|
|
|
FTPErrors.print_histogram()
|
|
|
|
PartyPokerErrors.print_histogram()
|
|
|
|
BetfairErrors.print_histogram()
|
2010-08-19 12:30:12 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|
|
|
|
|