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:
parent
20c5ecee82
commit
70c3480105
218
pyfpdb/Hand.py
218
pyfpdb/Hand.py
|
@ -282,75 +282,10 @@ db: a connected Database object"""
|
|||
def updateSessionsCache(self, db):
|
||||
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 """
|
||||
c = cnxn.cursor()
|
||||
|
||||
# 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
|
||||
c = db.get_cursor()
|
||||
q = """SELECT
|
||||
hp.seatno,
|
||||
round(hp.winnings / 100.0,2) as winnings,
|
||||
p.name,
|
||||
|
@ -358,69 +293,101 @@ db: a connected Database object"""
|
|||
hp.card1,hp.card2,
|
||||
hp.position
|
||||
FROM
|
||||
handsplayers as hp,
|
||||
players as p
|
||||
HandsPlayers as hp,
|
||||
Players as p
|
||||
WHERE
|
||||
hp.handid = %(handid)s
|
||||
hp.handId = %s
|
||||
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():
|
||||
h.addPlayer(seat,name,chips)
|
||||
if card1 and card2:
|
||||
h.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)), name, dealt=True)
|
||||
if winnings > 0:
|
||||
h.addCollectPot(name, winnings)
|
||||
if position == 'B':
|
||||
h.buttonpos = seat
|
||||
print "DEBUG: seat: '%s'\tname: '%s'\tchips: '%s'" % (seat, name, chips)
|
||||
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
|
||||
|
||||
|
||||
# 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
|
||||
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
|
||||
#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
|
||||
|
||||
#hhc.readShowdownActions(self)
|
||||
#hc.readShownCards(self)
|
||||
h.totalPot()
|
||||
h.rake = h.totalpot - h.totalcollected
|
||||
#h.totalPot()
|
||||
#h.rake = h.totalpot - h.totalcollected
|
||||
|
||||
return h
|
||||
|
||||
def addPlayer(self, seat, name, chips):
|
||||
"""\
|
||||
|
@ -853,10 +820,11 @@ class HoldemOmahaHand(Hand):
|
|||
hhc.readOther(self)
|
||||
#print "\nHand:\n"+str(self)
|
||||
elif builtFrom == "DB":
|
||||
if handid is not None:
|
||||
self.select(handid) # Will need a handId
|
||||
else:
|
||||
log.warning(_("HoldemOmahaHand.__init__:Can't assemble hand from db without a handid"))
|
||||
#if handid is not None:
|
||||
# self.select(handid) # Will need a handId
|
||||
#else:
|
||||
# log.warning(_("HoldemOmahaHand.__init__:Can't assemble hand from db without a handid"))
|
||||
print "DEBUG: HoldemOmaha hand initialised for select()"
|
||||
else:
|
||||
log.warning(_("HoldemOmahaHand.__init__:Neither HHC nor DB+handid provided"))
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user