Carbon Poker offers a 5 card stud game that wasn't listed here. It's not available...
[fpdb-dooglus.git] / pyfpdb / TestSummaryImport.py
blobd2b0afe129eecad075ff9cb620f03a22e32be344
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright 2010-2011, Carl Gherardi
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ########################################################################
21 import sys
22 import os
23 import codecs
24 import pprint
25 import Configuration
26 import Database
27 import SQL
28 from GuiTourneyImport import SummaryImporter
31 class FpdbError:
32 def __init__(self, sitename):
33 self.site = sitename
34 self.errorcount = 0
35 self.histogram = {}
36 self.statcount = {}
38 def error_report(self, filename, hand, stat, ghash, testhash, player):
39 print "Regression Test Error:"
40 print "\tFile: %s" % filename
41 print "\tStat: %s" % stat
42 print "\tPlayer: %s" % player
43 if filename in self.histogram:
44 self.histogram[filename] += 1
45 else:
46 self.histogram[filename] = 1
48 if stat in self.statcount:
49 self.statcount[stat] += 1
50 else:
51 self.statcount[stat] = 1
52 self.errorcount += 1
54 def print_histogram(self):
55 print "%s:" % self.site
56 for f in self.histogram:
57 idx = f.find('regression')
58 print "(%3d) : %s" %(self.histogram[f], f[idx:])
60 def compare(leaf, importer, errors, site):
61 filename = leaf
62 #print "DEBUG: fileanme: %s" % filename
64 if filename.endswith('.txt'):
65 # test if there is a .hp version of the file
66 importer.addImportFileOrDir(filename, site = site)
67 (stored, errs) = importer.runImport()
69 # if os.path.isfile(filename + '.hp') and errs < 1:
70 # # Compare them
71 # hashfilename = filename + '.hp'
73 # in_fh = codecs.open(hashfilename, 'r', 'utf8')
74 # whole_file = in_fh.read()
75 # in_fh.close()
77 # testhash = eval(whole_file)
79 # hhc = importer.getCachedHHC()
80 # handlist = hhc.getProcessedHands()
81 # #We _really_ only want to deal with a single hand here.
82 # for hand in handlist:
83 # ghash = hand.stats.getHandsPlayers()
84 # for p in ghash:
85 # #print "DEBUG: player: '%s'" % p
86 # pstat = ghash[p]
87 # teststat = testhash[p]
89 # for stat in pstat:
90 # #print "pstat[%s][%s]: %s == %s" % (p, stat, pstat[stat], teststat[stat])
91 # try:
92 # if pstat[stat] == teststat[stat]:
93 # # The stats match - continue
94 # pass
95 # else:
96 # # Stats don't match - Doh!
97 # errors.error_report(filename, hand, stat, ghash, testhash, p)
98 # except KeyError, e:
99 # errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p)
100 if errs > 0:
101 errors.error_report(filename, False, "Parse", False, False, False)
103 importer.clearFileList()
107 def walk_testfiles(dir, function, importer, errors, site):
108 """Walks a directory, and executes a callback on each file """
109 dir = os.path.abspath(dir)
110 for file in [file for file in os.listdir(dir) if not file in [".",".."]]:
111 nfile = os.path.join(dir,file)
112 if os.path.isdir(nfile):
113 walk_testfiles(nfile, compare, importer, errors, site)
114 else:
115 print "***********************************"
116 compare(nfile, importer, errors, site)
117 print "***********************************"
119 def main(argv=None):
120 if argv is None:
121 argv = sys.argv[1:]
123 config = Configuration.Config(file = "HUD_config.test.xml")
124 db = Database.Database(config)
125 sql = SQL.Sql(db_server = 'sqlite')
126 db.recreate_tables()
128 importer = SummaryImporter(config, sql, None)
130 PokerStarsErrors = FpdbError('PokerStars')
131 FTPErrors = FpdbError('Full Tilt Poker')
132 #PartyPokerErrors = FpdbError('Party Poker')
133 #BetfairErrors = FpdbError('Betfair')
134 #OnGameErrors = FpdbError('OnGame')
135 #AbsoluteErrors = FpdbError('Absolute Poker')
136 #UltimateBetErrors = FpdbError('Ultimate Bet')
137 #EverleafErrors = FpdbError('Everleaf Poker')
138 #CarbonErrors = FpdbError('Carbon')
139 #PKRErrors = FpdbError('PKR')
140 #iPokerErrors = FpdbError('iPoker')
141 WinamaxErrors = FpdbError('Winamax')
143 ErrorsList = [
144 PokerStarsErrors, FTPErrors, WinamaxErrors,
145 #PartyPokerErrors,
146 #BetfairErrors, OnGameErrors, AbsoluteErrors,
147 #EverleafErrors, CarbonErrors, PKRErrors,
148 #iPokerErrors, UltimateBetErrors,
151 sites = {
152 'PokerStars' : True,
153 'Full Tilt Poker' : True,
154 #'PartyPoker' : True,
155 #'Betfair' : True,
156 #'OnGame' : True,
157 #'Absolute' : True,
158 #'UltimateBet' : True,
159 #'Everleaf' : True,
160 #'Carbon' : True,
161 #'PKR' : False,
162 #'iPoker' : True,
163 'Winamax' : True,
166 if sites['PokerStars'] == True:
167 walk_testfiles("regression-test-files/summaries/Stars/", compare, importer, PokerStarsErrors, "PokerStars")
168 if sites['Full Tilt Poker'] == True:
169 walk_testfiles("regression-test-files/summaries/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
170 # walk_testfiles("regression-test-files/tour/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
171 #if sites['PartyPoker'] == True:
172 # walk_testfiles("regression-test-files/cash/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
173 # walk_testfiles("regression-test-files/tour/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
174 #if sites['Betfair'] == True:
175 # walk_testfiles("regression-test-files/cash/Betfair/", compare, importer, BetfairErrors, "Betfair")
176 #if sites['OnGame'] == True:
177 # walk_testfiles("regression-test-files/cash/OnGame/", compare, importer, OnGameErrors, "OnGame")
178 #if sites['Absolute'] == True:
179 # walk_testfiles("regression-test-files/cash/Absolute/", compare, importer, AbsoluteErrors, "Absolute")
180 #if sites['UltimateBet'] == True:
181 # walk_testfiles("regression-test-files/cash/UltimateBet/", compare, importer, UltimateBetErrors, "Absolute")
182 #if sites['Everleaf'] == True:
183 # walk_testfiles("regression-test-files/cash/Everleaf/", compare, importer, EverleafErrors, "Everleaf")
184 #if sites['Carbon'] == True:
185 # walk_testfiles("regression-test-files/cash/Carbon/", compare, importer, CarbonErrors, "Carbon")
186 #if sites['PKR'] == True:
187 # walk_testfiles("regression-test-files/cash/PKR/", compare, importer, PKRErrors, "PKR")
188 #if sites['iPoker'] == True:
189 # walk_testfiles("regression-test-files/cash/iPoker/", compare, importer, iPokerErrors, "iPoker")
190 if sites['Winamax'] == True:
191 walk_testfiles("regression-test-files/summaries/Winamax/", compare, importer, WinamaxErrors, "Winamax")
193 totalerrors = 0
195 for i, site in enumerate(ErrorsList):
196 totalerrors += ErrorsList[i].errorcount
198 print "---------------------"
199 print "Total Errors: %d" % totalerrors
200 print "---------------------"
201 for i, site in enumerate(ErrorsList):
202 ErrorsList[i].print_histogram()
204 # Merge the dicts of stats from the various error objects
205 statdict = {}
206 for i, site in enumerate(ErrorsList):
207 tmp = ErrorsList[i].statcount
208 for stat in tmp:
209 if stat in statdict:
210 statdict[stat] += tmp[stat]
211 else:
212 statdict[stat] = tmp[stat]
214 print "\n"
215 print "---------------------"
216 print "Errors by stat:"
217 print "---------------------"
218 #for stat in statdict:
219 # print "(%3d) : %s" %(statdict[stat], stat)
221 sortedstats = sorted([(value,key) for (key,value) in statdict.items()])
222 for num, stat in sortedstats:
223 print "(%3d) : %s" %(num, stat)
226 if __name__ == '__main__':
227 sys.exit(main())