Don't allow the start date to be later than the end date. If it is, modify whichever...
[fpdb-dooglus.git] / pyfpdb / FullTiltPokerSummary.py
blobcb02b9c90f3ca0780eafa9347ed4434ab10cad42
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2011 Steffen Schaumburg
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.
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.
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 """pokerstars-specific summary parsing code"""
20 import L10n
21 _ = L10n.get_translation()
23 from decimal_wrapper import Decimal
24 import datetime
26 from Exceptions import FpdbParseError
27 from HandHistoryConverter import *
28 from TourneySummary import *
30 class FullTiltPokerSummary(TourneySummary):
31 limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
32 games = { # base, category
33 "Hold'em" : ('hold','holdem'),
34 'Omaha' : ('hold','omahahi'),
35 'Omahai Hi' : ('hold','omahahi'),
36 'Omaha Hi/Lo' : ('hold','omahahilo'),
37 'Razz' : ('stud','razz'),
38 'RAZZ' : ('stud','razz'),
39 '7 Card Stud' : ('stud','studhi'),
40 '7 Card Stud Hi/Lo' : ('stud','studhilo'),
41 'Badugi' : ('draw','badugi'),
42 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
43 '5 Card Draw' : ('draw','fivedraw')
46 substitutions = {
47 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
48 'LS' : u"\$|\xe2\x82\xac|\u20ac|", # legal currency symbols - Euro(cp1252, utf-8)
49 'TAB' : u"-\u2013'\s\da-zA-Z", # legal characters for tablename
50 'NUM' : u".,\d", # legal characters in number format
53 re_SplitTourneys = re.compile("^Full Tilt Poker Tournament Summary")
55 re_TourNo = re.compile("\#(?P<TOURNO>[0-9]+),")
57 re_TourneyInfo = re.compile(u"""
58 \s.*
59 (?P<TYPE>Tournament|Sit\s\&\sGo|\(Rebuy\)|)\s\((?P<TOURNO>[0-9]+)\)(\s+)?
60 (?P<GAME>Hold\'em|Razz|RAZZ|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball|5\sCard\sDraw)\s+
61 (?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\s+
62 (Buy-In:\s[%(LS)s](?P<BUYIN>[.\d]+)(\s\+\s[%(LS)s](?P<FEE>[.\d]+))?\s+)?
63 (Add-On:\s[%(LS)s](?P<ADDON>[.\d]+)\s+)?
64 (Rebuy:\s[%(LS)s](?P<REBUYAMT>[.\d]+)\s+)?
65 ((?P<PNAME>.{2,15})\sperformed\s(?P<PREBUYS>\d+)\sRebuys\s+)?
66 (Buy-In\sChips:\s(?P<CHIPS>\d+)\s+)?
67 (Add-On\sChips:\s(?P<ADDONCHIPS>\d+)\s+)?
68 (Rebuy\sChips:\s(?P<REBUYCHIPS>\d+)\s+)?
69 (?P<ENTRIES>[0-9]+)\sEntries\s+
70 (Total\sAdd-Ons:\s(?P<ADDONS>\d+)\s+)?
71 (Total\sRebuys:\s(?P<REBUYS>\d+)\s+)?
72 ([%(LS)s]?(?P<ADDED>[.\d]+)\sadded\sto\sthe\sprize\spool\sby\sPokerStars\.com\s+)?
73 (Total\sPrize\sPool:\s[%(LS)s]?(?P<PRIZEPOOL>[%(NUM)s]+)\s+)?
74 (Target\sTournament\s.*)?
75 Tournament\sstarted:\s
76 (?P<Y>[\d]{4})\/(?P<M>[\d]{2})\/(?P<D>[\d]+)\s+(?P<H>[\d]+):(?P<MIN>[\d]+):(?P<S>[\d]+)\s??(?P<TZ>[A-Z]+)\s
77 """ % substitutions ,re.VERBOSE|re.MULTILINE|re.DOTALL)
79 re_Currency = re.compile(u"""(?P<CURRENCY>[%(LS)s]|FPP)""" % substitutions)
81 re_Player = re.compile(u"""(?P<RANK>[\d]+):\s(?P<NAME>[^,\r\n]{2,15})(,(\s)?[%(LS)s](?P<WINNINGS>[.\d]+))?""")
82 re_Finished = re.compile(u"""(?P<NAME>[^,\r\n]{2,15}) finished in (?P<RANK>[\d]+)\S\S place""")
84 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]+)")
86 codepage = ["utf-16", "cp1252", "utf-8"]
88 def parseSummary(self):
89 m = self.re_TourneyInfo.search(self.summaryText[:2000])
90 if m == None:
91 tmp = self.summaryText[0:200]
92 log.error("parseSummary: " + _("Unable to recognise Tourney Info: '%s'") % tmp)
93 log.error("parseSummary: " + _("Raising FpdbParseError"))
94 raise FpdbParseError(_("Unable to recognise Tourney Info: '%s'") % tmp)
96 #print "DEBUG: m.groupdict(): %s" % m.groupdict()
98 mg = m.groupdict()
99 if 'TOURNO' in mg: self.tourNo = mg['TOURNO']
100 if 'LIMIT' in mg: self.gametype['limitType'] = self.limits[mg['LIMIT']]
101 if 'GAME' in mg: self.gametype['category'] = self.games[mg['GAME']][1]
102 if mg['BUYIN'] != None:
103 self.buyin = int(100*Decimal(mg['BUYIN']))
104 if mg['FEE'] != None:
105 self.fee = int(100*Decimal(mg['FEE']))
106 if 'PRIZEPOOL' in mg: self.prizepool = mg['PRIZEPOOL']
107 if 'ENTRIES' in mg: self.entries = mg['ENTRIES']
109 datetimestr = "%s/%s/%s %s:%s:%s" % (mg['Y'], mg['M'], mg['D'], mg['H'], mg['MIN'], mg['S'])
110 self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
112 if 'TZ' in mg:
113 self.startTime = HandHistoryConverter.changeTimezone(self.startTime, mg['TZ'], "UTC")
116 m = self.re_Currency.search(self.summaryText)
117 if m == None:
118 log.error("parseSummary: " + _("Unable to locate currency"))
119 log.error("parseSummary: " + _("Raising FpdbParseError"))
120 raise FpdbParseError(_("Unable to locate currency"))
121 #print "DEBUG: m.groupdict(): %s" % m.groupdict()
123 mg = m.groupdict()
124 if mg['CURRENCY'] == "$": self.currency = "USD"
125 elif mg['CURRENCY'] == u"€": self.currency="EUR"
126 elif mg['CURRENCY'] == "FPP": self.currency="PSFP"
128 m = self.re_Player.finditer(self.summaryText)
129 playercount = 0
130 for a in m:
131 mg = a.groupdict()
132 #print "DEBUG: a.groupdict(): %s" % mg
133 name = mg['NAME']
134 rank = mg['RANK']
135 winnings = 0
137 if 'WINNINGS' in mg and mg['WINNINGS'] != None:
138 winnings = int(100*Decimal(mg['WINNINGS']))
139 self.addPlayer(rank, name, winnings, self.currency, None, None, None)
140 playercount += 1
142 # Some files dont contain the normals lines, and only contain the line
143 # <PLAYER> finished in XXXXrd place
144 if playercount == 0:
145 m = self.re_Finished.finditer(self.summaryText)
146 for a in m:
147 winnings = 0
148 name = a.group('NAME')
149 rank = a.group('RANK')
150 self.addPlayer(rank, name, winnings, self.currency, None, None, None)