2 # -*- coding: utf-8 -*-
4 # Copyright 2010-2011, Carl Gherardi
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 ########################################################################
28 from GuiTourneyImport
import SummaryImporter
32 def __init__(self
, sitename
):
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
46 self
.histogram
[filename
] = 1
48 if stat
in self
.statcount
:
49 self
.statcount
[stat
] += 1
51 self
.statcount
[stat
] = 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
):
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:
71 # hashfilename = filename + '.hp'
73 # in_fh = codecs.open(hashfilename, 'r', 'utf8')
74 # whole_file = in_fh.read()
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()
85 # #print "DEBUG: player: '%s'" % p
87 # teststat = testhash[p]
90 # #print "pstat[%s][%s]: %s == %s" % (p, stat, pstat[stat], teststat[stat])
92 # if pstat[stat] == teststat[stat]:
93 # # The stats match - continue
96 # # Stats don't match - Doh!
97 # errors.error_report(filename, hand, stat, ghash, testhash, p)
99 # errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p)
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
)
115 print "***********************************"
116 compare(nfile
, importer
, errors
, site
)
117 print "***********************************"
123 config
= Configuration
.Config(file = "HUD_config.test.xml")
124 db
= Database
.Database(config
)
125 sql
= SQL
.Sql(db_server
= 'sqlite')
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')
144 PokerStarsErrors
, FTPErrors
, WinamaxErrors
,
146 #BetfairErrors, OnGameErrors, AbsoluteErrors,
147 #EverleafErrors, CarbonErrors, PKRErrors,
148 #iPokerErrors, UltimateBetErrors,
153 'Full Tilt Poker' : True,
154 #'PartyPoker' : True,
158 #'UltimateBet' : 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")
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
206 for i
, site
in enumerate(ErrorsList
):
207 tmp
= ErrorsList
[i
].statcount
210 statdict
[stat
] += tmp
[stat
]
212 statdict
[stat
] = tmp
[stat
]
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__':