stripEOLspaces = rstrip, cleanup filterCrap some more, cleanup ParseActionType, should no longer count lines with player names containing "bets" or "raises" as an action, parseHandStartTime no longer uses an infinite loop, parsePositions cleaned up, parseWinLine cleaned up, recognisePlayerIDs cleaned up

This commit is contained in:
eblade 2009-03-26 17:20:08 -04:00
parent 3e6fccd34d
commit cb542d9b3e

View File

@ -616,84 +616,78 @@ def filterAnteBlindFold(site,hand):
#end def filterAnteFold #end def filterAnteFold
def stripEOLspaces(str): def stripEOLspaces(str):
if str[-1] == ' ': return str.rstrip()
str = str[:-1]
if str[-1] == ' ':
str = str[:-1]
return str
#removes useless lines as well as trailing spaces #removes useless lines as well as trailing spaces
def filterCrap(site, hand, isTourney): def filterCrap(site, hand, isTourney):
#remove two trailing spaces at end of line #remove two trailing spaces at end of line
hand = [stripEOLspaces(line) for line in hand] hand = [line.rstrip() for line in hand]
#print "hand after trailing space removal in filterCrap:",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 ["):
hand[i] = False hand[i] = False
elif (hand[i].find(" out of hand ")!=-1): elif hand[i].find(" out of hand ")!=-1:
hand[i]=hand[i][:-56] hand[i]=hand[i][:-56]
elif (hand[i].find("($0 in chips)") != -1): elif "($0 in chips)" in hand[i]:
hand[i] = False hand[i] = False
elif (hand[i]=="*** HOLE CARDS ***"): elif hand[i]=="*** HOLE CARDS ***":
hand[i] = False hand[i] = False
elif (hand[i].endswith("has been disconnected")): elif hand[i].endswith("has been disconnected"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("has requested TIME")): elif hand[i].endswith("has requested TIME"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("has returned")): elif hand[i].endswith("has returned"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("will be allowed to play after the button")): elif hand[i].endswith("will be allowed to play after the button"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("has timed out")): elif hand[i].endswith("has timed out"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("has timed out while disconnected")): elif hand[i].endswith("has timed out while disconnected"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("has timed out while being disconnected")): elif hand[i].endswith("has timed out while being disconnected"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("is connected")): elif hand[i].endswith("is connected"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("is disconnected")): elif hand[i].endswith("is disconnected"):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" is feeling angry")): elif hand[i].endswith(" is feeling angry"):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" is feeling confused")): elif hand[i].endswith(" is feeling confused"):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" is feeling happy")): elif hand[i].endswith(" is feeling happy"):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" is feeling normal")): elif hand[i].endswith(" is feeling normal"):
hand[i] = False hand[i] = False
elif (hand[i].find(" is low with [")!=-1): elif " is low with [" in hand[i]:
hand[i] = False hand[i] = False
#elif (hand[i].find("-max Seat #")!=-1 and hand[i].find(" is the button")!=-1): #elif (hand[i].find("-max Seat #")!=-1 and hand[i].find(" is the button")!=-1):
# toRemove.append(hand[i]) # toRemove.append(hand[i])
elif (hand[i].endswith(" mucks")): elif hand[i].endswith(" mucks"):
hand[i] = False hand[i] = False
elif (hand[i].endswith(": mucks hand")): elif hand[i].endswith(": mucks hand"):
hand[i] = False hand[i] = False
elif (hand[i]=="No low hand qualified"): elif hand[i] == "No low hand qualified":
hand[i] = False hand[i] = False
elif (hand[i]=="Pair on board - a double bet is allowed"): elif hand[i] == "Pair on board - a double bet is allowed":
hand[i] = False hand[i] = False
elif (hand[i].find(" shows ")!=-1 and hand[i].find("[")==-1): elif " shows " in hand[i] and "[" not in hand[i]:
hand[i] = False hand[i] = False
#elif (hand[i].startswith("Table '") and hand[i].endswith("-max")): elif hand[i].startswith("The button is in seat #"):
# toRemove.append(hand[i])
elif (hand[i].startswith("The button is in seat #")):
hand[i] = False hand[i] = False
#above is alphabetic, reorder below if bored #above is alphabetic, reorder below if bored
elif (hand[i].startswith("Time has expired")): elif hand[i].startswith("Time has expired"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("has reconnected")): elif hand[i].endswith("has reconnected"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("seconds left to act")): elif hand[i].endswith("seconds left to act"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("seconds to reconnect")): elif hand[i].endswith("seconds to reconnect"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("was removed from the table for failing to post")): elif hand[i].endswith("was removed from the table for failing to post"):
hand[i] = False hand[i] = False
elif (hand[i].find("joins the table at seat ")!=-1): elif "joins the table at seat " in hand[i]:
hand[i] = False hand[i] = False
elif (hand[i].endswith(" sits down")): elif (hand[i].endswith(" sits down")):
hand[i] = False hand[i] = False
@ -701,20 +695,20 @@ def filterCrap(site, hand, isTourney):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" stands up")): elif (hand[i].endswith(" stands up")):
hand[i] = False hand[i] = False
elif (hand[i].find("is high with ")!=-1): elif "is high with" in hand[i]:
hand[i] = False hand[i] = False
elif (hand[i].endswith("doesn't show hand")): elif hand[i].endswith("doesn't show hand"):
hand[i] = False hand[i] = False
elif (hand[i].endswith("is being treated as all-in")): elif hand[i].endswith("is being treated as all-in"):
hand[i] = False hand[i] = False
elif (hand[i].find(" adds $")!=-1): elif " adds $" in hand[i]:
hand[i] = False hand[i] = False
elif (hand[i]=="Betting is capped"): elif hand[i] == "Betting is capped":
hand[i] = False hand[i] = False
#site specific variable position filter #site specific variable position filter
elif (hand[i].find(" said, \"")!=-1): elif 'said, "' in hand[i]:
hand[i] = False hand[i] = False
elif (hand[i].find(": ")!=-1 and site=="ftp" and hand[i].find("Seat ")==-1 and hand[i].find(": Table")==-1): #filter ftp chat elif site == "ftp" and ":" in hand[i] and "Seat " not in hand[i] and ": Table" not in hand[i]: # FTP chat
hand[i] = False hand[i] = False
if isTourney and not hand[i] == False: if isTourney and not hand[i] == False:
if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))): if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))):
@ -734,11 +728,11 @@ def filterCrap(site, hand, isTourney):
#takes a poker float (including , for thousand seperator and converts it to an int #takes a poker float (including , for thousand seperator and converts it to an int
def float2int(string): def float2int(string):
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:])
pos = string.find(".") pos = string.find(".")
if (pos!=-1): #remove decimal point if pos != -1: #remove decimal point
string = "%s%s" % (string[0:pos], string[pos+1:]) string = "%s%s" % (string[0:pos], string[pos+1:])
result = int(string) result = int(string)
@ -884,6 +878,12 @@ def goesAllInOnThisLine(line):
#end def goesAllInOnThisLine #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 = { 'calls':"call", 'brings in for':"blind", 'completes it to':"bet", ' posts $':"blind",
' posts a dead ' : "blind", ' posts the small blind of $':"blind", ': posts big blind ':"blind",
' posts the big blind of $':"blind", ': posts small & big blinds $':"blind",
': posts small blind $':"blind",
'bets' : "bet", 'raises' : "bet"
}
def parseActionType(line): def parseActionType(line):
if (line.startswith("Uncalled bet")): if (line.startswith("Uncalled bet")):
return "unbet" return "unbet"
@ -891,33 +891,10 @@ def parseActionType(line):
return "fold" return "fold"
elif (line.endswith("checks")): elif (line.endswith("checks")):
return "check" return "check"
elif (line.find("calls")!=-1):
return "call"
elif (line.find("brings in for")!=-1):
return "blind"
elif (line.find("completes it to")!=-1):
return "bet"
#todo: what if someone completes instead of bringing in?
elif (line.find(" posts $")!=-1):
return "blind"
elif (line.find(" posts a dead ")!=-1):
return "blind"
elif (line.find(": posts small blind ")!=-1):
return "blind"
elif (line.find(" posts the small blind of $")!=-1):
return "blind"
elif (line.find(": posts big blind ")!=-1):
return "blind"
elif (line.find(" posts the big blind of $")!=-1):
return "blind"
elif (line.find(": posts small & big blinds $")!=-1):
return "blind"
#todo: seperately record voluntary blind payments made to join table out of turn
elif (line.find("bets")!=-1):
return "bet"
elif (line.find("raises")!=-1):
return "bet"
else: else:
for x in ActionTypes:
if x in line:
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 #end def parseActionType
@ -1053,12 +1030,12 @@ def parseFee(topline):
def parseHandStartTime(topline, site): def parseHandStartTime(topline, site):
#convert x:13:35 to 0x:13:35 #convert x:13:35 to 0x:13:35
counter=0 counter=0
while (True): while counter < 10:
pos=topline.find(" "+str(counter)+":") pos = topline.find(" %d:" % counter)
if (pos!=-1): if pos != -1:
topline=topline[0:pos+1]+"0"+topline[pos+1:] topline = "%s0%s" % (topline[0:pos+1], topline[pos+1:])
break
counter += 1 counter += 1
if counter==10: break
isUTC=False isUTC=False
if site=="ftp": if site=="ftp":
@ -1116,46 +1093,44 @@ def parseNames(lines):
#end def parseNames #end def parseNames
def parsePositions(hand, names): def parsePositions(hand, names):
positions = map(lambda x: -1, names) positions = [-1 for i in names]
sb, bb = -1, -1
#find blinds #find blinds
sb,bb=-1,-1 for line in hand:
for i in xrange (len(hand)): if sb == -1 and "small blind" in line and "dead small blind" not in line:
if (sb==-1 and hand[i].find("small blind")!=-1 and hand[i].find("dead small blind")==-1): sb = line
sb=hand[i] if bb == -1 and "big blind" in line and "dead big blind" not in line:
#print "sb:",sb bb = line
if (bb==-1 and hand[i].find("big blind")!=-1 and hand[i].find("dead big blind")==-1):
bb=hand[i]
#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: # if big and small are same, then don't duplicate the small
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
@ -1183,8 +1158,7 @@ def parsePositions(hand, names):
arraypos-=1 arraypos-=1
distFromBtn+=1 distFromBtn+=1
for i in xrange (len(names)): if -1 in names:
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")
@ -1255,20 +1229,21 @@ def parseTourneyNo(topline):
#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, site, names, winnings, isTourney): def parseWinLine(line, site, names, winnings, isTourney):
#print "parseWinLine: line:",line #print "parseWinLine: line:",line
for i in xrange(len(names)): for i,n in enumerate(names):
if (line.startswith(names[i].encode("latin-1"))): #found a winner n = n.encode("latin-1")
if line.startswith(n):
if isTourney: if isTourney:
pos1 = line.rfind("collected ") + 10 pos1 = line.rfind("collected ") + 10
if (site=="ftp"): if site == "ftp":
pos2 = line.find(")", pos1) pos2 = line.find(")", pos1)
elif (site=="ps"): elif site == "ps":
pos2 = line.find(" ", pos1) pos2 = line.find(" ", pos1)
winnings[i] += int(line[pos1:pos2]) winnings[i] += int(line[pos1:pos2])
else: else:
pos1 = line.rfind("$") + 1 pos1 = line.rfind("$") + 1
if (site=="ftp"): if site == "ftp":
pos2 = line.find(")", pos1) pos2 = line.find(")", pos1)
elif (site=="ps"): elif site == "ps":
pos2 = line.find(" ", pos1) pos2 = line.find(" ", pos1)
winnings[i] += float2int(line[pos1:pos2]) winnings[i] += float2int(line[pos1:pos2])
#end def parseWinLine #end def parseWinLine
@ -1417,16 +1392,16 @@ def recogniseTourneyTypeId(cursor, siteId, buyin, fee, knockout, rebuyOrAddon):
#returns the SQL ids of the names given in an array #returns the SQL ids of the names given in an array
def recognisePlayerIDs(cursor, names, site_id): def recognisePlayerIDs(cursor, names, site_id):
result = [] result = []
for i in xrange(len(names)): for n in names:
cursor.execute ("SELECT id FROM Players WHERE name=%s", (names[i],)) cursor.execute("SELECT id FROM Players WHERE name=%s", (n,))
tmp = cursor.fetchall() tmp = cursor.fetchall()
if (len(tmp)==0): #new player if len(tmp) == 0:
cursor.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (names[i], site_id)) cursor.execute("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (n, site_id))
#print "Number of players rows inserted: %d" % cursor.rowcount cursor.execute("SELECT id FROM Players WHERE name=%s", (n,))
cursor.execute ("SELECT id FROM Players WHERE name=%s", (names[i],))
tmp = cursor.fetchall() tmp = cursor.fetchall()
#print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp
result.append(tmp[0][0]) result.append(tmp[0][0])
return result return result
#end def recognisePlayerIDs #end def recognisePlayerIDs