Hand: Start select() method

Can currently add the players in the hand. Still a long way to go, but a good start
This commit is contained in:
Worros 2010-12-17 19:03:50 +08:00
parent 20c5ecee82
commit 70c3480105

View File

@ -282,75 +282,10 @@ db: a connected Database object"""
def updateSessionsCache(self, db): def updateSessionsCache(self, db):
db.storeSessionsCache(self.dbid_pids, self.startTime, self.gametype, self.stats.getHandsPlayers()) db.storeSessionsCache(self.dbid_pids, self.startTime, self.gametype, self.stats.getHandsPlayers())
def select(self, handId): def select(self, db, handId):
""" Function to create Hand object from database """ """ Function to create Hand object from database """
c = cnxn.cursor() c = db.get_cursor()
q = """SELECT
# We need at least sitename, gametype, handid
# for the Hand.__init__
c.execute("""SELECT
s.name,
g.category,
g.base,
g.type,
g.limitType,
g.hilo,
round(g.smallBlind / 100.0,2),
round(g.bigBlind / 100.0,2),
round(g.smallBet / 100.0,2),
round(g.bigBet / 100.0,2),
s.currency,
h.boardcard1,
h.boardcard2,
h.boardcard3,
h.boardcard4,
h.boardcard5
FROM
hands as h,
sites as s,
gametypes as g,
handsplayers as hp,
players as p
WHERE
h.id = %(handid)s
and g.id = h.gametypeid
and hp.handid = h.id
and p.id = hp.playerid
and s.id = p.siteid
limit 1""", {'handid':handid})
#TODO: siteid should be in hands table - we took the scenic route through players here.
res = c.fetchone()
gametype = {'category':res[1],'base':res[2],'type':res[3],'limitType':res[4],'hilo':res[5],'sb':res[6],'bb':res[7], 'currency':res[10]}
c = Configuration.Config()
h = HoldemOmahaHand(config = c, hhc = None, sitename=res[0], gametype = gametype, handText=None, builtFrom = "DB", handid=handid)
cards = map(Card.valueSuitFromCard, res[11:16] )
if cards[0]:
h.setCommunityCards('FLOP', cards[0:3])
if cards[3]:
h.setCommunityCards('TURN', [cards[3]])
if cards[4]:
h.setCommunityCards('RIVER', [cards[4]])
#[Card.valueSuitFromCard(x) for x in cards]
# HandInfo : HID, TABLE
# BUTTON - why is this treated specially in Hand?
# answer: it is written out in hand histories
# still, I think we should record all the active seat positions in a seat_order array
c.execute("""SELECT
h.sitehandno as hid,
h.tablename as table,
h.startTime as startTime
FROM
hands as h
WHERE h.id = %(handid)s
""", {'handid':handid})
res = c.fetchone()
h.handid = res[0]
h.tablename = res[1]
h.startTime = res[2] # automatically a datetime
# PlayerStacks
c.execute("""SELECT
hp.seatno, hp.seatno,
round(hp.winnings / 100.0,2) as winnings, round(hp.winnings / 100.0,2) as winnings,
p.name, p.name,
@ -358,69 +293,101 @@ db: a connected Database object"""
hp.card1,hp.card2, hp.card1,hp.card2,
hp.position hp.position
FROM FROM
handsplayers as hp, HandsPlayers as hp,
players as p Players as p
WHERE WHERE
hp.handid = %(handid)s hp.handId = %s
and p.id = hp.playerid and p.id = hp.playerid
""", {'handid':handid}) """
q = q.replace('%s', db.sql.query['placeholder'])
# PlayerStacks
c.execute(q, (handId,))
for (seat, winnings, name, chips, card1,card2, position) in c.fetchall(): for (seat, winnings, name, chips, card1,card2, position) in c.fetchall():
h.addPlayer(seat,name,chips) print "DEBUG: seat: '%s'\tname: '%s'\tchips: '%s'" % (seat, name, chips)
if card1 and card2: self.addPlayer(seat,name,str(chips))
h.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)), name, dealt=True) #if card1 and card2:
if winnings > 0: # self.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)), name, dealt=True)
h.addCollectPot(name, winnings) #if winnings > 0:
if position == 'B': # self.addCollectPot(name, winnings)
h.buttonpos = seat #if position == 'B':
# self.buttonpos = seat
# HandInfo : HID, TABLE
# BUTTON - why is this treated specially in Hand?
# answer: it is written out in hand histories
# still, I think we should record all the active seat positions in a seat_order array
#c.execute("""SELECT
# h.sitehandno as hid,
# h.tablename as table,
# h.startTime as startTime
# FROM
# Hands as h
# WHERE h.id = %(handid)s
# """, {'handid':handid})
#res = c.fetchone()
#h.handid = res[0]
#h.tablename = res[1]
#h.startTime = res[2] # automatically a datetime
#cards = map(Card.valueSuitFromCard, res[11:16] )
#if cards[0]:
# h.setCommunityCards('FLOP', cards[0:3])
#if cards[3]:
# h.setCommunityCards('TURN', [cards[3]])
#if cards[4]:
# h.setCommunityCards('RIVER', [cards[4]])
#[Card.valueSuitFromCard(x) for x in cards]
# actions # actions
c.execute("""SELECT #c.execute("""SELECT
(ha.street,ha.actionno) as actnum, # (ha.street,ha.actionno) as actnum,
p.name, # p.name,
ha.street, # ha.street,
ha.action, # ha.action,
ha.allin, # ha.allin,
round(ha.amount / 100.0,2) # round(ha.amount / 100.0,2)
FROM # FROM
handsplayers as hp, # handsplayers as hp,
handsactions as ha, # handsactions as ha,
players as p # players as p
WHERE # WHERE
hp.handid = %(handid)s # hp.handid = %(handid)s
and ha.handsplayerid = hp.id # and ha.handsplayerid = hp.id
and p.id = hp.playerid # and p.id = hp.playerid
ORDER BY # ORDER BY
ha.street,ha.actionno # ha.street,ha.actionno
""", {'handid':handid}) # """, {'handid':handid})
res = c.fetchall() #res = c.fetchall()
for (actnum,player, streetnum, act, allin, amount) in res: #for (actnum,player, streetnum, act, allin, amount) in res:
act=act.strip() # act=act.strip()
street = h.allStreets[streetnum+1] # street = h.allStreets[streetnum+1]
if act==u'blind': # if act==u'blind':
h.addBlind(player, 'big blind', amount) # h.addBlind(player, 'big blind', amount)
# TODO: The type of blind is not recorded in the DB. # # TODO: The type of blind is not recorded in the DB.
# TODO: preflop street name anomalies in Hand # # TODO: preflop street name anomalies in Hand
elif act==u'fold': # elif act==u'fold':
h.addFold(street,player) # h.addFold(street,player)
elif act==u'call': # elif act==u'call':
h.addCall(street,player,amount) # h.addCall(street,player,amount)
elif act==u'bet': # elif act==u'bet':
h.addBet(street,player,amount) # h.addBet(street,player,amount)
elif act==u'check': # elif act==u'check':
h.addCheck(street,player) # h.addCheck(street,player)
elif act==u'unbet': # elif act==u'unbet':
pass # pass
else: # else:
print act, player, streetnum, allin, amount # print act, player, streetnum, allin, amount
# TODO : other actions # # TODO : other actions
#hhc.readShowdownActions(self) #hhc.readShowdownActions(self)
#hc.readShownCards(self) #hc.readShownCards(self)
h.totalPot() #h.totalPot()
h.rake = h.totalpot - h.totalcollected #h.rake = h.totalpot - h.totalcollected
return h
def addPlayer(self, seat, name, chips): def addPlayer(self, seat, name, chips):
"""\ """\
@ -853,10 +820,11 @@ class HoldemOmahaHand(Hand):
hhc.readOther(self) hhc.readOther(self)
#print "\nHand:\n"+str(self) #print "\nHand:\n"+str(self)
elif builtFrom == "DB": elif builtFrom == "DB":
if handid is not None: #if handid is not None:
self.select(handid) # Will need a handId # self.select(handid) # Will need a handId
else: #else:
log.warning(_("HoldemOmahaHand.__init__:Can't assemble hand from db without a handid")) # log.warning(_("HoldemOmahaHand.__init__:Can't assemble hand from db without a handid"))
print "DEBUG: HoldemOmaha hand initialised for select()"
else: else:
log.warning(_("HoldemOmahaHand.__init__:Neither HHC nor DB+handid provided")) log.warning(_("HoldemOmahaHand.__init__:Neither HHC nor DB+handid provided"))
pass pass