Merge branch 'master' of git://git.assembla.com/mctfpdb

This commit is contained in:
Worros 2009-06-17 10:18:13 +08:00
commit 4d2aecc17b

View File

@ -518,6 +518,59 @@ Card ranks will be uppercased
self.addHoleCards(holeandboard.difference(board),player,shown=True) self.addHoleCards(holeandboard.difference(board),player,shown=True)
def writeHTMLHand(self, fh=sys.__stdout__):
from nevow import tags as T
from nevow import flat
players_who_act_preflop = (([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']]))
players_stacks = [x for x in self.players if x[1] in players_who_act_preflop]
action_streets = [x for x in self.actionStreets if len(self.actions[x]) > 0]
def render_stack(context,data):
pat = context.tag.patternGenerator('list_item')
for player in data:
x = "Seat %s: %s ($%s in chips) " %(player[0], player[1],
player[2])
context.tag[ pat().fillSlots('playerStack', x)]
return context.tag
def render_street(context,data):
pat = context.tag.patternGenerator('list_item')
for street in data:
actions = [
T.h3['%s' % street],
T.ol(class_='actions', data=self.actions[street],
render=render_action)[
T.li(pattern='list_item')[ T.slot(name='action')]
]
]
context.tag[ pat().fillSlots('street', actions)]
return context.tag
def render_action(context,data):
pat = context.tag.patternGenerator('list_item')
for act in data:
x = "%s %s" % (act[0],act[1])
context.tag[ pat().fillSlots('action', x)]
return context.tag
s = T.p[
T.h1[ "%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid,
self.getGameTypeAsString(), self.sb, self.bb,
datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))
],
T.h2[ "Table '%s' %d-max Seat #%s is the button" %(self.tablename,
self.maxseats, self.buttonpos)],
T.ol(class_='stacks', data = players_stacks, render=render_stack)[
T.li(pattern='list_item')[ T.slot(name='playerStack') ]
],
T.ol(class_='streets', data = action_streets,
render=render_street)[
T.li(pattern='list_item')[ T.slot(name='street')]
]
]
return flat.flatten(s)
def writeHand(self, fh=sys.__stdout__): def writeHand(self, fh=sys.__stdout__):
# PokerStars format. # PokerStars format.
print >>fh, ("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))) print >>fh, ("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET')))
@ -1120,10 +1173,10 @@ select
g.type, g.type,
g.limitType, g.limitType,
g.hilo, g.hilo,
g.smallBlind / 100.0, round(g.smallBlind / 100.0,2),
g.bigBlind / 100.0 , round(g.bigBlind / 100.0,2),
g.smallBet / 100.0, round(g.smallBet / 100.0,2),
g.bigBet / 100.0, round(g.bigBet / 100.0,2),
s.currency, s.currency,
bc.card1value, bc.card1value,
bc.card1suit, bc.card1suit,
@ -1150,14 +1203,18 @@ limit 1""", {'handid':handid})
res = c.fetchone() 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]} 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]}
h = HoldemOmahaHand(hhc = None, sitename=res[0], gametype = gametype, handText=None, builtFrom = "DB", handid=handid) h = HoldemOmahaHand(hhc = None, sitename=res[0], gametype = gametype, handText=None, builtFrom = "DB", handid=handid)
cards = map("".join, zip(map(str,res[11:21:2]), res[12:21:2])) rank = {0:'X',1:'1',2:'2',3:'3',4:'4',
5:'5',6:'6',7:'7',8:'8',9:'9',
10:'T',11:'J',12:'Q',13:'K',14:'A'}
ranks = [rank[r] for r in res[11:21:2]]
cards = map("".join, zip(ranks, res[12:21:2]))
if cards[0] != "0x": if cards[0] != "Xx":
h.setCommunityCards('FLOP', cards[0:3]) h.setCommunityCards('FLOP', cards[0:3])
if cards[3] != "0x": if cards[3] != "Xx":
h.setCommunityCards('TURN', cards[3]) h.setCommunityCards('TURN', [cards[3]])
if cards[4] != "0x": if cards[4] != "Xx":
h.setCommunityCards('RIVER', cards[4]) h.setCommunityCards('RIVER', [cards[4]])
#[Card.valueSuitFromCard(x) for x in cards] #[Card.valueSuitFromCard(x) for x in cards]
@ -1186,9 +1243,10 @@ WHERE h.id = %(handid)s
c.execute(""" c.execute("""
SELECT SELECT
hp.seatno, hp.seatno,
round(hp.winnings / 100.0,2) as winnings,
p.name, p.name,
round(hp.startcash / 100.0,2) as chips, round(hp.startcash / 100.0,2) as chips,
(hp.card1,hp.card2) as hole hp.card1,hp.card2
FROM FROM
handsplayers as hp, handsplayers as hp,
players as p players as p
@ -1196,9 +1254,11 @@ WHERE
hp.handid = %(handid)s hp.handid = %(handid)s
and p.id = hp.playerid and p.id = hp.playerid
""", {'handid':handid}) """, {'handid':handid})
for (seat, name, chips, cards) in c.fetchall(): for (seat, winnings, name, chips, card1,card2) in c.fetchall():
h.addPlayer(seat,name,chips) h.addPlayer(seat,name,chips)
h.addHoleCards([Card.valueSuitFromCard(x) for x in cards],name) h.addHoleCards(map(Card.valueSuitFromCard, (card1,card2)),name)
if winnings > 0:
h.addCollectPot(name, winnings)
# actions # actions
c.execute(""" c.execute("""
@ -1208,7 +1268,7 @@ SELECT
ha.street, ha.street,
ha.action, ha.action,
ha.allin, ha.allin,
ha.amount / 100.0 round(ha.amount / 100.0,2)
FROM FROM
handsplayers as hp, handsplayers as hp,
handsactions as ha, handsactions as ha,
@ -1241,7 +1301,7 @@ ORDER BY
else: else:
print act, player, streetnum, allin, amount print act, player, streetnum, allin, amount
# TODO : other actions # TODO : other actions
#hhc.readCollectPot(self)
#hhc.readShowdownActions(self) #hhc.readShowdownActions(self)
#hc.readShownCards(self) #hc.readShownCards(self)
h.totalPot() h.totalPot()