From 00f98f0e12e83e666a39d393276b299338bbfb9f Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Feb 2011 23:28:37 -0500 Subject: [PATCH 1/6] Hand.py: Use str.replace instead of re.sub for stripping commas. --- pyfpdb/Hand.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 1e3642aa..0bd08470 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -445,7 +445,7 @@ chips (string) the chips the player has at the start of the hand (can be None) 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 = re.sub(u',', u'', chips) #some sites have commas + chips = chips.replace(u',', u'') #some sites have commas self.players.append([seat, name, chips]) self.stacks[name] = Decimal(chips) self.pot.addPlayer(name) @@ -487,7 +487,7 @@ If a player has None chips he won't be added.""" For sites (currently only Carbon Poker) which record "all in" as a special action, which can mean either "calls and is all in" or "raises all in". """ self.checkPlayerExists(player) - amount = re.sub(u',', u'', amount) #some sites have commas + amount = amount.replace(u',', u'') #some sites have commas Ai = Decimal(amount) Bp = self.lastBet[street] Bc = reduce(operator.add, self.bets[street][player], 0) @@ -503,7 +503,7 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio def addAnte(self, player, ante): log.debug("%s %s antes %s" % ('BLINDSANTES', player, ante)) if player is not None: - ante = re.sub(u',', u'', ante) #some sites have commas + ante = ante.replace(u',', u'') #some sites have commas self.bets['BLINDSANTES'][player].append(Decimal(ante)) self.stacks[player] -= Decimal(ante) act = (player, 'ante', Decimal(ante), self.stacks[player]==0) @@ -522,7 +522,7 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio # log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount)) if player is not None: - amount = re.sub(u',', u'', amount) #some sites have commas + amount = amount.replace(u',', u'') #some sites have commas self.stacks[player] -= Decimal(amount) act = (player, blindtype, Decimal(amount), self.stacks[player]==0) self.actions['BLINDSANTES'].append(act) @@ -555,7 +555,7 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio def addCall(self, street, player=None, amount=None): if amount: - amount = re.sub(u',', u'', amount) #some sites have commas + amount = amount.replace(u',', u'') #some sites have commas log.debug(_("%s %s calls %s") %(street, player, amount)) # Potentially calculate the amount of the call if not supplied # corner cases include if player would be all in @@ -583,7 +583,7 @@ Add a raise by amountBy on [street] by [player] # then: C = Bp - Bc (amount to call) # Rt = Bp + Rb (raise to) # - amountBy = re.sub(u',', u'', amountBy) #some sites have commas + amountBy = amountBy.replace(u',', u'') #some sites have commas self.checkPlayerExists(player) Rb = Decimal(amountBy) Bp = self.lastBet[street] @@ -601,7 +601,7 @@ Add a raise by amountBy on [street] by [player] """\ For sites which by "raises x" mean "calls and raises putting a total of x in the por". """ self.checkPlayerExists(player) - amount = re.sub(u',', u'', amount) #some sites have commas + amount = amount.replace(u',', u'') #some sites have commas CRb = Decimal(amount) Bp = self.lastBet[street] Bc = reduce(operator.add, self.bets[street][player], 0) @@ -617,7 +617,7 @@ Add a raise on [street] by [player] to [amountTo] """ #CG - No idea if this function has been test/verified self.checkPlayerExists(player) - amountTo = re.sub(u',', u'', amountTo) #some sites have commas + amountTo = amountTo.replace(u',', u'') #some sites have commas Bp = self.lastBet[street] Bc = reduce(operator.add, self.bets[street][player], 0) Rt = Decimal(amountTo) @@ -638,7 +638,7 @@ Add a raise on [street] by [player] to [amountTo] def addBet(self, street, player, amount): log.debug(_("%s %s bets %s") %(street, player, amount)) - amount = re.sub(u',', u'', amount) #some sites have commas + amount = amount.replace(u',', u'') #some sites have commas self.checkPlayerExists(player) self.bets[street][player].append(Decimal(amount)) self.stacks[player] -= Decimal(amount) @@ -1377,7 +1377,7 @@ closed likewise, but known only to player Add a complete on [street] by [player] to [amountTo] """ log.debug(_("%s %s completes %s") % (street, player, amountTo)) - amountTo = re.sub(u',', u'', amountTo) #some sites have commas + amountTo = amountTo.replace(u',', u'') #some sites have commas self.checkPlayerExists(player) Bp = self.lastBet['THIRD'] Bc = reduce(operator.add, self.bets[street][player], 0) From 1227c5df740780aed446739577255f8aeb48e927 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Feb 2011 23:31:46 -0500 Subject: [PATCH 2/6] Hand.py: Use sum(x) instead of reduce(operator.add, x, 0). --- pyfpdb/Hand.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 0bd08470..50886a9e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -490,7 +490,7 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio amount = amount.replace(u',', u'') #some sites have commas Ai = Decimal(amount) Bp = self.lastBet[street] - Bc = reduce(operator.add, self.bets[street][player], 0) + Bc = sum(self.bets[street][player]) C = Bp - Bc if Ai <= C: self.addCall(street, player, amount) @@ -587,7 +587,7 @@ Add a raise by amountBy on [street] by [player] self.checkPlayerExists(player) Rb = Decimal(amountBy) Bp = self.lastBet[street] - Bc = reduce(operator.add, self.bets[street][player], 0) + Bc = sum(self.bets[street][player]) C = Bp - Bc Rt = Bp + Rb @@ -604,7 +604,7 @@ For sites which by "raises x" mean "calls and raises putting a total of x in the amount = amount.replace(u',', u'') #some sites have commas CRb = Decimal(amount) Bp = self.lastBet[street] - Bc = reduce(operator.add, self.bets[street][player], 0) + Bc = sum(self.bets[street][player]) C = Bp - Bc Rb = CRb - C Rt = Bp + Rb @@ -619,7 +619,7 @@ Add a raise on [street] by [player] to [amountTo] self.checkPlayerExists(player) amountTo = amountTo.replace(u',', u'') #some sites have commas Bp = self.lastBet[street] - Bc = reduce(operator.add, self.bets[street][player], 0) + Bc = sum(self.bets[street][player]) Rt = Decimal(amountTo) C = Bp - Bc Rb = Rt - C - Bc @@ -1380,7 +1380,7 @@ Add a complete on [street] by [player] to [amountTo] amountTo = amountTo.replace(u',', u'') #some sites have commas self.checkPlayerExists(player) Bp = self.lastBet['THIRD'] - Bc = reduce(operator.add, self.bets[street][player], 0) + Bc = sum(self.bets[street][player]) Rt = Decimal(amountTo) C = Bp - Bc Rb = Rt - C From cdf158cfae08ab33f98a6c1abacf4f6d7d8cd79c Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Feb 2011 23:41:14 -0500 Subject: [PATCH 3/6] Hand.py: Call Decimal ctor a lot less. --- pyfpdb/Hand.py | 67 ++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 50886a9e..6e642c20 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -504,12 +504,13 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio log.debug("%s %s antes %s" % ('BLINDSANTES', player, ante)) if player is not None: ante = ante.replace(u',', u'') #some sites have commas - self.bets['BLINDSANTES'][player].append(Decimal(ante)) - self.stacks[player] -= Decimal(ante) - act = (player, 'ante', Decimal(ante), self.stacks[player]==0) + ante = Decimal(ante) + self.bets['BLINDSANTES'][player].append(ante) + self.stacks[player] -= ante + act = (player, 'ante', ante, self.stacks[player]==0) self.actions['BLINDSANTES'].append(act) -# self.pot.addMoney(player, Decimal(ante)) - self.pot.addCommonMoney(player, Decimal(ante)) +# self.pot.addMoney(player, ante) + self.pot.addCommonMoney(player, ante) #I think the antes should be common money, don't have enough hand history to check def addBlind(self, player, blindtype, amount): @@ -523,21 +524,24 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount)) if player is not None: amount = amount.replace(u',', u'') #some sites have commas - self.stacks[player] -= Decimal(amount) - act = (player, blindtype, Decimal(amount), self.stacks[player]==0) + amount = Decimal(amount) + self.stacks[player] -= amount + act = (player, blindtype, amount, self.stacks[player]==0) self.actions['BLINDSANTES'].append(act) if blindtype == 'both': # work with the real amount. limit games are listed as $1, $2, where # the SB 0.50 and the BB is $1, after the turn the minimum bet amount is $2.... - amount = self.bb - self.bets['BLINDSANTES'][player].append(Decimal(self.sb)) - self.pot.addCommonMoney(player, Decimal(self.sb)) + amount = Decimal(self.bb) + sb = Decimal(self.sb) + self.bets['BLINDSANTES'][player].append(sb) + self.pot.addCommonMoney(player, sb) if blindtype == 'secondsb': amount = Decimal(0) - self.bets['BLINDSANTES'][player].append(Decimal(self.sb)) - self.pot.addCommonMoney(player, Decimal(self.sb)) + sb = Decimal(self.sb) + self.bets['BLINDSANTES'][player].append(sb) + self.pot.addCommonMoney(player, sb) street = 'BLAH' @@ -546,9 +550,9 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio elif self.gametype['base'] == 'draw': street = 'DEAL' - self.bets[street][player].append(Decimal(amount)) - self.pot.addMoney(player, Decimal(amount)) - self.lastBet[street] = Decimal(amount) + self.bets[street][player].append(amount) + self.pot.addMoney(player, amount) + self.lastBet[street] = amount self.posted = self.posted + [[player,blindtype]] @@ -560,13 +564,14 @@ For sites (currently only Carbon Poker) which record "all in" as a special actio # Potentially calculate the amount of the call if not supplied # corner cases include if player would be all in if amount is not None: - self.bets[street][player].append(Decimal(amount)) - #self.lastBet[street] = Decimal(amount) - self.stacks[player] -= Decimal(amount) + amount = Decimal(amount) + self.bets[street][player].append(amount) + #self.lastBet[street] = amount + self.stacks[player] -= amount #print "DEBUG %s calls %s, stack %s" % (player, amount, self.stacks[player]) - act = (player, 'calls', Decimal(amount), self.stacks[player]==0) + act = (player, 'calls', amount, self.stacks[player] == 0) self.actions[street].append(act) - self.pot.addMoney(player, Decimal(amount)) + self.pot.addMoney(player, amount) def addRaiseBy(self, street, player, amountBy): """\ @@ -639,14 +644,15 @@ Add a raise on [street] by [player] to [amountTo] def addBet(self, street, player, amount): log.debug(_("%s %s bets %s") %(street, player, amount)) amount = amount.replace(u',', u'') #some sites have commas + amount = Decimal(amount) self.checkPlayerExists(player) - self.bets[street][player].append(Decimal(amount)) - self.stacks[player] -= Decimal(amount) + self.bets[street][player].append(amount) + self.stacks[player] -= amount #print "DEBUG %s bets %s, stack %s" % (player, amount, self.stacks[player]) - act = (player, 'bets', Decimal(amount), self.stacks[player]==0) + act = (player, 'bets', amount, self.stacks[player]==0) self.actions[street].append(act) - self.lastBet[street] = Decimal(amount) - self.pot.addMoney(player, Decimal(amount)) + self.lastBet[street] = amount + self.pot.addMoney(player, amount) def addStandsPat(self, street, player): @@ -1395,12 +1401,13 @@ Add a complete on [street] by [player] to [amountTo] def addBringIn(self, player, bringin): if player is not None: log.debug(_("Bringin: %s, %s") % (player , bringin)) - self.bets['THIRD'][player].append(Decimal(bringin)) - self.stacks[player] -= Decimal(bringin) - act = (player, 'bringin', Decimal(bringin), self.stacks[player]==0) + bringin = Decimal(bringin) + self.bets['THIRD'][player].append(bringin) + self.stacks[player] -= bringin + act = (player, 'bringin', bringin, self.stacks[player]==0) self.actions['THIRD'].append(act) - self.lastBet['THIRD'] = Decimal(bringin) - self.pot.addMoney(player, Decimal(bringin)) + self.lastBet['THIRD'] = bringin + self.pot.addMoney(player, bringin) def getStreetTotals(self): # street1Pot INT, /* pot size at flop/street4 */ From bf417f05695fe5bfd123568039edc74f2dcdcf5d Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 24 Feb 2011 00:27:43 -0500 Subject: [PATCH 4/6] Filters.py: Fix broken show/hide button for Graphing Options. --- pyfpdb/Filters.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index 557bb846..632f71ab 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -829,11 +829,16 @@ class Filters(threading.Thread): top_hbox.pack_start(title, expand=True, padding=3) showb = gtk.Button(label="hide", stock=None, use_underline=True) showb.set_alignment(xalign=1.0, yalign=0.5) - showb.connect('clicked', self.__toggle_box, 'games') + showb.connect('clicked', self.__toggle_box, 'graphops') top_hbox.pack_start(showb, expand=False, padding=1) + vbox1 = gtk.VBox(False, 0) + vbox.pack_start(vbox1, False, False, 0) + vbox1.show() + self.boxes['graphops'] = vbox1 + hbox1 = gtk.HBox(False, 0) - vbox.pack_start(hbox1, False, False, 0) + vbox1.pack_start(hbox1, False, False, 0) hbox1.show() label = gtk.Label(_("Show Graph In:")) @@ -852,10 +857,6 @@ class Filters(threading.Thread): button.connect("toggled", self.__set_displayin_select, "BB") button.show() - vbox1 = gtk.VBox(False, 0) - vbox.pack_start(vbox1, False, False, 0) - vbox1.show() - button = gtk.CheckButton(_("Showdown Winnings"), False) vbox1.pack_start(button, True, True, 0) # wouldn't it be awesome if there was a way to remember the state of things like From f64c28b1b46855236fbae41fae4644e55087b681 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 25 Feb 2011 03:10:29 -0500 Subject: [PATCH 5/6] small wrapper to use cdecimal library if available. --- pyfpdb/decimal.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pyfpdb/decimal.py diff --git a/pyfpdb/decimal.py b/pyfpdb/decimal.py new file mode 100644 index 00000000..e5202d92 --- /dev/null +++ b/pyfpdb/decimal.py @@ -0,0 +1,4 @@ +try: + from cdecimal import * +except ImportError: + from decimal import * From 6e3abbbb0a6dcd4738900617a61f53d3fbb8a65b Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 25 Feb 2011 03:41:42 -0500 Subject: [PATCH 6/6] DerivedStats: build init dict for player stats only once. --- pyfpdb/DerivedStats.py | 129 +++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 62 deletions(-) diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index 654e6001..93c09571 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -30,71 +30,76 @@ class DerivedStats(): self.hands = {} self.handsplayers = {} self.handsactions = {} + self._initStats = DerivedStats._buildStatsInitializer() + + @staticmethod + def _buildStatsInitializer(): + init = {} + #Init vars that may not be used, but still need to be inserted. + # All stud street4 need this when importing holdem + init['winnings'] = 0 + init['rake'] = 0 + init['totalProfit'] = 0 + init['street4Aggr'] = False + init['wonWhenSeenStreet1'] = 0.0 + init['sawShowdown'] = False + init['wonAtSD'] = 0.0 + init['startCards'] = 0 + init['position'] = 2 + init['street0_3BChance'] = False + init['street0_3BDone'] = False + init['street0_4BChance'] = False + init['street0_4BDone'] = False + init['street0_C4BChance'] = False + init['street0_C4BDone'] = False + init['street0_FoldTo3BChance']= False + init['street0_FoldTo3BDone']= False + init['street0_FoldTo4BChance']= False + init['street0_FoldTo4BDone']= False + init['street0_SqueezeChance']= False + init['street0_SqueezeDone'] = False + init['success_Steal'] = False + init['raiseFirstInChance'] = False + init['raisedFirstIn'] = False + init['foldBbToStealChance'] = False + init['foldSbToStealChance'] = False + init['foldedSbToSteal'] = False + init['foldedBbToSteal'] = False + init['tourneyTypeId'] = None + init['street1Seen'] = False + init['street2Seen'] = False + init['street3Seen'] = False + init['street4Seen'] = False + + + for i in range(5): + init['street%dCalls' % i] = 0 + init['street%dBets' % i] = 0 + init['street%dRaises' % i] = 0 + for i in range(1,5): + init['street%dCBChance' %i] = False + init['street%dCBDone' %i] = False + init['street%dCheckCallRaiseChance' %i] = False + init['street%dCheckCallRaiseDone' %i] = False + init['otherRaisedStreet%d' %i] = False + init['foldToOtherRaisedStreet%d' %i] = False + + #FIXME - Everything below this point is incomplete. + init['other3BStreet0'] = False + init['other4BStreet0'] = False + init['otherRaisedStreet0'] = False + init['foldToOtherRaisedStreet0'] = False + for i in range(1,5): + init['foldToStreet%dCBChance' %i] = False + init['foldToStreet%dCBDone' %i] = False + init['wonWhenSeenStreet2'] = 0.0 + init['wonWhenSeenStreet3'] = 0.0 + init['wonWhenSeenStreet4'] = 0.0 + return init def getStats(self, hand): - for player in hand.players: - self.handsplayers[player[1]] = {} - #Init vars that may not be used, but still need to be inserted. - # All stud street4 need this when importing holdem - self.handsplayers[player[1]]['winnings'] = 0 - self.handsplayers[player[1]]['rake'] = 0 - self.handsplayers[player[1]]['totalProfit'] = 0 - self.handsplayers[player[1]]['street4Aggr'] = False - self.handsplayers[player[1]]['wonWhenSeenStreet1'] = 0.0 - self.handsplayers[player[1]]['sawShowdown'] = False - self.handsplayers[player[1]]['wonAtSD'] = 0.0 - self.handsplayers[player[1]]['startCards'] = 0 - self.handsplayers[player[1]]['position'] = 2 - self.handsplayers[player[1]]['street0_3BChance'] = False - self.handsplayers[player[1]]['street0_3BDone'] = False - self.handsplayers[player[1]]['street0_4BChance'] = False - self.handsplayers[player[1]]['street0_4BDone'] = False - self.handsplayers[player[1]]['street0_C4BChance'] = False - self.handsplayers[player[1]]['street0_C4BDone'] = False - self.handsplayers[player[1]]['street0_FoldTo3BChance']= False - self.handsplayers[player[1]]['street0_FoldTo3BDone']= False - self.handsplayers[player[1]]['street0_FoldTo4BChance']= False - self.handsplayers[player[1]]['street0_FoldTo4BDone']= False - self.handsplayers[player[1]]['street0_SqueezeChance']= False - self.handsplayers[player[1]]['street0_SqueezeDone'] = False - self.handsplayers[player[1]]['success_Steal'] = False - self.handsplayers[player[1]]['raiseFirstInChance'] = False - self.handsplayers[player[1]]['raisedFirstIn'] = False - self.handsplayers[player[1]]['foldBbToStealChance'] = False - self.handsplayers[player[1]]['foldSbToStealChance'] = False - self.handsplayers[player[1]]['foldedSbToSteal'] = False - self.handsplayers[player[1]]['foldedBbToSteal'] = False - self.handsplayers[player[1]]['tourneyTypeId'] = None - self.handsplayers[player[1]]['street1Seen'] = False - self.handsplayers[player[1]]['street2Seen'] = False - self.handsplayers[player[1]]['street3Seen'] = False - self.handsplayers[player[1]]['street4Seen'] = False - - - for i in range(5): - self.handsplayers[player[1]]['street%dCalls' % i] = 0 - self.handsplayers[player[1]]['street%dBets' % i] = 0 - self.handsplayers[player[1]]['street%dRaises' % i] = 0 - for i in range(1,5): - self.handsplayers[player[1]]['street%dCBChance' %i] = False - self.handsplayers[player[1]]['street%dCBDone' %i] = False - self.handsplayers[player[1]]['street%dCheckCallRaiseChance' %i] = False - self.handsplayers[player[1]]['street%dCheckCallRaiseDone' %i] = False - self.handsplayers[player[1]]['otherRaisedStreet%d' %i] = False - self.handsplayers[player[1]]['foldToOtherRaisedStreet%d' %i] = False - - #FIXME - Everything below this point is incomplete. - self.handsplayers[player[1]]['other3BStreet0'] = False - self.handsplayers[player[1]]['other4BStreet0'] = False - self.handsplayers[player[1]]['otherRaisedStreet0'] = False - self.handsplayers[player[1]]['foldToOtherRaisedStreet0'] = False - for i in range(1,5): - self.handsplayers[player[1]]['foldToStreet%dCBChance' %i] = False - self.handsplayers[player[1]]['foldToStreet%dCBDone' %i] = False - self.handsplayers[player[1]]['wonWhenSeenStreet2'] = 0.0 - self.handsplayers[player[1]]['wonWhenSeenStreet3'] = 0.0 - self.handsplayers[player[1]]['wonWhenSeenStreet4'] = 0.0 + self.handsplayers[player[1]] = self._initStats.copy() self.assembleHands(self.hand) self.assembleHandsPlayers(self.hand)