fpdb_parse_logic: cleanup
This commit is contained in:
parent
4c67cad27a
commit
a424a9c77d
|
@ -23,10 +23,9 @@ import fpdb_save_to_db
|
|||
#parses a holdem hand
|
||||
def mainParser(backend, db, cursor, site, category, hand, config):
|
||||
category = fpdb_simple.recogniseCategory(hand[0])
|
||||
if (category=="holdem" or category=="omahahi" or category=="omahahilo"):
|
||||
base="hold"
|
||||
else:
|
||||
base="stud"
|
||||
|
||||
base = "hold" if category == "holdem" or category == "omahahi" or ctegory == "omahahilo" else "stud"
|
||||
|
||||
#part 0: create the empty arrays
|
||||
lineTypes = [] #char, valid values: header, name, cards, action, win, rake, ignore
|
||||
lineStreets = [] #char, valid values: (predeal, preflop, flop, turn, river)
|
||||
|
@ -41,14 +40,13 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
|
||||
isTourney = fpdb_simple.isTourney(hand[0])
|
||||
smallBlindLine = 0
|
||||
for i in range(len(hand)):
|
||||
if 'posts small blind' in hand[i] or 'posts the small blind' in hand[i]:
|
||||
if hand[i][-2:] == "$0":
|
||||
continue
|
||||
for i, line in enumerate(hand):
|
||||
if 'posts small blind' in line or 'posts the small blind' in line:
|
||||
if line[-2:] == "$0": continue
|
||||
smallBlindLine = i
|
||||
#print "found small blind line:",smallBlindLine
|
||||
break
|
||||
#print "small blind line:",smallBlindLine
|
||||
|
||||
gametypeID = fpdb_simple.recogniseGametypeID(backend, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
||||
if isTourney:
|
||||
if site != "ps":
|
||||
|
@ -63,6 +61,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
||||
|
||||
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
||||
|
||||
fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo)
|
||||
|
||||
#part 2: classify lines by type (e.g. cards, action, win, sectionchange) and street
|
||||
|
@ -70,9 +69,10 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
|
||||
#part 3: read basic player info
|
||||
#3a read player names, startcashes
|
||||
for i in range (len(hand)): #todo: use maxseats+1 here.
|
||||
if (lineTypes[i]=="name"):
|
||||
seatLines.append(hand[i])
|
||||
for i, line in enumerate(hand):
|
||||
if lineTypes[i] == "name":
|
||||
seatLines.append(line)
|
||||
|
||||
names = fpdb_simple.parseNames(seatLines)
|
||||
playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID)
|
||||
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines, site)
|
||||
|
@ -86,33 +86,32 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
positions = fpdb_simple.parsePositions(hand, names)
|
||||
|
||||
#part 4: take appropriate action for each line based on linetype
|
||||
for i in range(len(hand)):
|
||||
if (lineTypes[i]=="cards"):
|
||||
fpdb_simple.parseCardLine (site, category, lineStreets[i], hand[i], names, cardValues, cardSuits, boardValues, boardSuits)
|
||||
for i, line in enumerate(hand):
|
||||
if lineTypes[i] == "cards":
|
||||
fpdb_simple.parseCardLine(site, category, lineStreets[i], line, names, cardValues, cardSuits, boardValues, boardSuits)
|
||||
#if category=="studhilo":
|
||||
# print "hand[i]:", hand[i]
|
||||
# print "cardValues:", cardValues
|
||||
# print "cardSuits:", cardSuits
|
||||
elif (lineTypes[i]=="action"):
|
||||
fpdb_simple.parseActionLine (site, base, isTourney, hand[i], lineStreets[i], playerIDs, names, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo)
|
||||
elif (lineTypes[i]=="win"):
|
||||
fpdb_simple.parseWinLine (hand[i], site, names, winnings, isTourney)
|
||||
elif (lineTypes[i]=="rake"):
|
||||
if isTourney:
|
||||
totalRake=0
|
||||
else:
|
||||
totalRake=fpdb_simple.parseRake(hand[i])
|
||||
elif lineTypes[i] == "action":
|
||||
fpdb_simple.parseActionLine(site, base, isTourney, line, lineStreets[i], playerIDs, names, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo)
|
||||
elif lineTypes[i] == "win":
|
||||
fpdb_simple.parseWinLine(line, site, names, winnings, isTourney)
|
||||
elif lineTypes[i] == "rake":
|
||||
totalRake = 0 if isTourney else fpdb_simple.parseRake(line)
|
||||
fpdb_simple.splitRake(winnings, rakes, totalRake)
|
||||
elif (lineTypes[i]=="header" or lineTypes[i]=="rake" or lineTypes[i]=="name" or lineTypes[i]=="ignore"):
|
||||
elif lineTypes[i]=="header" or lineTypes[i]=="rake" or lineTypes[i]=="name" or lineTypes[i]=="ignore":
|
||||
pass
|
||||
elif (lineTypes[i]=="ante"):
|
||||
fpdb_simple.parseAnteLine(hand[i], site, isTourney, names, antes)
|
||||
elif (lineTypes[i]=="table"):
|
||||
tableResult=fpdb_simple.parseTableLine(site, base, hand[i])
|
||||
elif lineTypes[i]=="ante":
|
||||
fpdb_simple.parseAnteLine(line, site, isTourney, names, antes)
|
||||
elif lineTypes[i]=="table":
|
||||
tableResult=fpdb_simple.parseTableLine(site, base, line)
|
||||
else:
|
||||
raise fpdb_simple.FpdbError("unrecognised lineType:"+lineTypes[i])
|
||||
|
||||
if site == "ftp":
|
||||
tableResult = fpdb_simple.parseTableLine(site, base, hand[0])
|
||||
|
||||
maxSeats = tableResult['maxSeats']
|
||||
tableName = tableResult['tableName']
|
||||
#print "before part5, antes:", antes
|
||||
|
@ -129,10 +128,9 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
limit_type = cursor.fetchone()[0]
|
||||
fpdb_simple.convert3B4B(site, category, limit_type, actionTypes, actionAmounts)
|
||||
|
||||
totalWinnings=0
|
||||
for i in range(len(winnings)):
|
||||
totalWinnings+=winnings[i]
|
||||
totalWinnings = sum(winnings)
|
||||
|
||||
# if hold'em, use positions and not antes, if stud do not use positions, use antes
|
||||
if base == "hold":
|
||||
hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
|
||||
, allIns, actionTypeByNo, winnings, totalWinnings, positions
|
||||
|
@ -144,8 +142,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
|
||||
if isTourney:
|
||||
ranks = []
|
||||
for i in range (len(names)):
|
||||
ranks.append(0)
|
||||
map(lambda x: 0, names) # create an array of 0's equal to the length of names
|
||||
payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee)
|
||||
|
||||
if base == "hold":
|
||||
|
@ -167,7 +164,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
, allIns, actionAmounts, actionNos, hudImportData, maxSeats
|
||||
, tableName, seatNos)
|
||||
else:
|
||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
||||
raise fpdb_simple.FpdbError("unrecognised category") # it's impossible to get here, but w/e
|
||||
else:
|
||||
if base == "hold":
|
||||
result = fpdb_save_to_db.ring_holdem_omaha(
|
||||
|
@ -185,7 +182,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
|||
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
|
||||
, seatNos)
|
||||
else:
|
||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
||||
raise fpdb_simple.FpdbError ("unrecognised category") # also impossible to get here
|
||||
db.commit()
|
||||
return result
|
||||
#end def mainParser
|
||||
|
|
Loading…
Reference in New Issue
Block a user