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,12 +1126,8 @@ 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
@ -1143,8 +1139,8 @@ def parsePositions (hand, names):
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")
@ -1290,17 +1286,19 @@ 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:
if "Hi/Lo" not in line and "H/L" not in line:
return "omahahi" return "omahahi"
elif (line.find("Omaha")!=-1 and (line.find("Hi/Lo")!=-1 or line.find("H/L")!=-1)): else:
return "omahahilo" return "omahahilo"
elif (line.find("Stud")!=-1 and line.find("Hi/Lo")==-1 and line.find("H/L")==-1): elif "Stud" in line:
if "Hi/Lo" not in line and "H/L" not in line:
return "studhi" return "studhi"
elif (line.find("Stud")!=-1 and (line.find("Hi/Lo")!=-1 or line.find("H/L")!=-1)): else:
return "studhilo" return "studhilo"
else: else:
raise FpdbError("failed to recognise category, line:"+line) raise FpdbError("failed to recognise category, line:"+line)