From 30332d213265602db8004016c17eb3b0d193aec4 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 25 Nov 2009 10:27:54 +0800 Subject: [PATCH 1/3] Remove forced assert --- pyfpdb/test_Database.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyfpdb/test_Database.py b/pyfpdb/test_Database.py index b348f741..25bd6dbc 100644 --- a/pyfpdb/test_Database.py +++ b/pyfpdb/test_Database.py @@ -64,5 +64,4 @@ def testSQLiteModFunction(): assert vars[idx]%13 == int(i[0]) idx = idx+1 - assert 0 == 1 cur.execute("DROP TABLE test") From 83f06c35cc5005c3fd2fefb601ab7abb66789044 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 25 Nov 2009 14:59:29 +0800 Subject: [PATCH 2/3] [NEWIMPORT] HandsPlayers.CBet stats --- pyfpdb/Database.py | 27 ++++++++++++++-------- pyfpdb/DerivedStats.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 9f214aeb..fde03b71 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1409,6 +1409,14 @@ class Database: pdata[p]['street2Aggr'], pdata[p]['street3Aggr'], pdata[p]['street4Aggr'], + pdata[p]['street1CBChance'], + pdata[p]['street2CBChance'], + pdata[p]['street3CBChance'], + pdata[p]['street4CBChance'], + pdata[p]['street1CBDone'], + pdata[p]['street2CBDone'], + pdata[p]['street3CBDone'], + pdata[p]['street4CBDone'], pdata[p]['wonWhenSeenStreet1'], pdata[p]['street0Calls'], pdata[p]['street1Calls'], @@ -1449,6 +1457,14 @@ class Database: street2Aggr, street3Aggr, street4Aggr, + street1CBChance, + street2CBChance, + street3CBChance, + street4CBChance, + street1CBDone, + street2CBDone, + street3CBDone, + street4CBDone, wonWhenSeenStreet1, street0Calls, street1Calls, @@ -1462,7 +1478,8 @@ class Database: street4Bets ) VALUES ( - %s, %s, + %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, @@ -1491,14 +1508,6 @@ class Database: # foldedBbToSteal, # foldSbToStealChance, # foldedSbToSteal, -# street1CBChance, -# street1CBDone, -# street2CBChance, -# street2CBDone, -# street3CBChance, -# street3CBDone, -# street4CBChance, -# street4CBDone, # foldToStreet1CBChance, # foldToStreet1CBDone, # foldToStreet2CBChance, diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index 3da670cc..c5575ddc 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -49,10 +49,14 @@ class DerivedStats(): for i in range(5): self.handsplayers[player[1]]['street%dCalls' % i] = 0 self.handsplayers[player[1]]['street%dBets' % 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.assembleHands(self.hand) self.assembleHandsPlayers(self.hand) + if DEBUG: print "Hands:" pp.pprint(self.hands) @@ -137,6 +141,8 @@ class DerivedStats(): for player in hand.pot.committed: self.handsplayers[player]['totalProfit'] = int(self.handsplayers[player]['winnings'] - (100*hand.pot.committed[player])) + self.calcCBets(hand) + #default_holecards = ["Xx", "Xx", "Xx", "Xx"] #if hand.gametype['base'] == "hold": # pass @@ -221,6 +227,20 @@ class DerivedStats(): for (i, street) in enumerate(hand.actionStreets[1:]): self.hands['street%dRaises' % i] = len(filter( lambda action: action[1] in ('raises','bets'), hand.actions[street])) + def calcCBets(self, hand): + # Continuation Bet chance, action: + # Had the last bet (initiative) on previous street, got called, close street action + # Then no bets before the player with initiatives first action on current street + # ie. if player on street-1 had initiative + # and no donkbets occurred + for i, street in enumerate(hand.actionStreets[2:], start=1): + name = self.lastBetOrRaiser(hand.actionStreets[i]) + if name: + chance = self.noBetsBefore(hand.actionStreets[i+1], name) + self.handsplayers[name]['street%dCBChance' %i] = True + if chance == True: + self.handsplayers[name]['street%dCBDone' %i] = self.betStreet(hand.actionStreets[i+1], name) + def seen(self, hand, i): pas = set() for act in hand.actions[hand.actionStreets[i+1]]: @@ -273,3 +293,35 @@ class DerivedStats(): if f is not None and action[1] in f: continue players.add(action[0]) return players + + def noBetsBefore(self, street, player): + """Returns true if there were no bets before the specified players turn, false otherwise""" + betOrRaise = False + for act in self.hand.actions[street]: + #Must test for player first in case UTG + if act[0] == player: + betOrRaise = True + break + if act[1] in ('bets', 'raises'): + break + return betOrRaise + + def betStreet(self, street, player): + """Returns true if player bet/raised the street as their first action""" + betOrRaise = False + for act in self.hand.actions[street]: + if act[0] == player and act[1] in ('bets', 'raises'): + betOrRaise = True + else: + break + return betOrRaise + + + def lastBetOrRaiser(self, street): + """Returns player name that placed the last bet or raise for that street. + None if there were no bets or raises on that street""" + lastbet = None + for act in self.hand.actions[street]: + if act[1] in ('bets', 'raises'): + lastbet = act[0] + return lastbet From aee9a7339c60d023d7f335fe935f021ca29da838 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 25 Nov 2009 16:29:30 +0800 Subject: [PATCH 3/3] [NEWIMPORT] Stop duplicate hands from crashing import --- pyfpdb/Database.py | 16 ++++++++++++++++ pyfpdb/Hand.py | 30 +++++++++++++++--------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index fde03b71..42cd986c 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1672,6 +1672,15 @@ class Database: # street4CheckCallRaiseChance, # street4CheckCallRaiseDone) + def isDuplicate(self, gametypeID, siteHandNo): + dup = False + c = self.get_cursor() + c.execute(self.sql.query['isAlreadyInDB'], (gametypeID, siteHandNo)) + result = c.fetchall() + if len(result) > 0: + dup = True + return dup + def getGameTypeId(self, siteid, game): c = self.get_cursor() #FIXME: Fixed for NL at the moment @@ -1711,6 +1720,13 @@ class Database: q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s" q = q.replace('%s', self.sql.query['placeholder']) + #NOTE/FIXME?: MySQL has ON DUPLICATE KEY UPDATE + #Usage: + # INSERT INTO `tags` (`tag`, `count`) + # VALUES ($tag, 1) + # ON DUPLICATE KEY UPDATE `count`=`count`+1; + + #print "DEBUG: name: %s site: %s" %(name, site_id) c.execute (q, (site_id, name)) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index a5ea87ec..f6fa478e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -210,24 +210,24 @@ db: a connected fpdb_db object""" ##### # End prep functions ##### - - # HandsActions - all actions for all players for all streets - self.actions - # HudCache data can be generated from HandsActions (HandsPlayers?) - - # Hands - Summary information of hand indexed by handId - gameinfo hh = self.stats.getHands() - hh['gameTypeId'] = gtid - # seats TINYINT NOT NULL, - hh['seats'] = len(sqlids) - #print hh - handid = db.storeHand(hh) - # HandsPlayers - ? ... Do we fix winnings? - db.storeHandsPlayers(handid, sqlids, self.stats.getHandsPlayers()) - # Tourneys ? - # TourneysPlayers + if not db.isDuplicate(gtid, hh['siteHandNo']): + # Hands - Summary information of hand indexed by handId - gameinfo + hh['gameTypeId'] = gtid + # seats TINYINT NOT NULL, + hh['seats'] = len(sqlids) - pass + handid = db.storeHand(hh) + db.storeHandsPlayers(handid, sqlids, self.stats.getHandsPlayers()) + # HandsActions - all actions for all players for all streets - self.actions + # HudCache data can be generated from HandsActions (HandsPlayers?) + # Tourneys ? + # TourneysPlayers + else: + log.info("Hand.insert(): hid #: %s is a duplicate" % hh['siteHandNo']) + #Raise Duplicate exception? + pass def select(self, handId): """ Function to create Hand object from database """