Merge branch 'master' into hudfix

This commit is contained in:
Mika Bostrom 2009-11-25 14:41:01 +02:00
commit 9e23346e5b
4 changed files with 101 additions and 25 deletions

View File

@ -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,
@ -1663,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
@ -1702,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))

View File

@ -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

View File

@ -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 """

View File

@ -64,5 +64,4 @@ def testSQLiteModFunction():
assert vars[idx]%13 == int(i[0])
idx = idx+1
assert 0 == 1
cur.execute("DROP TABLE test")