Coverage for PokerTrackerSummary.py: 0%

123 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 18:50 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3 

4#Copyright 2008-2012 Chaz Littlejohn 

5#This program is free software: you can redistribute it and/or modify 

6#it under the terms of the GNU Affero General Public License as published by 

7#the Free Software Foundation, version 3 of the License. 

8# 

9#This program is distributed in the hope that it will be useful, 

10#but WITHOUT ANY WARRANTY; without even the implied warranty of 

11#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12#GNU General Public License for more details. 

13# 

14#You should have received a copy of the GNU Affero General Public License 

15#along with this program. If not, see <http://www.gnu.org/licenses/>. 

16#In the "official" distribution you can find the license in agpl-3.0.txt. 

17 

18 

19#import L10n 

20#_ = L10n.get_translation() 

21 

22from decimal_wrapper import Decimal 

23import datetime 

24 

25from Exceptions import FpdbParseError 

26from HandHistoryConverter import * 

27from TourneySummary import * 

28 

29class PokerTrackerSummary(TourneySummary): 

30 hhtype = "summary" 

31 limits = { 'NL':'nl', 'No Limit':'nl', 'Pot Limit':'pl', 'PL': 'pl', 'FL': 'fl', 'Limit':'fl', 'LIMIT':'fl' } 

32 games = { # base, category 

33 "Hold'em" : ('hold','holdem'), 

34 "Texas Hold'em" : ('hold','holdem'), 

35 "Holdem" : ('hold','holdem'), 

36 'Omaha' : ('hold','omahahi'), 

37 'Omaha Hi' : ('hold','omahahi'), 

38 'Omaha Hi/Lo' : ('hold','omahahilo') 

39 } 

40 

41 substitutions = { 

42 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes 

43 'LS' : u"\$|€|\£|P|SC|", # legal currency symbols - Euro(cp1252, utf-8) 

44 'PLYR': r'(?P<PNAME>.+?)', 

45 'NUM' : u".,\d", 

46 'CUR': u"(\$|€||\£|)", 

47 } 

48 

49 re_Identify = re.compile(u"PokerTracker") 

50 

51 re_TourneyInfo = re.compile(u""" 

52 \s(3|4)\sTournament\sSummary\s+ 

53 Site:\s(?P<SITE>.+?)\s+ 

54 Game:\s(?P<GAME>Holdem|Texas\sHold\'em|Omaha|Omaha\sHi|Omaha\sHi\/Lo)\s+ 

55 Tournament\s\#:\s(?P<TOURNO>[0-9]+)\s+ 

56 Started:\s(?P<DATETIME>.+?)\s+ 

57 Finished:\s(?P<DATETIME1>.+?)\s+ 

58 Buyin:\s(?P<CURRENCY>[%(LS)s]?)(?P<BUYIN>[,.0-9]+)\s+ 

59 (Bounty:\s[%(LS)s]?(?P<BOUNTY>[,.0-9]+)\s+)? 

60 Fee:\s[%(LS)s]?(?P<FEE>[,.0-9]+)\s+ 

61 (Prize\sPool:\s[%(LS)s]?(?P<PRIZEPOOL>[,.0-9]+)\s+)? 

62 (Rebuy:\s[%(LS)s]?(?P<REBUYAMT>[,.0-9]+)\s+)? 

63 (Addon:\s[%(LS)s]?(?P<ADDON>[,.0-9]+)\s+)? 

64 Initial\sStack:\s(?P<STACK>[0-9]+)\s+ 

65 Table\sType:\s(?P<TYPE>.+?)\s+ 

66 Tourney\sType:\s(?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit|N\/A)\s+ 

67 Players:\s(?P<ENTRIES>\d+)\s+ 

68 """ % substitutions ,re.VERBOSE|re.MULTILINE) 

69 

70 re_Max = re.compile("\((?P<MAX>\d+)\smax\)\s") 

71 re_Speed = re.compile("(?P<SPEED>Turbo|Hyper\-Turbo)") 

72 re_Sng = re.compile("\s(?P<SNG>SNG)\s") 

73 

74 re_Player = re.compile(u""" 

75 Place:\s(?P<RANK>[0-9]+),\s 

76 Player:\s(?P<NAME>.*),\s 

77 Won:\s(?P<CUR>[%(LS)s]?)(?P<WINNINGS>[,.0-9]+), 

78 (\sBounties:\s(?P<KOS>\d+),)? 

79 (\sRebuys:\s(?P<REBUYS>\d+),)? 

80 (\sAddons:\s(?P<ADDONS>\d+),)? 

81 """ % substitutions, re.VERBOSE) 

82 

83 re_DateTime = re.compile("""(?P<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)""", re.MULTILINE) 

84 

85 codepage = ["utf-8", "cp1252"] 

86 

87 siteNameMap = { 

88 'Pacific Poker': 'PacificPoker', 

89 'MicroGaming': 'Microgaming', 

90 'PokerStars': 'PokerStars', 

91 'Full Tilt': 'Fulltilt', 

92 'Party Poker': 'PartyPoker', 

93 'Merge': 'Merge', 

94 'Winamax':'Winamax' 

95 } 

96 

97 @staticmethod 

98 def getSplitRe(self, head): 

99 re_SplitTourneys = re.compile("PokerTracker") 

100 return re_SplitTourneys 

101 

102 def parseSummary(self): 

103 m = self.re_TourneyInfo.search(self.summaryText) 

104 if m == None: 

105 tmp = self.summaryText[0:200] 

106 log.error(("PokerTrackerSummary.parseSummary: '%s'") % tmp) 

107 raise FpdbParseError 

108 

109 #print "DEBUG: m.groupdict(): %s" % m.groupdict() 

110 

111 mg = m.groupdict() 

112 if 'SITE' in mg: 

113 if self.siteNameMap.get(mg['SITE']) != None: 

114 self.siteName = self.siteNameMap.get(mg['SITE']) 

115 self.siteId = self.SITEIDS.get(self.siteName) 

116 else: 

117 tmp = self.summaryText[0:200] 

118 log.error(("PokerTrackerSummary.parseSummary: Unsupported site summary '%s'") % tmp) 

119 raise FpdbParseError 

120 if 'TOURNO' in mg: self.tourNo = mg['TOURNO'] 

121 if 'GAME' in mg: self.gametype['category'] = self.games[mg['GAME']][1] 

122 if mg['LIMIT'] in self.limits: 

123 self.gametype['limitType'] = self.limits[mg['LIMIT']] 

124 elif self.gametype['category'] == 'holdem': 

125 self.gametype['limitType'] = 'nl' 

126 else: 

127 self.gametype['limitType'] = 'pl' 

128 if 'TYPE' in mg: 

129 self.tourneyName = mg['TYPE'] 

130 t1 = self.re_Max.search(self.tourneyName) 

131 if t1: 

132 self.maxseats = int(t1.group('MAX')) 

133 t2 = self.re_Speed.search(self.tourneyName) 

134 if t2: 

135 if t2.group('SPEED')=='Turbo': 

136 self.speed = 'Turbo' 

137 elif t2.group('SPEED')=='Hyper-Turbo': 

138 self.speed = 'Hyper' 

139 t3 = self.re_Sng.search(self.tourneyName) 

140 if t3: self.isSng = True 

141 if "DEEP" in self.tourneyName: 

142 self.stack = "Deep" 

143 if "SATELLITE" in self.tourneyName: 

144 self.isSatellite = True 

145 if mg['BUYIN'] != None: 

146 self.buyin = int(100*float(self.clearMoneyString(mg['BUYIN']))) 

147 if mg['FEE'] != None: 

148 self.fee = int(100*float(self.clearMoneyString(mg['FEE']))) 

149 if 'REBUYAMT' in mg and mg['REBUYAMT'] != None: 

150 self.isRebuy = True 

151 self.rebuyCost = int(100*float(self.clearMoneyString(mg['REBUYAMT']))) 

152 if 'PRIZEPOOL' in mg and mg['PRIZEPOOL'] != None: 

153 self.prizepool = int(100*float(self.clearMoneyString(mg['PRIZEPOOL']))) 

154 if 'ADDON' in mg and mg['ADDON'] != None: 

155 self.isAddOn = True 

156 self.addOnCost = int(100*float(self.clearMoneyString(mg['ADDON']))) 

157 if 'BOUNTY' in mg and mg['BOUNTY'] != None: 

158 self.koBounty = int(100*float(self.clearMoneyString(mg['BOUNTY']))) 

159 self.isKO = True 

160 if 'ENTRIES' in mg: 

161 self.entries = mg['ENTRIES'] 

162 if 'DATETIME' in mg: 

163 m1 = self.re_DateTime.finditer(mg['DATETIME']) 

164 for a in m1: 

165 datetimestr = "%s/%s/%s %s:%s:%s" % (a.group('Y'), a.group('M'),a.group('D'),a.group('H'),a.group('MIN'),a.group('S')) 

166 else: 

167 datetimestr = "2000/01/01 00:00:00" # default used if time not found 

168 

169 self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET" 

170 

171 if mg['CURRENCY'] == "$": self.buyinCurrency="USD" 

172 elif mg['CURRENCY'] == u"€": self.buyinCurrency="EUR" 

173 elif mg['CURRENCY'] in ("SC","P"): self.buyinCurrency="PSFP" 

174 elif not mg['CURRENCY']: self.buyinCurrency="play" 

175 if self.buyin == 0: self.buyinCurrency="FREE" 

176 self.currency = self.buyinCurrency 

177 

178 if self.buyinCurrency not in ('FREE', 'PSFP') and 'ENTRIES' in mg and self.prizepool == 0: 

179 self.prizepool = int(Decimal(self.clearMoneyString(mg['BUYIN']))) * int(self.entries) 

180 

181 m = self.re_Player.finditer(self.summaryText) 

182 for a in m: 

183 mg = a.groupdict() 

184 #print "DEBUG: a.groupdict(): %s" % mg 

185 name = mg['NAME'] 

186 rank = int(mg['RANK']) 

187 winnings = 0 

188 rebuyCount = None 

189 addOnCount = None 

190 koCount = None 

191 if len(name)>0: 

192 if 'WINNINGS' in mg and mg['WINNINGS'] != None: 

193 winning1 = mg['WINNINGS'] 

194 winning2 = self.clearMoneyString(winning1) 

195 winning3 = int(float(winning2)) 

196 winnings = int(100*float(self.clearMoneyString(mg['WINNINGS']))) 

197 

198 if 'REBUYS' in mg and mg['REBUYS']!=None: 

199 rebuyCount = int(mg['REBUYS']) 

200 

201 if 'ADDONS' in mg and mg['ADDONS']!=None: 

202 addOnCount = int(mg['ADDONS']) 

203 

204 if 'KOS' in mg and mg['KOS']!=None: 

205 koCount = int(mg['KOS']) 

206 

207 if 'CUR' in mg and mg['CUR'] != None: 

208 if mg['CUR'] == "$": self.currency="USD" 

209 elif mg['CUR'] == u"€": self.currency="EUR" 

210 elif mg['CUR'] in ("P","SC"): self.currency="PSFP" 

211 

212 if rank==0: 

213 #print "stillplaying" 

214 rank=None 

215 winnings=None 

216 

217 if len(name)==0: 

218 log.debug("DEBUG: a.groupdict(): %d %s" % (i, mg)) 

219 

220 #print "DEBUG: addPlayer(%s, %s, %s, %s, None, None, None)" %(rank, name, winnings, self.currency) 

221 #print "DEBUG: self.buyin: %s self.fee %s" %(self.buyin, self.fee) 

222 self.addPlayer(rank, name, winnings, self.currency, rebuyCount, addOnCount, koCount) 

223 

224 #print self 

225 

226#end class PokerStarsSummary