Coverage for PokerTrackerSummary.py: 0%
133 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
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.
19# import L10n
20# _ = L10n.get_translation()
22from HandHistoryConverter import FpdbParseError
23import re
24import logging
25import datetime
26from TourneySummary import TourneySummary
27from decimal import Decimal
29# PokerStars HH Format
30log = logging.getLogger("parser")
33class PokerTrackerSummary(TourneySummary):
34 hhtype = "summary"
35 limits = {"NL": "nl", "No Limit": "nl", "Pot Limit": "pl", "PL": "pl", "FL": "fl", "Limit": "fl", "LIMIT": "fl"}
36 games = { # base, category
37 "Hold'em": ("hold", "holdem"),
38 "Texas Hold'em": ("hold", "holdem"),
39 "Holdem": ("hold", "holdem"),
40 "Omaha": ("hold", "omahahi"),
41 "Omaha Hi": ("hold", "omahahi"),
42 "Omaha Hi/Lo": ("hold", "omahahilo"),
43 }
45 substitutions = {
46 "LEGAL_ISO": "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
47 "LS": "\$|€|\£|P|SC|", # legal currency symbols - Euro(cp1252, utf-8)
48 "PLYR": r"(?P<PNAME>.+?)",
49 "NUM": ".,\d",
50 "CUR": "(\$|€||\£|)",
51 }
53 re_Identify = re.compile("PokerTracker")
55 re_TourneyInfo = re.compile(
56 """
57 \s(3|4)\sTournament\sSummary\s+
58 Site:\s(?P<SITE>.+?)\s+
59 Game:\s(?P<GAME>Holdem|Texas\sHold\'em|Omaha|Omaha\sHi|Omaha\sHi\/Lo)\s+
60 Tournament\s\#:\s(?P<TOURNO>[0-9]+)\s+
61 Started:\s(?P<DATETIME>.+?)\s+
62 Finished:\s(?P<DATETIME1>.+?)\s+
63 Buyin:\s(?P<CURRENCY>[%(LS)s]?)(?P<BUYIN>[,.0-9]+)\s+
64 (Bounty:\s[%(LS)s]?(?P<BOUNTY>[,.0-9]+)\s+)?
65 Fee:\s[%(LS)s]?(?P<FEE>[,.0-9]+)\s+
66 (Prize\sPool:\s[%(LS)s]?(?P<PRIZEPOOL>[,.0-9]+)\s+)?
67 (Rebuy:\s[%(LS)s]?(?P<REBUYAMT>[,.0-9]+)\s+)?
68 (Addon:\s[%(LS)s]?(?P<ADDON>[,.0-9]+)\s+)?
69 Initial\sStack:\s(?P<STACK>[0-9]+)\s+
70 Table\sType:\s(?P<TYPE>.+?)\s+
71 Tourney\sType:\s(?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit|N\/A)\s+
72 Players:\s(?P<ENTRIES>\d+)\s+
73 """
74 % substitutions,
75 re.VERBOSE | re.MULTILINE,
76 )
78 re_Max = re.compile("\((?P<MAX>\d+)\smax\)\s")
79 re_Speed = re.compile("(?P<SPEED>Turbo|Hyper\-Turbo)")
80 re_Sng = re.compile("\s(?P<SNG>SNG)\s")
82 re_Player = re.compile(
83 """
84 Place:\s(?P<RANK>[0-9]+),\s
85 Player:\s(?P<NAME>.*),\s
86 Won:\s(?P<CUR>[%(LS)s]?)(?P<WINNINGS>[,.0-9]+),
87 (\sBounties:\s(?P<KOS>\d+),)?
88 (\sRebuys:\s(?P<REBUYS>\d+),)?
89 (\sAddons:\s(?P<ADDONS>\d+),)?
90 """
91 % substitutions,
92 re.VERBOSE,
93 )
95 re_DateTime = re.compile(
96 """(?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]+)""",
97 re.MULTILINE,
98 )
100 codepage = ["utf-8", "cp1252"]
102 siteNameMap = {
103 "Pacific Poker": "PacificPoker",
104 "MicroGaming": "Microgaming",
105 "PokerStars": "PokerStars",
106 "Full Tilt": "Fulltilt",
107 "Party Poker": "PartyPoker",
108 "Merge": "Merge",
109 "Winamax": "Winamax",
110 }
112 @staticmethod
113 def getSplitRe(self, head):
114 re_SplitTourneys = re.compile("PokerTracker")
115 return re_SplitTourneys
117 def parseSummary(self):
118 m = self.re_TourneyInfo.search(self.summaryText)
119 if m is None:
120 tmp = self.summaryText[0:200]
121 log.error(("PokerTrackerSummary.parseSummary: '%s'") % tmp)
122 raise FpdbParseError
124 # print "DEBUG: m.groupdict(): %s" % m.groupdict()
126 mg = m.groupdict()
127 if "SITE" in mg:
128 if self.siteNameMap.get(mg["SITE"]) is not None:
129 self.siteName = self.siteNameMap.get(mg["SITE"])
130 self.siteId = self.SITEIDS.get(self.siteName)
131 else:
132 tmp = self.summaryText[0:200]
133 log.error(("PokerTrackerSummary.parseSummary: Unsupported site summary '%s'") % tmp)
134 raise FpdbParseError
135 if "TOURNO" in mg:
136 self.tourNo = mg["TOURNO"]
137 if "GAME" in mg:
138 self.gametype["category"] = self.games[mg["GAME"]][1]
139 if mg["LIMIT"] in self.limits:
140 self.gametype["limitType"] = self.limits[mg["LIMIT"]]
141 elif self.gametype["category"] == "holdem":
142 self.gametype["limitType"] = "nl"
143 else:
144 self.gametype["limitType"] = "pl"
145 if "TYPE" in mg:
146 self.tourneyName = mg["TYPE"]
147 t1 = self.re_Max.search(self.tourneyName)
148 if t1:
149 self.maxseats = int(t1.group("MAX"))
150 t2 = self.re_Speed.search(self.tourneyName)
151 if t2:
152 if t2.group("SPEED") == "Turbo":
153 self.speed = "Turbo"
154 elif t2.group("SPEED") == "Hyper-Turbo":
155 self.speed = "Hyper"
156 t3 = self.re_Sng.search(self.tourneyName)
157 if t3:
158 self.isSng = True
159 if "DEEP" in self.tourneyName:
160 self.stack = "Deep"
161 if "SATELLITE" in self.tourneyName:
162 self.isSatellite = True
163 if mg["BUYIN"] is not None:
164 self.buyin = int(100 * float(self.clearMoneyString(mg["BUYIN"])))
165 if mg["FEE"] is not None:
166 self.fee = int(100 * float(self.clearMoneyString(mg["FEE"])))
167 if "REBUYAMT" in mg and mg["REBUYAMT"] is not None:
168 self.isRebuy = True
169 self.rebuyCost = int(100 * float(self.clearMoneyString(mg["REBUYAMT"])))
170 if "PRIZEPOOL" in mg and mg["PRIZEPOOL"] is not None:
171 self.prizepool = int(100 * float(self.clearMoneyString(mg["PRIZEPOOL"])))
172 if "ADDON" in mg and mg["ADDON"] is not None:
173 self.isAddOn = True
174 self.addOnCost = int(100 * float(self.clearMoneyString(mg["ADDON"])))
175 if "BOUNTY" in mg and mg["BOUNTY"] is not None:
176 self.koBounty = int(100 * float(self.clearMoneyString(mg["BOUNTY"])))
177 self.isKO = True
178 if "ENTRIES" in mg:
179 self.entries = mg["ENTRIES"]
180 if "DATETIME" in mg:
181 m1 = self.re_DateTime.finditer(mg["DATETIME"])
182 for a in m1:
183 datetimestr = "%s/%s/%s %s:%s:%s" % (
184 a.group("Y"),
185 a.group("M"),
186 a.group("D"),
187 a.group("H"),
188 a.group("MIN"),
189 a.group("S"),
190 )
191 else:
192 datetimestr = "2000/01/01 00:00:00" # default used if time not found
194 self.startTime = datetime.datetime.strptime(
195 datetimestr, "%Y/%m/%d %H:%M:%S"
196 ) # also timezone at end, e.g. " ET"
198 if mg["CURRENCY"] == "$":
199 self.buyinCurrency = "USD"
200 elif mg["CURRENCY"] == "€":
201 self.buyinCurrency = "EUR"
202 elif mg["CURRENCY"] in ("SC", "P"):
203 self.buyinCurrency = "PSFP"
204 elif not mg["CURRENCY"]:
205 self.buyinCurrency = "play"
206 if self.buyin == 0:
207 self.buyinCurrency = "FREE"
208 self.currency = self.buyinCurrency
210 if self.buyinCurrency not in ("FREE", "PSFP") and "ENTRIES" in mg and self.prizepool == 0:
211 self.prizepool = int(Decimal(self.clearMoneyString(mg["BUYIN"]))) * int(self.entries)
213 m = self.re_Player.finditer(self.summaryText)
214 for a in m:
215 mg = a.groupdict()
216 # print "DEBUG: a.groupdict(): %s" % mg
217 name = mg["NAME"]
218 rank = int(mg["RANK"])
219 winnings = 0
220 rebuyCount = None
221 addOnCount = None
222 koCount = None
223 if len(name) > 0:
224 if "WINNINGS" in mg and mg["WINNINGS"] is not None:
225 # winning1 = mg["WINNINGS"]
226 # winning2 = self.clearMoneyString(winning1)
227 # winning3 = int(float(winning2))
228 winnings = int(100 * float(self.clearMoneyString(mg["WINNINGS"])))
230 if "REBUYS" in mg and mg["REBUYS"] is not None:
231 rebuyCount = int(mg["REBUYS"])
233 if "ADDONS" in mg and mg["ADDONS"] is not None:
234 addOnCount = int(mg["ADDONS"])
236 if "KOS" in mg and mg["KOS"] is not None:
237 koCount = int(mg["KOS"])
239 if "CUR" in mg and mg["CUR"] is not None:
240 if mg["CUR"] == "$":
241 self.currency = "USD"
242 elif mg["CUR"] == "€":
243 self.currency = "EUR"
244 elif mg["CUR"] in ("P", "SC"):
245 self.currency = "PSFP"
247 if rank == 0:
248 # print "stillplaying"
249 rank = None
250 winnings = None
252 if len(name) == 0:
253 log.debug("DEBUG: a.groupdict(): %s" % (mg))
255 # print "DEBUG: addPlayer(%s, %s, %s, %s, None, None, None)" %(rank, name, winnings, self.currency)
256 # print "DEBUG: self.buyin: %s self.fee %s" %(self.buyin, self.fee)
257 self.addPlayer(rank, name, winnings, self.currency, rebuyCount, addOnCount, koCount)
259 # print self
262# end class PokerStarsSummary