Hand: First pass at select() for Hand

This commit is contained in:
Worros 2010-12-22 12:13:58 +08:00
parent 797c126318
commit 10fc52e96f

View File

@ -289,99 +289,109 @@ db: a connected Database object"""
hp.seatno,
round(hp.winnings / 100.0,2) as winnings,
p.name,
round(hp.startcash / 100.0,2) as chips,
hp.card1,hp.card2,
round(hp.startCash / 100.0,2) as chips,
hp.card1,hp.card2,hp.card3,hp.card4,
hp.position
FROM
HandsPlayers as hp,
Players as p
WHERE
hp.handId = %s
and p.id = hp.playerid
and p.id = hp.playerId
"""
q = q.replace('%s', db.sql.query['placeholder'])
# PlayerStacks
c.execute(q, (handId,))
for (seat, winnings, name, chips, card1,card2, position) in c.fetchall():
print "DEBUG: seat: '%s'\tname: '%s'\tchips: '%s'" % (seat, name, chips)
for (seat, winnings, name, chips, card1, card2, card3, card4, position) in c.fetchall():
self.addPlayer(seat,name,str(chips))
#if card1 and card2:
# self.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)), name, dealt=True)
#if winnings > 0:
# self.addCollectPot(name, winnings)
#if position == 'B':
# self.buttonpos = seat
cardlist = map(Card.valueSuitFromCard, [card1, card2, card3, card4])
cardlist = [card1, card2, card3, card4]
self.addHoleCards('PREFLOP', name, closed=cardlist, shown=False, mucked=False, dealt=True)
if winnings > 0:
self.addCollectPot(name, str(winnings))
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
# HandInfo
q = """SELECT *
FROM Hands
WHERE id = %s
"""
q = q.replace('%s', db.sql.query['placeholder'])
c.execute(q, (handId,))
# NOTE: This relies on row_factory = sqlite3.Row (set in connect() params)
# Need to find MySQL and Postgres equivalents
# MySQL maybe: cursorclass=MySQLdb.cursors.DictCursor
res = c.fetchone()
self.tablename = res['tableName']
self.startTime = res['startTime'] # automatically a datetime
#res['tourneyId']
#gametypeId
#res['importTime'] # Don't really care about this
#res['seats']
self.maxseats = res['maxSeats']
#res['rush']
cards = map(Card.valueSuitFromCard, [res['boardcard1'], res['boardcard2'], res['boardcard3'], res['boardcard4'], res['boardcard5']])
if cards[0]:
self.setCommunityCards('FLOP', cards[0:3])
if cards[3]:
self.setCommunityCards('TURN', [cards[3]])
if cards[4]:
self.setCommunityCards('RIVER', [cards[4]])
# playersVpi | playersAtStreet1 | playersAtStreet2 | playersAtStreet3 |
# playersAtStreet4 | playersAtShowdown | street0Raises | street1Raises |
# street2Raises | street3Raises | street4Raises | street1Pot | street2Pot |
# street3Pot | street4Pot | showdownPot | comment | commentTs | texture
#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
#c.execute("""SELECT
# (ha.street,ha.actionno) as actnum,
# p.name,
# ha.street,
# ha.action,
# ha.allin,
# round(ha.amount / 100.0,2)
# FROM
# handsplayers as hp,
# handsactions as ha,
# players as p
# WHERE
# hp.handid = %(handid)s
# and ha.handsplayerid = hp.id
# and p.id = hp.playerid
# ORDER BY
# ha.street,ha.actionno
# """, {'handid':handid})
#res = c.fetchall()
#for (actnum,player, streetnum, act, allin, amount) in res:
# act=act.strip()
# street = h.allStreets[streetnum+1]
# if act==u'blind':
# h.addBlind(player, 'big blind', amount)
# # TODO: The type of blind is not recorded in the DB.
# # TODO: preflop street name anomalies in Hand
# elif act==u'fold':
# h.addFold(street,player)
# elif act==u'call':
# h.addCall(street,player,amount)
# elif act==u'bet':
# h.addBet(street,player,amount)
# elif act==u'check':
# h.addCheck(street,player)
# elif act==u'unbet':
# pass
# else:
# print act, player, streetnum, allin, amount
# # TODO : other actions
# Actions
q = """SELECT
ha.actionNo,
p.name,
ha.street,
ha.actionId,
ha.allIn,
round(ha.amount / 100.0,2) as bet
FROM
HandsActions as ha,
HandsPlayers as hp,
Players as p,
Hands as h
WHERE
h.id = %s
and ha.handsPlayerId = hp.id
and hp.playerId = p.id
AND h.id = hp.handId
ORDER BY
ha.id ASC
; """
q = q.replace('%s', db.sql.query['placeholder'])
c.execute(q, (handId,))
for row in c.fetchall():
name = row['name']
street = row['street']
act = row['actionId']
# allin True/False if row['allIn'] == 0
bet = row['bet']
print "DEBUG: name: '%s' street: '%s' act: '%s' bet: '%s'" %(name, street, act, bet)
street = self.allStreets[int(street)+1]
if act == 2: # Small Blind
self.addBlind(name, 'small blind', str(bet))
elif act == 4: # Big Blind
self.addBlind(name, 'big blind', str(bet))
elif act == 6: # Call
self.addCall(street, name, str(bet))
elif act == 8: # Bet
self.addBet(street, name, str(bet))
elif act == 10: # Fold
self.addFold(street, name)
elif act == 11: # Check
self.addCheck(street, name)
else:
print "DEBUG: unknown action: '%s'" % act
#hhc.readShowdownActions(self)
#hc.readShownCards(self)