From 3ac124903f5d4fbf572bf3fc2ba0b612df0ae4b9 Mon Sep 17 00:00:00 2001 From: evilny0 Date: Mon, 11 Apr 2011 23:10:47 +0200 Subject: [PATCH] Reads rank and winnings from pokerstars hand history --- pyfpdb/Database.py | 2 +- pyfpdb/Hand.py | 13 ++++++++++++- pyfpdb/PokerStarsToFpdb.py | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index b2269699..ed01b8a1 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -2834,7 +2834,7 @@ class Database: else: if source=="HHC": cursor.execute (self.sql.query['insertTourneysPlayer'].replace('%s', self.sql.query['placeholder']), - (hand.tourneyId, playerId, None, None, None, None, None, None)) + (hand.tourneyId, playerId, player[3], player[4], None, None, None, None)) elif source=="TS": #print "all values: tourneyId",hand.tourneyId, "playerId",playerId, "rank",hand.ranks[player], "winnings",hand.winnings[player], "winCurr",hand.winningsCurrency[player], hand.rebuyCounts[player], hand.addOnCounts[player], hand.koCounts[player] if hand.ranks[player]: diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 8cf8a8b4..a4e6935b 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -469,7 +469,7 @@ If a player has None chips he won't be added.""" log.debug("addPlayer: %s %s (%s)" % (seat, name, chips)) if chips is not None: chips = chips.replace(u',', u'') #some sites have commas - self.players.append([seat, name, chips]) + self.players.append([seat, name, chips, 0, 0]) self.stacks[name] = Decimal(chips) self.pot.addPlayer(name) for street in self.actionStreets: @@ -478,6 +478,17 @@ If a player has None chips he won't be added.""" #self.discards[name] = {} # dict from street names. + def addPlayerRank(self, name, winnings, rank): + """\ +name (string) player name +winnings (int) winnings +rank (int) rank the player finished the tournament""" + log.debug("addPlayerRank: %s %s (%s)" % (name, winnings, rank)) + for player in self.players: + if player[1] == name: + player[3]=rank + player[4]=winnings + def addStreets(self, match): # go through m and initialise actions to empty list for each street. if match: diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 294fa98e..ab821d38 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -159,6 +159,9 @@ class PokerStars(HandHistoryConverter): re_sitsOut = re.compile("^%s sits out" % short_subst['PLYR'], re.MULTILINE) re_ShownCards = re.compile("^Seat (?P[0-9]+): %s (\(.*\) )?(?Pshowed|mucked) \[(?P.*)\]( and won \([.\d]+\) with (?P.*))?" % short_subst['PLYR'], re.MULTILINE) re_CollectPot = re.compile(r"Seat (?P[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P[.\d]+)\)(, mucked| with.*|)" % short_subst, re.MULTILINE) + re_WinningRankOne = re.compile(u"^%(PLYR)s wins the tournament and receives %(CUR)s(?P[\.0-9]+) - congratulations!$" % short_subst, re.MULTILINE) + re_WinningRankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P[0-9]+)(st|nd|rd|th) place and received %(CUR)s(?P[.0-9]+)\.$" % short_subst, re.MULTILINE) + re_RankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P[0-9]+)(st|nd|rd|th) place$" % short_subst, re.MULTILINE) def compilePlayerRegexs(self, hand): pass @@ -453,6 +456,15 @@ class PokerStars(HandHistoryConverter): cards = shows.group('CARDS').split(' ') hand.addShownCards(cards, shows.group('PNAME')) + for winningrankone in self.re_WinningRankOne.finditer(hand.handText): + hand.addPlayerRank (winningrankone.group('PNAME'),int(100*Decimal(winningrankone.group('AMT'))),1) + + for winningrankothers in self.re_WinningRankOther.finditer(hand.handText): + hand.addPlayerRank (winningrankothers.group('PNAME'),int(100*Decimal(winningrankothers.group('AMT'))),winningrankothers.group('RANK')) + + for rankothers in self.re_RankOther.finditer(hand.handText): + hand.addPlayerRank (rankothers.group('PNAME'),0,rankothers.group('RANK')) + def readCollectPot(self,hand): for m in self.re_CollectPot.finditer(hand.handText): hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT'))