Coverage for PacificPokerSummary.py: 0%

93 statements  

« 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 -*- 

3 

4# Copyright 2008-2012 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. 

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# import L10n 

19# _ = L10n.get_translation() 

20from HandHistoryConverter import FpdbParseError 

21from decimal import Decimal 

22import re 

23import logging 

24from TourneySummary import TourneySummary 

25 

26# Pacifc(888) HH Format 

27log = logging.getLogger("parser") 

28 

29 

30class PacificPokerSummary(TourneySummary): 

31 limits = {"No Limit": "nl", "Pot Limit": "pl", "Limit": "fl", "LIMIT": "fl"} 

32 

33 games = { # base, category 

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

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

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

37 "Omaha Hi/Lo": ("hold", "omahahilo"), 

38 "OmahaHL": ("hold", "omahahilo"), 

39 } 

40 

41 substitutions = { 

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

43 "LS": "\$|€|", # legal currency symbols 

44 "NUM": ".,\d\xa0", # legal characters in number format 

45 } 

46 

47 re_Identify = re.compile("\*{5}\s(Cassava|888poker|888)(\.[a-z]{2})?(\-[a-z]{2})? Tournament Summary\s\*{5}") 

48 

49 re_TourneyInfo = re.compile( 

50 """ 

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

52 Buy-In:\s(?P<BUYIN>(((?P<BIAMT>(?P<CURRENCY1>%(LS)s)?[%(NUM)s]+\s?(?P<CURRENCY2>%(LS)s)?)(\s\+\s?(?P<BIRAKE>(%(LS)s)?[%(NUM)s]+\s?(%(LS)s)?))?)|(Free)|(.+?)))\s+ 

53 (Rebuy:\s[%(LS)s](?P<REBUYAMT>[%(NUM)s]+)\s?(%(LS)s)?\s+)? 

54 (Add-On:\s[%(LS)s](?P<ADDON>[%(NUM)s]+)\s?(%(LS)s)?\s+)? 

55 ((?P<P1NAME>.*?)\sperformed\s(?P<PREBUYS>\d+)\srebuys?\s+)? 

56 ((?P<P2NAME>.*?)\sperformed\s(?P<PADDONS>\d+)\sadd-ons?\s+)? 

57 ^(?P<PNAME>.+?)\sfinished\s(?P<RANK>[0-9]+)\/(?P<ENTRIES>[0-9]+)(\sand\swon\s(?P<WCURRENCY>[%(LS)s])?(?P<WINNINGS>[%(NUM)s]+)\s?(?P<WCURRENCY2>[%(LS)s])?)? 

58 """ 

59 % substitutions, 

60 re.VERBOSE | re.MULTILINE | re.DOTALL, 

61 ) 

62 

63 re_Category = re.compile( 

64 """ 

65 (?P<LIMIT>No\sLimit|Fix\sLimit|Pot\sLimit)\s 

66 (?P<GAME>Holdem|Omaha|OmahaHL|Hold\'em|Omaha\sHi/Lo|OmahaHL) 

67 """ 

68 % substitutions, 

69 re.VERBOSE | re.MULTILINE | re.DOTALL, 

70 ) 

71 

72 codepage = ("utf8", "cp1252") 

73 

74 @staticmethod 

75 def getSplitRe(self, head): 

76 re_SplitTourneys = re.compile( 

77 "\*\*\*\*\* (Cassava|888poker|888)(\.[a-z]{2})?(\-[a-z]{2})? Tournament Summary \*\*\*\*\*" 

78 ) 

79 return re_SplitTourneys 

80 

81 def parseSummary(self): 

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

83 if m is None: 

84 tmp = self.summaryText[0:200] 

85 log.error(("PacificPokerSummary.parseSummary: '%s'") % tmp) 

86 raise FpdbParseError 

87 

88 mg = m.groupdict() 

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

90 # print "DEBUG: m1.groupdict(): %s" % mg1 

91 

92 self.tourNo = mg["TOURNO"] 

93 

94 m1 = self.re_Category.search(self.in_path) 

95 if m1: 

96 mg1 = m1.groupdict() 

97 if "LIMIT" in mg1 and mg1["LIMIT"] is not None: 

98 self.gametype["limitType"] = self.limits[mg1["LIMIT"]] 

99 else: 

100 self.gametype["limitType"] = "fl" 

101 if "GAME" in mg1: 

102 self.gametype["category"] = self.games[mg1["GAME"]][1] 

103 else: 

104 self.gametype["limitType"] = "nl" 

105 self.gametype["category"] = "holdem" 

106 

107 if "BUYIN" in mg and mg["BUYIN"] is not None: 

108 if mg["BUYIN"] == "Free" or mg["BIAMT"] is None: 

109 self.buyin = 0 

110 self.fee = 0 

111 else: 

112 self.buyin = int(100 * self.convert_to_decimal(mg["BIAMT"])) 

113 if mg["BIRAKE"] is None: 

114 self.fee = 0 

115 else: 

116 self.fee = int(100 * self.convert_to_decimal(mg["BIRAKE"])) 

117 

118 self.entries = mg["ENTRIES"] 

119 self.prizepool = self.buyin * int(self.entries) 

120 if "REBUYAMT" in mg and mg["REBUYAMT"] is not None: 

121 self.isRebuy = True 

122 self.rebuyCost = int(100 * self.convert_to_decimal(mg["REBUYAMT"])) 

123 if "ADDON" in mg and mg["ADDON"] is not None: 

124 self.isAddOn = True 

125 self.addOnCost = int(100 * self.convert_to_decimal(mg["ADDON"])) 

126 # self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") 

127 

128 if "CURRENCY1" in mg and mg["CURRENCY1"]: 

129 currency = mg["CURRENCY1"] 

130 elif "CURRENCY2" in mg and mg["CURRENCY2"]: 

131 currency = mg["CURRENCY2"] 

132 else: 

133 currency = None 

134 

135 if currency: 

136 if currency == "$": 

137 self.buyinCurrency = "USD" 

138 elif currency == "€": 

139 self.buyinCurrency = "EUR" 

140 elif self.buyin == 0: 

141 self.buyinCurrency = "FREE" 

142 else: 

143 self.buyinCurrency = "play" 

144 self.currency = self.buyinCurrency 

145 

146 player = mg["PNAME"] 

147 rank = int(mg["RANK"]) 

148 winnings = 0 

149 rebuyCount = None 

150 addOnCount = None 

151 koCount = None 

152 

153 if "WINNINGS" in mg and mg["WINNINGS"] is not None: 

154 winnings = int(100 * self.convert_to_decimal(mg["WINNINGS"])) 

155 if mg.get("WCURRENCY"): 

156 if mg["WCURRENCY"] == "$": 

157 self.currency = "USD" 

158 elif mg["WCURRENCY"] == "€": 

159 self.currency = "EUR" 

160 elif mg.get("WCURRENCY2"): 

161 if mg["WCURRENCY2"] == "$": 

162 self.currency = "USD" 

163 elif mg["WCURRENCY2"] == "€": 

164 self.currency = "EUR" 

165 if "PREBUYS" in mg and mg["PREBUYS"] is not None: 

166 rebuyCount = int(mg["PREBUYS"]) 

167 if "PADDONS" in mg and mg["PADDONS"] is not None: 

168 addOnCount = int(mg["PADDONS"]) 

169 

170 self.addPlayer(rank, player, winnings, self.currency, rebuyCount, addOnCount, koCount) 

171 

172 def convert_to_decimal(self, string): 

173 dec = self.clearMoneyString(string) 

174 dec = Decimal(dec) 

175 return dec