This commit is contained in:
Eric Blade 2009-09-15 22:04:37 -05:00
parent a566d52b9a
commit ba663c231c

View File

@ -201,17 +201,16 @@ def createArrays(category, seats, card_values, card_suits, antes, winnings,
#end def createArrays #end def createArrays
def fill_board_cards(board_values, board_suits): def fill_board_cards(board_values, board_suits):
#fill up the two board card arrays """ fill up the two board card arrays """
while (len(board_values)<5): while len(board_values) < 5:
board_values.append(0) board_values.append(0)
board_suits.append("x") board_suits.append("x")
#end def fill_board_cards
def fillCardArrays(player_count, base, category, card_values, card_suits): def fillCardArrays(player_count, base, category, card_values, card_suits):
"""fills up the two card arrays""" """fills up the two card arrays"""
if (category=="holdem"): if category == "holdem":
cardCount = 2 cardCount = 2
elif (category=="omahahi" or category=="omahahilo"): elif category == "omahahi" or category == "omahahilo":
cardCount = 4 cardCount = 4
elif base == "stud": elif base == "stud":
cardCount = 7 cardCount = 7
@ -219,7 +218,7 @@ def fillCardArrays(player_count, base, category, card_values, card_suits):
raise FpdbError("invalid category:", category) raise FpdbError("invalid category:", category)
for i in xrange(player_count): for i in xrange(player_count):
while (len(card_values[i]) < cardCount): while len(card_values[i]) < cardCount:
card_values[i].append(0) card_values[i].append(0)
card_suits[i].append("x") card_suits[i].append("x")
#end def fillCardArrays #end def fillCardArrays
@ -251,24 +250,23 @@ def filterAnteBlindFold(hand):
pos2 = line.find(" (") pos2 = line.find(" (")
foldeeName = line[pos1:pos2] foldeeName = line[pos1:pos2]
if foldeeName!=None: if foldeeName is not None:
#print "filterAnteBlindFold, foldeeName:",foldeeName #print "filterAnteBlindFold, foldeeName:",foldeeName
for i, line in enumerate(hand): for i, line in enumerate(hand):
if foldeeName in line: if foldeeName in line:
hand[i] = None hand[i] = None
return [line for line in hand if line] return [line for line in hand if line]
#end def filterAnteFold
def stripEOLspaces(str): def stripEOLspaces(str):
return str.rstrip() return str.rstrip()
#removes useless lines as well as trailing spaces
def filterCrap(hand, isTourney): def filterCrap(hand, isTourney):
#remove two trailing spaces at end of line """ removes useless lines as well as trailing spaces """
#remove trailing spaces at end of line
hand = [line.rstrip() for line in hand] hand = [line.rstrip() for line in hand]
#print "hand after trailing space removal in filterCrap:",hand
#general variable position word filter/string filter #general variable position word filter/string filter
for i in xrange(len(hand)): for i in xrange(len(hand)):
if hand[i].startswith("Board ["): if hand[i].startswith("Board ["):
@ -347,15 +345,16 @@ def filterCrap(hand, isTourney):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" is sitting out")): elif (hand[i].endswith(" is sitting out")):
hand[i] = False hand[i] = False
# python docs say this is identical to filter(None, list)
# which removes all false items from the passed list (hand)
hand = [line for line in hand if line]
hand = [line for line in hand if line] # python docs say this is identical to filter(None, list)
#print "done with filterCrap, hand:", hand
return hand return hand
#end filterCrap
#takes a poker float (including , for thousand seperator and converts it to an int
def float2int(string): def float2int(string):
""" takes a poker float (including , for thousand seperator) and
converts it to an int """
# Note that this automagically assumes US style currency formatters
pos = string.find(",") pos = string.find(",")
if pos != -1: #remove , the thousand seperator if pos != -1: #remove , the thousand seperator
string = "%s%s" % (string[0:pos], string[pos+1:]) string = "%s%s" % (string[0:pos], string[pos+1:])
@ -368,56 +367,46 @@ def float2int(string):
if pos == -1: #no decimal point - was in full dollars - need to multiply with 100 if pos == -1: #no decimal point - was in full dollars - need to multiply with 100
result *= 100 result *= 100
return result return result
#end def float2int
ActionLines = ( "calls $", ": calls ", "brings in for", "completes it to", "posts small blind", ActionLines = ( "calls $", ": calls ", "brings in for", "completes it to",
"posts the small blind", "posts big blind", "posts the big blind", "posts small blind", "posts the small blind", "posts big blind",
"posts small & big blinds", "posts $", "posts a dead", "bets $", "posts the big blind", "posts small & big blinds", "posts $",
": bets ", " raises") "posts a dead", "bets $", ": bets ", " raises")
#returns boolean whether the passed line is an action line
def isActionLine(line): def isActionLine(line):
if (line.endswith("folds")): if line.endswith("folds"):
return True return True
elif (line.endswith("checks")): elif line.endswith("checks"):
return True return True
elif (line.startswith("Uncalled bet")): elif line.startswith("Uncalled bet"):
return True return True
# searches for each member of ActionLines being in line, returns true
# on first match .. neat func
return any(x for x in ActionLines if x in line) return any(x for x in ActionLines if x in line)
# return bool([ x for x in ActionLines if x in line])
# ret = any(True for searchstr in ActionLines if searchstr in line)
# ret = len( [ x for x in ActionLines if line.find(x) > -1] ) > 0
# ret = any(searchstr in line for searchstr in ActionLines)
#end def isActionLine
#returns whether this is a duplicate
def isAlreadyInDB(db, gametypeID, siteHandNo): def isAlreadyInDB(db, gametypeID, siteHandNo):
#print "isAlreadyInDB gtid,shand:",gametypeID, siteHandNo
c = db.get_cursor() c = db.get_cursor()
c.execute(db.sql.query['isAlreadyInDB'], (gametypeID, siteHandNo)) c.execute(db.sql.query['isAlreadyInDB'], (gametypeID, siteHandNo))
result = c.fetchall() result = c.fetchall()
if (len(result)>=1): if len(result) >= 1:
raise DuplicateError ("dupl") raise DuplicateError ("dupl")
#end isAlreadyInDB
def isRebuyOrAddon(topline): def isRebuyOrAddon(topline):
"""isRebuyOrAddon not implemented yet""" """isRebuyOrAddon not implemented yet"""
return False return False
#end def isRebuyOrAddon
#returns whether the passed topline indicates a tournament or not #returns whether the passed topline indicates a tournament or not
def isTourney(topline): def isTourney(topline):
return "Tournament" in topline return "Tournament" in topline
#end def isTourney
WinLines = ( "wins the pot", "ties for the ", "wins side pot", "wins the low main pot", "wins the high main pot", WinLines = ( "wins the pot", "ties for the ", "wins side pot", "wins the low main pot", "wins the high main pot",
"wins the low", "wins the low",
"wins the high pot", "wins the high side pot", "wins the main pot", "wins the side pot", "collected" ) "wins the high pot", "wins the high side pot", "wins the main pot", "wins the side pot", "collected" )
#returns boolean whether the passed line is a win line
def isWinLine(line): def isWinLine(line):
""" returns boolean whether the passed line is a win line """
return any(x for x in WinLines if x in line) return any(x for x in WinLines if x in line)
#end def isWinLine
#returns the amount of cash/chips put into the put in the given action line #returns the amount of cash/chips put into the put in the given action line
def parseActionAmount(line, atype, isTourney): def parseActionAmount(line, atype, isTourney):
@ -426,7 +415,8 @@ def parseActionAmount(line, atype, isTourney):
#elif (line.endswith(", and is all in")): #elif (line.endswith(", and is all in")):
# line=line[:-15] # line=line[:-15]
if line.endswith(", and is capped"):#ideally we should recognise this as an all-in if category is capXl #ideally we should recognise this as an all-in if category is capXl
if line.endswith(", and is capped"):
line=line[:-15] line=line[:-15]
if line.endswith(" and is capped"): if line.endswith(" and is capped"):
line=line[:-14] line=line[:-14]
@ -439,7 +429,7 @@ def parseActionAmount(line, atype, isTourney):
pos1 = line.find("(") + 1 pos1 = line.find("(") + 1
pos2 = line.find(")") pos2 = line.find(")")
amount = float2int(line[pos1:pos2]) amount = float2int(line[pos1:pos2])
elif atype == "bet" and line.find(": raises $")!=-1 and line.find("to $")!=-1: elif atype == "bet" and ": raises $" in line and "to $" in line:
pos = line.find("to $")+4 pos = line.find("to $")+4
amount = float2int(line[pos:]) amount = float2int(line[pos:])
else: else:
@ -489,7 +479,6 @@ def parseActionLine(base, isTourney, line, street, playerIDs, names, action_type
actionNos[street][playerno].append(nextActionNo) actionNos[street][playerno].append(nextActionNo)
tmp=(playerIDs[playerno], atype) tmp=(playerIDs[playerno], atype)
actionTypeByNo[street].append(tmp) actionTypeByNo[street].append(tmp)
#end def parseActionLine
def goesAllInOnThisLine(line): def goesAllInOnThisLine(line):
"""returns whether the player went all-in on this line and removes the all-in text from the line.""" """returns whether the player went all-in on this line and removes the all-in text from the line."""
@ -501,7 +490,6 @@ def goesAllInOnThisLine(line):
line = line[:-15] line = line[:-15]
isAllIn = True isAllIn = True
return (line, isAllIn) return (line, isAllIn)
#end def goesAllInOnThisLine
#returns the action type code (see table design) of the given action line #returns the action type code (see table design) of the given action line
ActionTypes = { 'brings in for' :"blind", ActionTypes = { 'brings in for' :"blind",
@ -530,7 +518,6 @@ def parseActionType(line):
if x in line: if x in line:
return ActionTypes[x] return ActionTypes[x]
raise FpdbError ("failed to recognise actiontype in parseActionLine in: "+line) raise FpdbError ("failed to recognise actiontype in parseActionLine in: "+line)
#end def parseActionType
#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):
@ -547,15 +534,12 @@ def parseAnteLine(line, isTourney, names, antes):
pos1 = line.rfind("ante") + 5 pos1 = line.rfind("ante") + 5
pos2 = line.find(" ", pos1) pos2 = line.find(" ", pos1)
antes[i] += int(line[pos1:pos2]) antes[i] += int(line[pos1:pos2])
#print "parseAnteLine line: ", line, "antes[i]", antes[i], "antes", antes
#end def parseAntes
#returns the buyin of a tourney in cents #returns the buyin of a tourney in cents
def parseBuyin(topline): def parseBuyin(topline):
pos1 = topline.find("$")+1 pos1 = topline.find("$")+1
pos2 = topline.find("+") pos2 = topline.find("+")
return float2int(topline[pos1:pos2]) return float2int(topline[pos1:pos2])
#end def parseBuyin
#parses a card line and changes the passed arrays accordingly #parses a card line and changes the passed arrays accordingly
#todo: reorganise this messy method #todo: reorganise this messy method
@ -569,7 +553,8 @@ def parseCardLine(category, street, line, names, cardValues, cardSuits, boardVal
cardValues[playerNo].append(line[i:i+1]) cardValues[playerNo].append(line[i:i+1])
cardSuits[playerNo].append(line[i+1:i+2]) cardSuits[playerNo].append(line[i+1:i+2])
if len(cardValues[playerNo]) != 2: if len(cardValues[playerNo]) != 2:
if cardValues[playerNo][0]==cardValues[playerNo][2] and cardSuits[playerNo][1]==cardSuits[playerNo][3]: #two tests will do if (cardValues[playerNo][0] == cardValues[playerNo][2] and
cardSuits[playerNo][1] == cardSuits[playerNo][3]):
cardValues[playerNo]=cardValues[playerNo][0:2] cardValues[playerNo]=cardValues[playerNo][0:2]
cardSuits[playerNo]=cardSuits[playerNo][0:2] cardSuits[playerNo]=cardSuits[playerNo][0:2]
else: else:
@ -580,7 +565,8 @@ def parseCardLine(category, street, line, names, cardValues, cardSuits, boardVal
cardValues[playerNo].append(line[i:i+1]) cardValues[playerNo].append(line[i:i+1])
cardSuits[playerNo].append(line[i+1:i+2]) cardSuits[playerNo].append(line[i+1:i+2])
if (len(cardValues[playerNo])!=4): if (len(cardValues[playerNo])!=4):
if cardValues[playerNo][0]==cardValues[playerNo][4] and cardSuits[playerNo][3]==cardSuits[playerNo][7]: #two tests will do if (cardValues[playerNo][0] == cardValues[playerNo][4] and
cardSuits[playerNo][3] == cardSuits[playerNo][7]): #two tests will do
cardValues[playerNo] = cardValues[playerNo][0:4] cardValues[playerNo] = cardValues[playerNo][0:4]
cardSuits[playerNo] = cardSuits[playerNo][0:4] cardSuits[playerNo] = cardSuits[playerNo][0:4]
else: else:
@ -631,7 +617,6 @@ def parseCardLine(category, street, line, names, cardValues, cardSuits, boardVal
#print boardValues #print boardValues
else: else:
raise FpdbError ("unrecognised line:"+line) raise FpdbError ("unrecognised line:"+line)
#end def parseCardLine
def parseCashesAndSeatNos(lines): def parseCashesAndSeatNos(lines):
"""parses the startCashes and seatNos of each player out of the given lines and returns them as a dictionary of two arrays""" """parses the startCashes and seatNos of each player out of the given lines and returns them as a dictionary of two arrays"""
@ -647,7 +632,6 @@ def parseCashesAndSeatNos(lines):
pos2=lines[i].find(" in chips") pos2=lines[i].find(" in chips")
cashes.append(float2int(lines[i][pos1:pos2])) cashes.append(float2int(lines[i][pos1:pos2]))
return {'startCashes':cashes, 'seatNos':seatNos} return {'startCashes':cashes, 'seatNos':seatNos}
#end def parseCashesAndSeatNos
#returns the buyin of a tourney in cents #returns the buyin of a tourney in cents
def parseFee(topline): def parseFee(topline):
@ -655,7 +639,6 @@ def parseFee(topline):
pos1=topline.find("$",pos1)+1 pos1=topline.find("$",pos1)+1
pos2=topline.find(" ", pos1) pos2=topline.find(" ", pos1)
return float2int(topline[pos1:pos2]) return float2int(topline[pos1:pos2])
#end def parsefee
#returns a datetime object with the starttime indicated in the given topline #returns a datetime object with the starttime indicated in the given topline
def parseHandStartTime(topline): def parseHandStartTime(topline):
@ -691,7 +674,6 @@ def parseHandStartTime(topline):
result += datetime.timedelta(hours=5) result += datetime.timedelta(hours=5)
return result return result
#end def parseHandStartTime
#parses the names out of the given lines and returns them as an array #parses the names out of the given lines and returns them as an array
def findName(line): def findName(line):
@ -701,13 +683,11 @@ def findName(line):
def parseNames(lines): def parseNames(lines):
return [findName(line) for line in lines] return [findName(line) for line in lines]
#end def parseNames
def parsePositions(hand, names): def parsePositions(hand, names):
positions = [-1 for i in names] positions = [-1 for i in names]
sb, bb = -1, -1 sb, bb = -1, -1
#find blinds
for line in hand: for line in hand:
if sb == -1 and "small blind" in line and "dead small blind" not in line: if sb == -1 and "small blind" in line and "dead small blind" not in line:
sb = line sb = line
@ -735,10 +715,7 @@ def parsePositions(hand, names):
positions[bb]="B" positions[bb]="B"
#fill up rest of array #fill up rest of array
if sbExists: arraypos = sb - 1 if sbExists else bb - 1
arraypos = sb-1
else:
arraypos = bb-1
distFromBtn=0 distFromBtn=0
while arraypos >= 0 and arraypos != bb: while arraypos >= 0 and arraypos != bb:
@ -754,10 +731,8 @@ def parsePositions(hand, names):
positions[i] = 9 positions[i] = 9
i -= 1 i -= 1
### RHH - Changed to set the null seats before BB to "9" ### RHH - Changed to set the null seats before BB to "9"
if sbExists: i = sb - 1 if sbExists else bb - 1
i = sb-1
else:
i = bb-1
while positions[i] < 0: while positions[i] < 0:
positions[i]=9 positions[i]=9
i-=1 i-=1
@ -775,21 +750,18 @@ def parsePositions(hand, names):
raise FpdbError ("failed to read positions") raise FpdbError ("failed to read positions")
# print str(positions), "\n" # print str(positions), "\n"
return positions return positions
#end def parsePositions
#simply parses the rake amount and returns it as an int #simply parses the rake amount and returns it as an int
def parseRake(line): def parseRake(line):
pos = line.find("Rake")+6 pos = line.find("Rake")+6
rake = float2int(line[pos:]) rake = float2int(line[pos:])
return rake return rake
#end def parseRake
def parseSiteHandNo(topline): def parseSiteHandNo(topline):
"""returns the hand no assigned by the poker site""" """returns the hand no assigned by the poker site"""
pos1 = topline.find("#")+1 pos1 = topline.find("#")+1
pos2 = topline.find(":") pos2 = topline.find(":")
return topline[pos1:pos2] return topline[pos1:pos2]
#end def parseSiteHandNo
def parseTableLine(base, line): def parseTableLine(base, line):
"""returns a dictionary with maxSeats and tableName""" """returns a dictionary with maxSeats and tableName"""
@ -808,7 +780,6 @@ def parseTourneyNo(topline):
pos2 = topline.find(",", pos1) pos2 = topline.find(",", pos1)
#print "parseTourneyNo pos1:",pos1," pos2:",pos2, " result:",topline[pos1:pos2] #print "parseTourneyNo pos1:",pos1," pos2:",pos2, " result:",topline[pos1:pos2]
return topline[pos1:pos2] return topline[pos1:pos2]
#end def parseTourneyNo
#parses a win/collect line. manipulates the passed array winnings, no explicit return #parses a win/collect line. manipulates the passed array winnings, no explicit return
def parseWinLine(line, names, winnings, isTourney): def parseWinLine(line, names, winnings, isTourney):
@ -824,7 +795,6 @@ def parseWinLine(line, names, winnings, isTourney):
pos1 = line.rfind("$") + 1 pos1 = line.rfind("$") + 1
pos2 = line.find(" ", pos1) pos2 = line.find(" ", pos1)
winnings[i] += float2int(line[pos1:pos2]) winnings[i] += float2int(line[pos1:pos2])
#end def parseWinLine
#returns the category (as per database) string for the given line #returns the category (as per database) string for the given line
def recogniseCategory(line): def recogniseCategory(line):
@ -844,7 +814,6 @@ def recogniseCategory(line):
return "studhilo" return "studhilo"
else: else:
raise FpdbError("failed to recognise category, line:"+line) raise FpdbError("failed to recognise category, line:"+line)
#end def recogniseCategory
#returns the int for the gametype_id for the given line #returns the int for the gametype_id for the given line
def recogniseGametypeID(backend, db, cursor, topline, smallBlindLine, site_id, category, isTourney):#todo: this method is messy def recogniseGametypeID(backend, db, cursor, topline, smallBlindLine, site_id, category, isTourney):#todo: this method is messy
@ -855,7 +824,9 @@ def recogniseGametypeID(backend, db, cursor, topline, smallBlindLine, site_id, c
if isTourney: if isTourney:
type = "tour" type = "tour"
pos1 = topline.find("(")+1 pos1 = topline.find("(")+1
if (topline[pos1]=="H" or topline[pos1]=="O" or topline[pos1]=="R" or topline[pos1]=="S" or topline[pos1+2]=="C"): if(topline[pos1] == "H" or topline[pos1] == "O" or
topline[pos1] == "R" or topline[pos1]=="S" or
topline[pos1+2] == "C"):
pos1 = topline.find("(", pos1)+1 pos1 = topline.find("(", pos1)+1
pos2 = topline.find("/", pos1) pos2 = topline.find("/", pos1)
small_bet = int(topline[pos1:pos2]) small_bet = int(topline[pos1:pos2])
@ -878,24 +849,22 @@ def recogniseGametypeID(backend, db, cursor, topline, smallBlindLine, site_id, c
else: else:
big_bet = float2int(topline[pos1:pos2]) big_bet = float2int(topline[pos1:pos2])
if (topline.find("No Limit")!=-1): if 'No Limit' in topline:
limit_type="nl" limit_type = "nl" if 'Cap No' not in topline else "cn"
if (topline.find("Cap No")!=-1): elif 'Pot Limit' in topline:
limit_type="cn" limit_type = "pl" if 'Cap Pot' not in topline else "cp"
elif (topline.find("Pot Limit")!=-1):
limit_type="pl"
if (topline.find("Cap Pot")!=-1):
limit_type="cp"
else: else:
limit_type = "fl" limit_type = "fl"
#print "recogniseGametypeID small_bet/blind:",small_bet,"big bet/blind:", big_bet,"limit type:",limit_type #print "recogniseGametypeID small_bet/blind:",small_bet,"big bet/blind:", big_bet,"limit type:",limit_type
if (limit_type=="fl"): if limit_type == "fl":
cursor.execute ( db.sql.query['getGametypeFL'] cursor.execute(db.sql.query['getGametypeFL'], (site_id, type, category,
, (site_id, type, category, limit_type, small_bet, big_bet)) limit_type, small_bet,
big_bet))
else: else:
cursor.execute ( db.sql.query['getGametypeNL'] cursor.execute(db.sql.query['getGametypeNL'], (site_id, type, category,
, (site_id, type, category, limit_type, small_bet, big_bet)) limit_type, small_bet,
big_bet))
result = cursor.fetchone() result = cursor.fetchone()
#print "recgt1 result=",result #print "recgt1 result=",result
#ret=result[0] #ret=result[0]