Coverage for WinningSummary.py: 0%
112 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
« 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 -*-
4#Copyright 2016 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.
18"""winning poker specific summary parsing code"""
19from __future__ import division
21from past.utils import old_div
22#import L10n
23#_ = L10n.get_translation()
25from decimal_wrapper import Decimal
26import datetime
28from Exceptions import FpdbParseError
29from HandHistoryConverter import *
30from TourneySummary import *
32class WinningSummary(TourneySummary):
33 sym = {
34 'USD': "\$",
35 'T$': "",
36 "play": ""
37 }
38 substitutions = {
39 'LEGAL_ISO' : "TB|CP", # legal ISO currency codes
40 'LS' : u"\$|", # legal currency symbols
41 'PLYR': r'(?P<PNAME>.+?)',
42 'NUM' :u".,\dK",
43 }
44 games = {# base, category
45 "Hold'em" : ('hold','holdem'),
46 'Omaha' : ('hold','omahahi'),
47 'Omaha HiLow' : ('hold','omahahilo'),
48 'Seven Cards Stud' : ('stud','studhi'),
49 'Seven Cards Stud HiLow' : ('stud','studhilo')
50 }
52 speeds = {
53 'Turbo': 'Turbo',
54 'Hyper Turbo': 'Hyper',
55 'Regular': 'Normal'
56 }
58 re_Identify = re.compile(r'<link\sid="ctl00_CalendarTheme"')
60 re_HTMLPlayer = re.compile(r"Player\sDetails:\s%(PLYR)s</a>" % substitutions, re.IGNORECASE)
62 re_HTMLTourneyInfo = re.compile(
63 r'<td>(?P<TOURNO>[0-9]+)</td>' \
64 r'<td>(?P<GAME>Hold\'em|Omaha|Omaha\sHiLow|Seven\sCards\sStud|Seven\sCards\sStud\sHiLow)</td>' \
65 r'<td>(?P<TOURNAME>.*)</td>' \
66 r'<td>(?P<CURRENCY>[%(LS)s])(?P<BUYIN>[%(NUM)s]+)</td>' \
67 r'<td>[%(NUM)s]+</td>' \
68 r'<td>[%(NUM)s]+</td>' \
69 r'<td>[%(NUM)s]+</td>' \
70 r'<td>[%(LS)s](?P<FEE>[%(NUM)s]+)</td>' \
71 r'<td>[%(NUM)s]+</td>' \
72 r'<td>[%(NUM)s]+</td>' \
73 r'<td>[%(NUM)s]+</td>' \
74 r'<td>[%(LS)s](?P<REBUYS>[%(NUM)s]+)</td>' \
75 r'<td>[%(NUM)s]+</td>' \
76 r'<td>[%(NUM)s]+</td>' \
77 r'<td>[%(NUM)s]+</td>' \
78 r'<td>[%(LS)s](?P<ADDONS>[%(NUM)s]+)</td>' \
79 r'<td>[%(NUM)s]+</td>' \
80 r'<td>[%(NUM)s]+</td>' \
81 r'<td>[%(NUM)s]+</td>' \
82 r'<td>[%(LS)s](?P<WINNINGS>[%(NUM)s]+)</td>' \
83 r'<td>[%(NUM)s]+</td>' \
84 r'<td>[%(NUM)s]+</td>' \
85 r'<td>[%(NUM)s]+</td>' \
86 r'<td>.*</td>' \
87 r'<td>(?P<TOURNEYSTART>.*)</td>' \
88 r'<td>(?P<TOURNEYEND>.*)</td>' \
89 r'<td>.*</td>' # duration
90 % substitutions,
91 re.VERBOSE|re.IGNORECASE
92 )
94 re_HTMLTourneyExtraInfo = re.compile(u"""
95 ^([%(LS)s]|)?(?P<GUAR>[%(NUM)s]+)\s
96 ((?P<GAMEEXTRA>Holdem|PLO|PLO8|Omaha\sHi/Lo|Omaha|PL\sOmaha|PL\sOmaha\sHi/Lo|PLO\sHi/Lo)\s?)?
97 ((?P<SPECIAL>(GTD|Freeroll|FREEBUY|Freebuy))\s?)?
98 ((?P<SPEED>(Turbo|Hyper\sTurbo|Regular))\s?)?
99 ((?P<MAX>(\d+\-Max|Heads\-up|Heads\-Up))\s?)?
100 (?P<OTHER>.*?)
101 """ % substitutions,
102 re.VERBOSE|re.MULTILINE
103 )
105 re_HTMLDateTime = re.compile("(?P<M>[0-9]+)\/(?P<D>[0-9]+)\/(?P<Y>[0-9]{4})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+) (?P<AMPM>(AM|PM))", re.MULTILINE)
106 re_HTMLTourNo = re.compile("\s+<td>(?P<TOURNO>[0-9]+)</td>", re.DOTALL)
108 codepage = ["utf8", "cp1252"]
110 @staticmethod
111 def getSplitRe(self, head):
112 return re.compile("</tr><tr")
114 def parseSummary(self):
115 info = {}
116 m1 = self.re_HTMLPlayer.search(self.header)
117 m2 = self.re_HTMLTourneyInfo.search(self.summaryText)
118 if m1 == None or m2==None:
119 if self.re_HTMLTourNo.search(self.summaryText):
120 tmp1 = self.header[0:200] if m1 == None else 'NA'
121 tmp2 = self.summaryText[0:200] if m2 == None else 'NA'
122 log.error(("WinningSummary.parseSummaryHtml: '%s' '%s") % (tmp1, tmp2))
123 raise FpdbParseError
124 else:
125 raise FpdbHandPartial
126 #print m2.groupdict()
127 info.update(m1.groupdict())
128 info.update(m2.groupdict())
129 self.parseSummaryArchive(info)
131 def parseSummaryArchive(self, info):
132 #if 'SNG' in info and "Sit & Go" in info['SNG']:
133 # self.isSng = True
135 if 'TOURNAME' in info and info['TOURNAME'] != None:
136 self.tourneyName = info['TOURNAME']
137 m3 = self.re_HTMLTourneyExtraInfo.search(self.tourneyName)
138 if m3 != None:
139 info.update(m3.groupdict())
141 if 'GAME' in info:
142 self.gametype['category'] = self.games[info['GAME']][1]
144 if self.gametype['category'] == 'holdem':
145 self.gametype['limitType'] = 'nl'
146 elif self.gametype['category'] == 'omaha':
147 self.gametype['limitType'] = 'pl'
148 else:
149 self.gametype['limitType'] = 'fl'
151 self.buyinCurrency="USD"
152 if 'SPECIAL' in info and info['SPECIAL'] != None:
153 if info['SPECIAL'] in ('Freeroll', 'FREEBUY', 'Freebuy'):
154 self.buyinCurrency="FREE"
155 self.guaranteeAmt = int(100*Decimal(self.clearMoneyString(info['GUAR'])))
157 if 'TOURNO' in info:
158 self.tourNo = info['TOURNO']
159 if info['BUYIN'] != None:
160 self.buyin = int(100*Decimal(self.clearMoneyString(info['BUYIN'])))
161 if info['FEE'] != None:
162 self.fee = int(100*Decimal(self.clearMoneyString(info['FEE'])))
164 if ('REBUYS' in info and Decimal(self.clearMoneyString(info['REBUYS'].replace(" ", "")))>0):
165 self.isRebuy = True
166 self.rebuyCost = self.buyin
168 if ('ADDONS' in info and Decimal(self.clearMoneyString(info['ADDONS'].replace(" ", "")))>0):
169 self.isAddOn = True
170 self.addOnCost = self.buyin
172 if 'MAX' in info and info['MAX'] != None:
173 n = info['MAX'].replace('-Max', '')
174 if n in ('Heads-up', 'Heads-Up'):
175 self.maxseats = 2
176 else:
177 self.maxseats = int(n)
178 else:
179 self.maxseats = 10
181 if 'SPEED' in info and info['SPEED'] != None:
182 self.speed = self.speeds[info['SPEED']]
183 self.isSng = True
185 if "On Demand" in self.tourneyName:
186 self.isOnDemand = True
188 if " KO" in self.tourneyName or "Knockout" in self.tourneyName:
189 self.isKO = True
191 if "R/A" in self.tourneyName:
192 self.isRebuy = True
193 self.isAddOn = True
194 self.addOnCost = self.buyin
195 self.rebuyCost = self.buyin
197 if 'TOURNEYSTART' in info: m4 = self.re_HTMLDateTime.finditer(info['TOURNEYSTART'])
198 datetimestr = None # default used if time not found
199 for a in m4:
200 datetimestr = "%s/%s/%s %s:%s:%s %s" % (a.group('Y'), a.group('M'),a.group('D'),a.group('H'),a.group('MIN'),a.group('S'),a.group('AMPM'))
201 self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %I:%M:%S %p") # also timezone at end, e.g. " ET"
202 self.startTime = HandHistoryConverter.changeTimezone(self.startTime, self.import_parameters['timezone'], "UTC")
204 if 'TOURNEYEND' in info: m5 = self.re_HTMLDateTime.finditer(info['TOURNEYEND'])
205 datetimestr = None # default used if time not found
206 for a in m5:
207 datetimestr = "%s/%s/%s %s:%s:%s %s" % (a.group('Y'), a.group('M'),a.group('D'),a.group('H'),a.group('MIN'),a.group('S'),a.group('AMPM'))
208 self.endTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %I:%M:%S %p") # also timezone at end, e.g. " ET"
209 self.endTime = HandHistoryConverter.changeTimezone(self.endTime, self.import_parameters['timezone'], "UTC")
212 self.currency="USD"
213 winnings = 0
214 rebuyCount = None
215 addOnCount = None
216 koCount = None
217 rank = 9999 #fix with lookups
219 if 'WINNINGS' in info and info['WINNINGS'] != None:
220 winnings = int(100*Decimal(self.clearMoneyString(info['WINNINGS'])))
222 if self.isRebuy and self.rebuyCost > 0:
223 rebuyAmt = int(100*Decimal(self.clearMoneyString(info['REBUYS'].replace(" ", ""))))
224 rebuyCount = old_div(rebuyAmt,self.rebuyCost)
226 if self.isAddOn and self.addOnCost > 0:
227 addOnAmt = int(100*Decimal(self.clearMoneyString(info['ADDONS'].replace(" ", ""))))
228 addOnCount = old_div(addOnAmt,self.addOnCost)
230 self.hero = info['PNAME']
232 self.addPlayer(rank, info['PNAME'], winnings, self.currency, rebuyCount, addOnCount, koCount)