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

This commit is contained in:
grindi 2009-08-12 19:58:29 +04:00
commit 25923b02d1
9 changed files with 3165 additions and 3138 deletions

View File

@ -27,6 +27,12 @@ from HandHistoryConverter import *
class Absolute(HandHistoryConverter): class Absolute(HandHistoryConverter):
# Class Variables
sitename = "Absolute"
filetype = "text"
codepage = "cp1252"
siteid = 8
# Static regexes # Static regexes
re_SplitHands = re.compile(r"\n\n\n+") re_SplitHands = re.compile(r"\n\n\n+")
re_TailSplitHands = re.compile(r"(\n\n\n+)") re_TailSplitHands = re.compile(r"(\n\n\n+)")
@ -48,24 +54,6 @@ class Absolute(HandHistoryConverter):
# re_Board = re.compile(ur"\[ (?P<CARDS>.+) \]") # re_Board = re.compile(ur"\[ (?P<CARDS>.+) \]")
def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, debugging=False, index=0):
"""\
in_path (default '-' = sys.stdin)
out_path (default '-' = sys.stdout)
follow : whether to tail -f the input
autostart: whether to run the thread (or you can call start() yourself)
debugging: if False, pass on partially supported game types. If true, have a go and error..."""
#print "DEBUG: XXXXXXXXXXXXXXX"
HandHistoryConverter.__init__(self, in_path, out_path, sitename="Absolute", follow=follow, index=index)
logging.info("Initialising Absolute converter class")
self.filetype = "text"
self.codepage = "cp1252"
self.siteId = 8 # Needs to match id entry in Sites database
self.debugging = debugging
if autostart:
self.start()
# otherwise you need to call start yourself.
def compilePlayerRegexs(self, hand): def compilePlayerRegexs(self, hand):
players = set([player[1] for player in hand.players]) players = set([player[1] for player in hand.players])
if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' if not players <= self.compiledPlayers: # x <= y means 'x is subset of y'

View File

@ -1150,11 +1150,16 @@ class Database:
boardcard2, boardcard2,
boardcard3, boardcard3,
boardcard4, boardcard4,
boardcard5 boardcard5,
street1Pot,
street2Pot,
street3Pot,
street4Pot,
showdownPot
) )
VALUES 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, %s, %s)"""
#--- texture, #--- texture,
#-- playersVpi, #-- playersVpi,
#-- playersAtStreet1, #-- playersAtStreet1,
@ -1167,11 +1172,6 @@ class Database:
#-- street2Raises, #-- street2Raises,
#-- street3Raises, #-- street3Raises,
#-- street4Raises, #-- street4Raises,
#-- street1Pot,
#-- street2Pot,
#-- street3Pot,
#-- street4Pot,
#-- showdownPot
#-- seats, #-- seats,
q = q.replace('%s', self.sql.query['placeholder']) q = q.replace('%s', self.sql.query['placeholder'])
@ -1190,7 +1190,7 @@ class Database:
p['boardcard2'], p['boardcard2'],
p['boardcard3'], p['boardcard3'],
p['boardcard4'], p['boardcard4'],
p['boardcard5']) p['boardcard5'],
# hudCache['playersVpi'], # hudCache['playersVpi'],
# hudCache['playersAtStreet1'], # hudCache['playersAtStreet1'],
# hudCache['playersAtStreet2'], # hudCache['playersAtStreet2'],
@ -1202,12 +1202,12 @@ class Database:
# hudCache['street2Raises'], # hudCache['street2Raises'],
# hudCache['street3Raises'], # hudCache['street3Raises'],
# hudCache['street4Raises'], # hudCache['street4Raises'],
# hudCache['street1Pot'], p['street1Pot'],
# hudCache['street2Pot'], p['street2Pot'],
# hudCache['street3Pot'], p['street3Pot'],
# hudCache['street4Pot'], p['street4Pot'],
# hudCache['showdownPot'] p['showdownPot']
) ))
#return getLastInsertId(backend, conn, cursor) #return getLastInsertId(backend, conn, cursor)
# def storeHand # def storeHand

View File

@ -22,7 +22,6 @@ import gtk
import os import os
import fpdb_simple import fpdb_simple
import fpdb_import import fpdb_import
import fpdb_db import fpdb_db

View File

@ -203,11 +203,6 @@ db: a connected fpdb_db object"""
hh['tableName'] = self.tablename hh['tableName'] = self.tablename
hh['maxSeats'] = self.maxseats hh['maxSeats'] = self.maxseats
hh['seats'] = len(sqlids) hh['seats'] = len(sqlids)
# boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
# boardcard2 smallint,
# boardcard3 smallint,
# boardcard4 smallint,
# boardcard5 smallint,
# Flop turn and river may all be empty - add (likely) too many elements and trim with range # Flop turn and river may all be empty - add (likely) too many elements and trim with range
boardcards = self.board['FLOP'] + self.board['TURN'] + self.board['RIVER'] + [u'0x', u'0x', u'0x', u'0x', u'0x'] boardcards = self.board['FLOP'] + self.board['TURN'] + self.board['RIVER'] + [u'0x', u'0x', u'0x', u'0x', u'0x']
cards = [Card.encodeCard(c) for c in boardcards[0:5]] cards = [Card.encodeCard(c) for c in boardcards[0:5]]
@ -217,7 +212,6 @@ db: a connected fpdb_db object"""
hh['boardcard4'] = cards[3] hh['boardcard4'] = cards[3]
hh['boardcard5'] = cards[4] hh['boardcard5'] = cards[4]
print hh
# texture smallint, # texture smallint,
# playersVpi SMALLINT NOT NULL, /* num of players vpi */ # playersVpi SMALLINT NOT NULL, /* num of players vpi */
# Needs to be recorded # Needs to be recorded
@ -241,17 +235,14 @@ db: a connected fpdb_db object"""
# Needs to be recorded # Needs to be recorded
# street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */ # street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
# Needs to be recorded # Needs to be recorded
# street1Pot INT, /* pot size at flop/street4 */
# Needs to be recorded #print "DEBUG: self.getStreetTotals = (%s, %s, %s, %s, %s)" % self.getStreetTotals()
# street2Pot INT, /* pot size at turn/street5 */ #FIXME: Pot size still in decimal, needs to be converted to cents
# Needs to be recorded (hh['street1Pot'], hh['street2Pot'], hh['street3Pot'], hh['street4Pot'], hh['showdownPot']) = self.getStreetTotals()
# street3Pot INT, /* pot size at river/street6 */
# Needs to be recorded
# street4Pot INT, /* pot size at sd/street7 */
# Needs to be recorded
# showdownPot INT, /* pot size at sd/street7 */
# comment TEXT, # comment TEXT,
# commentTs DATETIME # commentTs DATETIME
#print hh
handid = db.storeHand(hh) handid = db.storeHand(hh)
# HandsPlayers - ? ... Do we fix winnings? # HandsPlayers - ? ... Do we fix winnings?
# Tourneys ? # Tourneys ?
@ -489,7 +480,6 @@ Card ranks will be uppercased
board = set([c for s in self.board.values() for c in s]) board = set([c for s in self.board.values() for c in s])
self.addHoleCards(holeandboard.difference(board),player,shown, mucked) self.addHoleCards(holeandboard.difference(board),player,shown, mucked)
def totalPot(self): def totalPot(self):
"""If all bets and blinds have been added, totals up the total pot size""" """If all bets and blinds have been added, totals up the total pot size"""
@ -573,6 +563,9 @@ Map the tuple self.gametype onto the pokerstars string describing it
"""Return a string of the stakes of the current hand.""" """Return a string of the stakes of the current hand."""
return "%s%s/%s%s" % (self.sym, self.sb, self.sym, self.bb) return "%s%s/%s%s" % (self.sym, self.sb, self.sym, self.bb)
def getStreetTotals(self):
pass
def writeGameLine(self): def writeGameLine(self):
"""Return the first HH line for the current hand.""" """Return the first HH line for the current hand."""
gs = "PokerStars Game #%s: " % self.handid gs = "PokerStars Game #%s: " % self.handid
@ -638,6 +631,7 @@ class HoldemOmahaHand(Hand):
for street in self.actionStreets: for street in self.actionStreets:
if self.streets[street]: if self.streets[street]:
hhc.readAction(self, street) hhc.readAction(self, street)
self.pot.markTotal(street)
hhc.readCollectPot(self) hhc.readCollectPot(self)
hhc.readShownCards(self) hhc.readShownCards(self)
self.totalPot() # finalise it (total the pot) self.totalPot() # finalise it (total the pot)
@ -662,6 +656,18 @@ class HoldemOmahaHand(Hand):
else: else:
self.addHoleCards('PREFLOP', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt) self.addHoleCards('PREFLOP', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt)
def getStreetTotals(self):
# street1Pot INT, /* pot size at flop/street4 */
# street2Pot INT, /* pot size at turn/street5 */
# street3Pot INT, /* pot size at river/street6 */
# street4Pot INT, /* pot size at sd/street7 */
# showdownPot INT, /* pot size at sd/street7 */
tmp1 = self.pot.getTotalAtStreet('FLOP')
tmp2 = self.pot.getTotalAtStreet('TURN')
tmp3 = self.pot.getTotalAtStreet('RIVER')
tmp4 = 0
tmp5 = 0
return (tmp1,tmp2,tmp3,tmp4,tmp5)
def writeHTMLHand(self, fh=sys.__stdout__): def writeHTMLHand(self, fh=sys.__stdout__):
from nevow import tags as T from nevow import tags as T
@ -886,6 +892,7 @@ class DrawHand(Hand):
for street in self.streetList: for street in self.streetList:
if self.streets[street]: if self.streets[street]:
hhc.readAction(self, street) hhc.readAction(self, street)
self.pot.markTotal(street)
hhc.readCollectPot(self) hhc.readCollectPot(self)
hhc.readShownCards(self) hhc.readShownCards(self)
self.totalPot() # finalise it (total the pot) self.totalPot() # finalise it (total the pot)
@ -946,6 +953,14 @@ class DrawHand(Hand):
act = (player, 'discards', num) act = (player, 'discards', num)
self.actions[street].append(act) self.actions[street].append(act)
def getStreetTotals(self):
# street1Pot INT, /* pot size at flop/street4 */
# street2Pot INT, /* pot size at turn/street5 */
# street3Pot INT, /* pot size at river/street6 */
# street4Pot INT, /* pot size at sd/street7 */
# showdownPot INT, /* pot size at sd/street7 */
return (0,0,0,0,0)
def writeHand(self, fh=sys.__stdout__): def writeHand(self, fh=sys.__stdout__):
# PokerStars format. # PokerStars format.
@ -1053,6 +1068,7 @@ class StudHand(Hand):
if self.streets[street]: if self.streets[street]:
log.debug(street + self.streets[street]) log.debug(street + self.streets[street])
hhc.readAction(self, street) hhc.readAction(self, street)
self.pot.markTotal(street)
hhc.readCollectPot(self) hhc.readCollectPot(self)
hhc.readShownCards(self) # not done yet hhc.readShownCards(self) # not done yet
self.totalPot() # finalise it (total the pot) self.totalPot() # finalise it (total the pot)
@ -1123,6 +1139,14 @@ Add a complete on [street] by [player] to [amountTo]
self.lastBet['THIRD'] = Decimal(bringin) self.lastBet['THIRD'] = Decimal(bringin)
self.pot.addMoney(player, Decimal(bringin)) self.pot.addMoney(player, Decimal(bringin))
def getStreetTotals(self):
# street1Pot INT, /* pot size at flop/street4 */
# street2Pot INT, /* pot size at turn/street5 */
# street3Pot INT, /* pot size at river/street6 */
# street4Pot INT, /* pot size at sd/street7 */
# showdownPot INT, /* pot size at sd/street7 */
return (0,0,0,0,0)
def writeHand(self, fh=sys.__stdout__): def writeHand(self, fh=sys.__stdout__):
# PokerStars format. # PokerStars format.
@ -1281,11 +1305,12 @@ class Pot(object):
def __init__(self): def __init__(self):
self.contenders = set() self.contenders = set()
self.committed = {} self.committed = {}
self.total = None self.streettotals = {}
self.returned = {} self.total = None
self.sym = u'$' # this is the default currency symbol self.returned = {}
self.sym = u'$' # this is the default currency symbol
def setSym(self, sym): def setSym(self, sym):
self.sym = sym self.sym = sym
@ -1302,6 +1327,14 @@ class Pot(object):
self.contenders.add(player) self.contenders.add(player)
self.committed[player] += amount self.committed[player] += amount
def markTotal(self, street):
self.streettotals[street] = sum(self.committed.values())
def getTotalAtStreet(self, street):
if street in self.streettotals:
return self.streettotals[street]
return 0
def end(self): def end(self):
self.total = sum(self.committed.values()) self.total = sum(self.committed.values())

View File

@ -77,9 +77,13 @@ follow : whether to tail -f the input"""
# TODO: out_path should be sanity checked. # TODO: out_path should be sanity checked.
out_dir = os.path.dirname(self.out_path) out_dir = os.path.dirname(self.out_path)
if not os.path.isdir(out_dir) and out_dir != '': if not os.path.isdir(out_dir) and out_dir != '':
logging.info("Creatin directory '%s'" % out_dir) log.info("Creating directory '%s'" % out_dir)
os.makedirs(out_dir) os.makedirs(out_dir)
self.out_fh = codecs.open(self.out_path, 'w', 'cp1252') try:
self.out_fh = codecs.open(self.out_path, 'w', 'cp1252')
log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh))
except:
log.error("out_path %s couldn't be opened" % (self.out_path))
self.follow = follow self.follow = follow
self.compiledPlayers = set() self.compiledPlayers = set()

View File

@ -25,6 +25,7 @@ import datetime
import time import time
import re import re
import sys import sys
import locale
import Card import Card
@ -37,6 +38,8 @@ MYSQL_INNODB = 2
PGSQL = 3 PGSQL = 3
SQLITE = 4 SQLITE = 4
(localename, encoding) = locale.getdefaultlocale()
class DuplicateError(Exception): class DuplicateError(Exception):
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
@ -543,7 +546,7 @@ def parseActionType(line):
#parses the ante out of the given line and checks which player paid it, updates antes accordingly. #parses the ante out of the given line and checks which player paid it, updates antes accordingly.
def parseAnteLine(line, isTourney, names, antes): def parseAnteLine(line, isTourney, names, antes):
for i, name in enumerate(names): for i, name in enumerate(names):
if line.startswith(name.encode("latin-1")): if line.startswith(name.encode(encoding)):
pos = line.rfind("$") + 1 pos = line.rfind("$") + 1
if not isTourney: if not isTourney:
antes[i] += float2int(line[pos:]) antes[i] += float2int(line[pos:])
@ -705,7 +708,7 @@ def parseHandStartTime(topline):
def findName(line): def findName(line):
pos1 = line.find(":") + 2 pos1 = line.find(":") + 2
pos2 = line.rfind("(") - 1 pos2 = line.rfind("(") - 1
return unicode(line[pos1:pos2], "latin-1") return unicode(line[pos1:pos2], encoding)
def parseNames(lines): def parseNames(lines):
return [findName(line) for line in lines] return [findName(line) for line in lines]
@ -822,7 +825,7 @@ def parseTourneyNo(topline):
def parseWinLine(line, names, winnings, isTourney): def parseWinLine(line, names, winnings, isTourney):
#print "parseWinLine: line:",line #print "parseWinLine: line:",line
for i,n in enumerate(names): for i,n in enumerate(names):
n = n.encode("latin-1") n = n.encode(encoding)
if line.startswith(n): if line.startswith(n):
if isTourney: if isTourney:
pos1 = line.rfind("collected ") + 10 pos1 = line.rfind("collected ") + 10
@ -1033,13 +1036,13 @@ def recognisePlayerNo(line, names, atype):
#print "recogniseplayerno, names:",names #print "recogniseplayerno, names:",names
for i in xrange(len(names)): for i in xrange(len(names)):
if (atype=="unbet"): if (atype=="unbet"):
if (line.endswith(names[i].encode("latin-1"))): if (line.endswith(names[i].encode(encoding))):
return (i) return (i)
elif (line.startswith("Dealt to ")): elif (line.startswith("Dealt to ")):
#print "recognisePlayerNo, card precut, line:",line #print "recognisePlayerNo, card precut, line:",line
tmp=line[9:] tmp=line[9:]
#print "recognisePlayerNo, card postcut, tmp:",tmp #print "recognisePlayerNo, card postcut, tmp:",tmp
if (tmp.startswith(names[i].encode("latin-1"))): if (tmp.startswith(names[i].encode(encoding))):
return (i) return (i)
elif (line.startswith("Seat ")): elif (line.startswith("Seat ")):
if (line.startswith("Seat 10")): if (line.startswith("Seat 10")):
@ -1047,10 +1050,10 @@ def recognisePlayerNo(line, names, atype):
else: else:
tmp=line[8:] tmp=line[8:]
if (tmp.startswith(names[i].encode("latin-1"))): if (tmp.startswith(names[i].encode(encoding))):
return (i) return (i)
else: else:
if (line.startswith(names[i].encode("latin-1"))): if (line.startswith(names[i].encode(encoding))):
return (i) return (i)
#if we're here we mustve failed #if we're here we mustve failed
raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype) raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype)