more cleanup

This commit is contained in:
eblade 2009-03-18 22:31:39 -04:00
parent c6179a1b85
commit 4830b72121

View File

@ -831,22 +831,22 @@ def parseActionAmount(line, atype, site, isTourney):
pos2 = line.find(")") pos2 = line.find(")")
amount = float2int(line[pos1:pos2]) amount = float2int(line[pos1:pos2])
elif atype == "bet" and site == "ps" and line.find(": raises $")!=-1 and line.find("to $")!=-1: elif atype == "bet" and site == "ps" and line.find(": raises $")!=-1 and line.find("to $")!=-1:
pos=line.find("to $")+4 pos = line.find("to $")+4
amount=float2int(line[pos:]) amount = float2int(line[pos:])
else: else:
if not isTourney: if not isTourney:
pos=line.rfind("$")+1 pos = line.rfind("$")+1
#print "parseActionAmount, line:", line, "line[pos:]:", line[pos:] #print "parseActionAmount, line:", line, "line[pos:]:", line[pos:]
amount=float2int(line[pos:]) amount = float2int(line[pos:])
else: else:
#print "line:"+line+"EOL" #print "line:"+line+"EOL"
pos=line.rfind(" ")+1 pos = line.rfind(" ")+1
#print "pos:",pos #print "pos:",pos
#print "pos of 20:", line.find("20") #print "pos of 20:", line.find("20")
amount=int(line[pos:]) amount = int(line[pos:])
if atype=="unbet": if atype == "unbet":
amount*=-1 amount *= -1
return amount return amount
#end def parseActionAmount #end def parseActionAmount
@ -854,25 +854,25 @@ def parseActionAmount(line, atype, site, isTourney):
# action_amounts. For stud this expects numeric streets (3-7), for # action_amounts. For stud this expects numeric streets (3-7), for
# holdem/omaha it expects predeal, preflop, flop, turn or river # holdem/omaha it expects predeal, preflop, flop, turn or river
def parseActionLine(site, base, isTourney, line, street, playerIDs, names, action_types, allIns, action_amounts, actionNos, actionTypeByNo): def parseActionLine(site, base, isTourney, line, street, playerIDs, names, action_types, allIns, action_amounts, actionNos, actionTypeByNo):
if (street=="predeal" or street=="preflop"): if street == "predeal" or street == "preflop":
street=0 street = 0
elif (street=="flop"): elif street == "flop":
street=1 street = 1
elif (street=="turn"): elif street == "turn":
street=2 street = 2
elif (street=="river"): elif street == "river":
street=3 street = 3
nextActionNo=0 nextActionNo = 0
for player in xrange(len(actionNos[street])): for player in xrange(len(actionNos[street])):
for count in xrange(len(actionNos[street][player])): for count in xrange(len(actionNos[street][player])):
if actionNos[street][player][count]>=nextActionNo: if actionNos[street][player][count]>=nextActionNo:
nextActionNo=actionNos[street][player][count]+1 nextActionNo=actionNos[street][player][count]+1
line, allIn=goesAllInOnThisLine(line) (line, allIn) = goesAllInOnThisLine(line)
atype=parseActionType(line) atype = parseActionType(line)
playerno=recognisePlayerNo(line, names, atype) playerno = recognisePlayerNo(line, names, atype)
amount=parseActionAmount(line, atype, site, isTourney) amount = parseActionAmount(line, atype, site, isTourney)
action_types[street][playerno].append(atype) action_types[street][playerno].append(atype)
allIns[street][playerno].append(allIn) allIns[street][playerno].append(allIn)
@ -884,13 +884,13 @@ def parseActionLine(site, base, isTourney, line, street, playerIDs, names, actio
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."""
isAllIn=False isAllIn = False
if (line.endswith(" and is all-in")): if (line.endswith(" and is all-in")):
line=line[:-14] line = line[:-14]
isAllIn=True isAllIn = True
elif (line.endswith(", and is all in")): elif (line.endswith(", and is all in")):
line=line[:-15] line = line[:-15]
isAllIn=True isAllIn = True
return (line, isAllIn) return (line, isAllIn)
#end def goesAllInOnThisLine #end def goesAllInOnThisLine
@ -934,48 +934,48 @@ 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, site, isTourney, names, antes): def parseAnteLine(line, site, isTourney, names, antes):
for i in xrange(len(names)): for i, name in enumerate(names):
if (line.startswith(names[i].encode("latin-1"))): #found the ante'er if line.startswith(name.encode("latin-1")):
pos=line.rfind("$")+1 pos = line.rfind("$") + 1
if not isTourney: if not isTourney:
antes[i]+=float2int(line[pos:]) antes[i] += float2int(line[pos:])
else: else:
if line.find("all-in")==-1: if "all-in" not in line:
pos=line.rfind(" ")+1 pos = line.rfind(" ") + 1
antes[i]+=int(line[pos:]) antes[i] += int(line[pos:])
else: else:
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 #print "parseAnteLine line: ", line, "antes[i]", antes[i], "antes", antes
#end def parseAntes #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 #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
def parseCardLine(site, category, street, line, names, cardValues, cardSuits, boardValues, boardSuits): def parseCardLine(site, category, street, line, names, cardValues, cardSuits, boardValues, boardSuits):
if (line.startswith("Dealt to ") or line.find(" shows [")!=-1 or line.find("mucked [")!=-1): if line.startswith("Dealt to") or " shows [" in line or "mucked [" in line:
playerNo=recognisePlayerNo(line, names, "card") #anything but unbet will be ok for that string playerNo = recognisePlayerNo(line, names, "card") #anything but unbet will be ok for that string
pos=line.rfind("[")+1 pos = line.rfind("[")+1
if (category=="holdem"): if category == "holdem":
for i in (pos, pos+3): for i in (pos, pos+3):
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]: #two tests will do
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:
print "line:",line,"cardValues[playerNo]:",cardValues[playerNo] print "line:",line,"cardValues[playerNo]:",cardValues[playerNo]
raise FpdbError("read too many/too few holecards in parseCardLine") raise FpdbError("read too many/too few holecards in parseCardLine")
elif (category=="omahahi" or category=="omahahilo"): elif category == "omahahi" or category == "omahahilo":
for i in (pos, pos+3, pos+6, pos+9): for i in (pos, pos+3, pos+6, pos+9):
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])
@ -986,8 +986,8 @@ def parseCardLine(site, category, street, line, names, cardValues, cardSuits, bo
else: else:
print "line:",line,"cardValues[playerNo]:",cardValues[playerNo] print "line:",line,"cardValues[playerNo]:",cardValues[playerNo]
raise FpdbError("read too many/too few holecards in parseCardLine") raise FpdbError("read too many/too few holecards in parseCardLine")
elif (category=="razz" or category=="studhi" or category=="studhilo"): elif category=="razz" or category=="studhi" or category=="studhilo":
if (line.find("shows")==-1 and line.find("mucked")==-1): if "shows" not in line and "mucked" not in line:
#print "parseCardLine(in stud if), street:", street #print "parseCardLine(in stud if), street:", street
if line[pos+2]=="]": #-> not (hero and 3rd street) if line[pos+2]=="]": #-> not (hero and 3rd street)
cardValues[playerNo][street+2]=line[pos:pos+1] cardValues[playerNo][street+2]=line[pos:pos+1]
@ -1126,85 +1126,81 @@ def parseNames(lines):
return result return result
#end def parseNames #end def parseNames
#returns an array with the positions of the respective players def parsePositions(hand, names):
def parsePositions (hand, names): positions = map(lambda x: -1, names)
#prep array
positions=[]
for i in xrange(len(names)):
positions.append(-1)
#find blinds #find blinds
sb,bb=-1,-1 sb,bb=-1,-1
for i in xrange (len(hand)): for i in xrange (len(hand)):
if (sb==-1 and hand[i].find("small blind")!=-1 and hand[i].find("dead small blind")==-1): if (sb==-1 and hand[i].find("small blind")!=-1 and hand[i].find("dead small blind")==-1):
sb=hand[i] sb=hand[i]
#print "sb:",sb #print "sb:",sb
if (bb==-1 and hand[i].find("big blind")!=-1 and hand[i].find("dead big blind")==-1): if (bb==-1 and hand[i].find("big blind")!=-1 and hand[i].find("dead big blind")==-1):
bb=hand[i] bb=hand[i]
#print "bb:",bb #print "bb:",bb
#identify blinds #identify blinds
#print "parsePositions before recognising sb/bb. names:",names #print "parsePositions before recognising sb/bb. names:",names
sbExists=True sbExists=True
if (sb!=-1): if (sb!=-1):
sb=recognisePlayerNo(sb, names, "bet") sb=recognisePlayerNo(sb, names, "bet")
else: else:
sbExists=False sbExists=False
if (bb!=-1): if (bb!=-1):
bb=recognisePlayerNo(bb, names, "bet") bb=recognisePlayerNo(bb, names, "bet")
# print "sb = ", sb, "bb = ", bb # print "sb = ", sb, "bb = ", bb
if bb == sb: if bb == sb:
sbExists = False sbExists = False
sb = -1 sb = -1
#write blinds into array #write blinds into array
if (sbExists): if (sbExists):
positions[sb]="S" positions[sb]="S"
positions[bb]="B" positions[bb]="B"
#fill up rest of array #fill up rest of array
if (sbExists): if (sbExists):
arraypos=sb-1 arraypos=sb-1
else: else:
arraypos=bb-1 arraypos=bb-1
distFromBtn=0 distFromBtn=0
while (arraypos>=0 and arraypos != bb): while (arraypos>=0 and arraypos != bb):
#print "parsePositions first while, arraypos:",arraypos,"positions:",positions #print "parsePositions first while, arraypos:",arraypos,"positions:",positions
positions[arraypos]=distFromBtn positions[arraypos]=distFromBtn
arraypos-=1 arraypos-=1
distFromBtn+=1 distFromBtn+=1
# eric - this takes into account dead seats between blinds # eric - this takes into account dead seats between blinds
if sbExists: if sbExists:
i = bb - 1 i = bb - 1
while positions[i] < 0 and i != sb: while positions[i] < 0 and i != sb:
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: if sbExists:
i = sb-1 i = sb-1
else: else:
i = bb-1 i = bb-1
while positions[i] < 0: while positions[i] < 0:
positions[i]=9 positions[i]=9
i-=1 i-=1
arraypos=len(names)-1 arraypos=len(names)-1
if (bb!=0 or (bb==0 and sbExists==False) or (bb == 1 and sb != arraypos) ): if (bb!=0 or (bb==0 and sbExists==False) or (bb == 1 and sb != arraypos) ):
while (arraypos>bb and arraypos > sb): while (arraypos>bb and arraypos > sb):
positions[arraypos]=distFromBtn positions[arraypos]=distFromBtn
arraypos-=1 arraypos-=1
distFromBtn+=1 distFromBtn+=1
for i in xrange (len(names)): for i in xrange (len(names)):
if positions[i]==-1: if positions[i]==-1:
print "parsePositions names:",names print "parsePositions names:",names
print "result:",positions print "result:",positions
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 #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
@ -1290,18 +1286,20 @@ def parseWinLine(line, site, names, winnings, isTourney):
#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):
if (line.find("Razz")!=-1): if "Razz" in line:
return "razz" return "razz"
elif (line.find("Hold'em")!=-1): elif "Hold'em" in line:
return "holdem" return "holdem"
elif (line.find("Omaha")!=-1 and line.find("Hi/Lo")==-1 and line.find("H/L")==-1): elif "Omaha" in line:
return "omahahi" if "Hi/Lo" not in line and "H/L" not in line:
elif (line.find("Omaha")!=-1 and (line.find("Hi/Lo")!=-1 or line.find("H/L")!=-1)): return "omahahi"
return "omahahilo" else:
elif (line.find("Stud")!=-1 and line.find("Hi/Lo")==-1 and line.find("H/L")==-1): return "omahahilo"
return "studhi" elif "Stud" in line:
elif (line.find("Stud")!=-1 and (line.find("Hi/Lo")!=-1 or line.find("H/L")!=-1)): if "Hi/Lo" not in line and "H/L" not in line:
return "studhilo" return "studhi"
else:
return "studhilo"
else: else:
raise FpdbError("failed to recognise category, line:"+line) raise FpdbError("failed to recognise category, line:"+line)
#end def recogniseCategory #end def recogniseCategory