fpdb_parse_logic: cleanup
This commit is contained in:
parent
4c67cad27a
commit
a424a9c77d
|
@ -22,47 +22,46 @@ import fpdb_save_to_db
|
||||||
|
|
||||||
#parses a holdem hand
|
#parses a holdem hand
|
||||||
def mainParser(backend, db, cursor, site, category, hand, config):
|
def mainParser(backend, db, cursor, site, category, hand, config):
|
||||||
category=fpdb_simple.recogniseCategory(hand[0])
|
category = fpdb_simple.recogniseCategory(hand[0])
|
||||||
if (category=="holdem" or category=="omahahi" or category=="omahahilo"):
|
|
||||||
base="hold"
|
base = "hold" if category == "holdem" or category == "omahahi" or ctegory == "omahahilo" else "stud"
|
||||||
else:
|
|
||||||
base="stud"
|
|
||||||
#part 0: create the empty arrays
|
#part 0: create the empty arrays
|
||||||
lineTypes=[] #char, valid values: header, name, cards, action, win, rake, ignore
|
lineTypes = [] #char, valid values: header, name, cards, action, win, rake, ignore
|
||||||
lineStreets=[] #char, valid values: (predeal, preflop, flop, turn, river)
|
lineStreets = [] #char, valid values: (predeal, preflop, flop, turn, river)
|
||||||
|
|
||||||
cardValues, cardSuits, boardValues, boardSuits, antes, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo, seatLines, winnings, rakes=[],[],[],[],[],[],[],[],[],[],[],[],[]
|
cardValues, cardSuits, boardValues, boardSuits, antes, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo, seatLines, winnings, rakes=[],[],[],[],[],[],[],[],[],[],[],[],[]
|
||||||
|
|
||||||
#part 1: read hand no and check for duplicate
|
#part 1: read hand no and check for duplicate
|
||||||
siteHandNo=fpdb_simple.parseSiteHandNo(hand[0])
|
siteHandNo = fpdb_simple.parseSiteHandNo(hand[0])
|
||||||
handStartTime=fpdb_simple.parseHandStartTime(hand[0], site)
|
handStartTime = fpdb_simple.parseHandStartTime(hand[0], site)
|
||||||
siteID=fpdb_simple.recogniseSiteID(cursor, site)
|
siteID = fpdb_simple.recogniseSiteID(cursor, site)
|
||||||
#print "parse logic, siteID:",siteID,"site:",site
|
#print "parse logic, siteID:",siteID,"site:",site
|
||||||
|
|
||||||
isTourney=fpdb_simple.isTourney(hand[0])
|
isTourney = fpdb_simple.isTourney(hand[0])
|
||||||
smallBlindLine=0
|
smallBlindLine = 0
|
||||||
for i in range(len(hand)):
|
for i, line in enumerate(hand):
|
||||||
if 'posts small blind' in hand[i] or 'posts the small blind' in hand[i]:
|
if 'posts small blind' in line or 'posts the small blind' in line:
|
||||||
if hand[i][-2:] == "$0":
|
if line[-2:] == "$0": continue
|
||||||
continue
|
smallBlindLine = i
|
||||||
smallBlindLine=i
|
|
||||||
#print "found small blind line:",smallBlindLine
|
|
||||||
break
|
break
|
||||||
#print "small blind line:",smallBlindLine
|
#print "small blind line:",smallBlindLine
|
||||||
gametypeID=fpdb_simple.recogniseGametypeID(backend, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
|
||||||
if isTourney:
|
|
||||||
if site!="ps":
|
|
||||||
raise fpdb_simple.FpdbError("tourneys are only supported on PS right now")
|
|
||||||
siteTourneyNo=fpdb_simple.parseTourneyNo(hand[0])
|
|
||||||
buyin=fpdb_simple.parseBuyin(hand[0])
|
|
||||||
fee=fpdb_simple.parseFee(hand[0])
|
|
||||||
entries=-1 #todo: parse this
|
|
||||||
prizepool=-1 #todo: parse this
|
|
||||||
knockout=0
|
|
||||||
tourneyStartTime=handStartTime #todo: read tourney start time
|
|
||||||
rebuyOrAddon=fpdb_simple.isRebuyOrAddon(hand[0])
|
|
||||||
|
|
||||||
tourneyTypeId=fpdb_simple.recogniseTourneyTypeId(cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
gametypeID = fpdb_simple.recogniseGametypeID(backend, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
||||||
|
if isTourney:
|
||||||
|
if site != "ps":
|
||||||
|
raise fpdb_simple.FpdbError("tourneys are only supported on PS right now")
|
||||||
|
siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0])
|
||||||
|
buyin = fpdb_simple.parseBuyin(hand[0])
|
||||||
|
fee = fpdb_simple.parseFee(hand[0])
|
||||||
|
entries = -1 #todo: parse this
|
||||||
|
prizepool = -1 #todo: parse this
|
||||||
|
knockout = 0
|
||||||
|
tourneyStartTime= handStartTime #todo: read tourney start time
|
||||||
|
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
||||||
|
|
||||||
|
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
||||||
|
|
||||||
fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo)
|
fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo)
|
||||||
|
|
||||||
#part 2: classify lines by type (e.g. cards, action, win, sectionchange) and street
|
#part 2: classify lines by type (e.g. cards, action, win, sectionchange) and street
|
||||||
|
@ -70,85 +69,83 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
||||||
|
|
||||||
#part 3: read basic player info
|
#part 3: read basic player info
|
||||||
#3a read player names, startcashes
|
#3a read player names, startcashes
|
||||||
for i in range (len(hand)): #todo: use maxseats+1 here.
|
for i, line in enumerate(hand):
|
||||||
if (lineTypes[i]=="name"):
|
if lineTypes[i] == "name":
|
||||||
seatLines.append(hand[i])
|
seatLines.append(line)
|
||||||
names=fpdb_simple.parseNames(seatLines)
|
|
||||||
|
names = fpdb_simple.parseNames(seatLines)
|
||||||
playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID)
|
playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID)
|
||||||
tmp=fpdb_simple.parseCashesAndSeatNos(seatLines, site)
|
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines, site)
|
||||||
startCashes=tmp['startCashes']
|
startCashes = tmp['startCashes']
|
||||||
seatNos=tmp['seatNos']
|
seatNos = tmp['seatNos']
|
||||||
|
|
||||||
fpdb_simple.createArrays(category, len(names), cardValues, cardSuits, antes, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo)
|
fpdb_simple.createArrays(category, len(names), cardValues, cardSuits, antes, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo)
|
||||||
|
|
||||||
#3b read positions
|
#3b read positions
|
||||||
if base=="hold":
|
if base == "hold":
|
||||||
positions = fpdb_simple.parsePositions (hand, names)
|
positions = fpdb_simple.parsePositions(hand, names)
|
||||||
|
|
||||||
#part 4: take appropriate action for each line based on linetype
|
#part 4: take appropriate action for each line based on linetype
|
||||||
for i in range(len(hand)):
|
for i, line in enumerate(hand):
|
||||||
if (lineTypes[i]=="cards"):
|
if lineTypes[i] == "cards":
|
||||||
fpdb_simple.parseCardLine (site, category, lineStreets[i], hand[i], names, cardValues, cardSuits, boardValues, boardSuits)
|
fpdb_simple.parseCardLine(site, category, lineStreets[i], line, names, cardValues, cardSuits, boardValues, boardSuits)
|
||||||
#if category=="studhilo":
|
#if category=="studhilo":
|
||||||
# print "hand[i]:", hand[i]
|
# print "hand[i]:", hand[i]
|
||||||
# print "cardValues:", cardValues
|
# print "cardValues:", cardValues
|
||||||
# print "cardSuits:", cardSuits
|
# print "cardSuits:", cardSuits
|
||||||
elif (lineTypes[i]=="action"):
|
elif lineTypes[i] == "action":
|
||||||
fpdb_simple.parseActionLine (site, base, isTourney, hand[i], lineStreets[i], playerIDs, names, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo)
|
fpdb_simple.parseActionLine(site, base, isTourney, line, lineStreets[i], playerIDs, names, actionTypes, allIns, actionAmounts, actionNos, actionTypeByNo)
|
||||||
elif (lineTypes[i]=="win"):
|
elif lineTypes[i] == "win":
|
||||||
fpdb_simple.parseWinLine (hand[i], site, names, winnings, isTourney)
|
fpdb_simple.parseWinLine(line, site, names, winnings, isTourney)
|
||||||
elif (lineTypes[i]=="rake"):
|
elif lineTypes[i] == "rake":
|
||||||
if isTourney:
|
totalRake = 0 if isTourney else fpdb_simple.parseRake(line)
|
||||||
totalRake=0
|
|
||||||
else:
|
|
||||||
totalRake=fpdb_simple.parseRake(hand[i])
|
|
||||||
fpdb_simple.splitRake(winnings, rakes, totalRake)
|
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
|
pass
|
||||||
elif (lineTypes[i]=="ante"):
|
elif lineTypes[i]=="ante":
|
||||||
fpdb_simple.parseAnteLine(hand[i], site, isTourney, names, antes)
|
fpdb_simple.parseAnteLine(line, site, isTourney, names, antes)
|
||||||
elif (lineTypes[i]=="table"):
|
elif lineTypes[i]=="table":
|
||||||
tableResult=fpdb_simple.parseTableLine(site, base, hand[i])
|
tableResult=fpdb_simple.parseTableLine(site, base, line)
|
||||||
else:
|
else:
|
||||||
raise fpdb_simple.FpdbError("unrecognised lineType:"+lineTypes[i])
|
raise fpdb_simple.FpdbError("unrecognised lineType:"+lineTypes[i])
|
||||||
if site=="ftp":
|
|
||||||
tableResult=fpdb_simple.parseTableLine(site, base, hand[0])
|
if site == "ftp":
|
||||||
maxSeats=tableResult['maxSeats']
|
tableResult = fpdb_simple.parseTableLine(site, base, hand[0])
|
||||||
tableName=tableResult['tableName']
|
|
||||||
|
maxSeats = tableResult['maxSeats']
|
||||||
|
tableName = tableResult['tableName']
|
||||||
#print "before part5, antes:", antes
|
#print "before part5, antes:", antes
|
||||||
|
|
||||||
#part 5: final preparations, then call fpdb_save_to_db.* with
|
#part 5: final preparations, then call fpdb_save_to_db.* with
|
||||||
# the arrays as they are - that file will fill them.
|
# the arrays as they are - that file will fill them.
|
||||||
fpdb_simple.convertCardValues(cardValues)
|
fpdb_simple.convertCardValues(cardValues)
|
||||||
if base=="hold":
|
if base == "hold":
|
||||||
fpdb_simple.convertCardValuesBoard(boardValues)
|
fpdb_simple.convertCardValuesBoard(boardValues)
|
||||||
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
||||||
fpdb_simple.checkPositions(positions)
|
fpdb_simple.checkPositions(positions)
|
||||||
|
|
||||||
cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
||||||
limit_type=cursor.fetchone()[0]
|
limit_type = cursor.fetchone()[0]
|
||||||
fpdb_simple.convert3B4B(site, category, limit_type, actionTypes, actionAmounts)
|
fpdb_simple.convert3B4B(site, category, limit_type, actionTypes, actionAmounts)
|
||||||
|
|
||||||
totalWinnings=0
|
totalWinnings = sum(winnings)
|
||||||
for i in range(len(winnings)):
|
|
||||||
totalWinnings+=winnings[i]
|
|
||||||
|
|
||||||
if base=="hold":
|
# if hold'em, use positions and not antes, if stud do not use positions, use antes
|
||||||
hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
|
if base == "hold":
|
||||||
|
hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
|
||||||
, allIns, actionTypeByNo, winnings, totalWinnings, positions
|
, allIns, actionTypeByNo, winnings, totalWinnings, positions
|
||||||
, actionTypes, actionAmounts, None)
|
, actionTypes, actionAmounts, None)
|
||||||
else:
|
else:
|
||||||
hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
|
hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes
|
||||||
, allIns, actionTypeByNo, winnings, totalWinnings, None
|
, allIns, actionTypeByNo, winnings, totalWinnings, None
|
||||||
, actionTypes, actionAmounts, antes)
|
, actionTypes, actionAmounts, antes)
|
||||||
|
|
||||||
if isTourney:
|
if isTourney:
|
||||||
ranks=[]
|
ranks = []
|
||||||
for i in range (len(names)):
|
map(lambda x: 0, names) # create an array of 0's equal to the length of names
|
||||||
ranks.append(0)
|
payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee)
|
||||||
payin_amounts=fpdb_simple.calcPayin(len(names), buyin, fee)
|
|
||||||
|
|
||||||
if base=="hold":
|
if base == "hold":
|
||||||
result = fpdb_save_to_db.tourney_holdem_omaha(
|
result = fpdb_save_to_db.tourney_holdem_omaha(
|
||||||
config, backend, db, cursor, base, category, siteTourneyNo, buyin
|
config, backend, db, cursor, base, category, siteTourneyNo, buyin
|
||||||
, fee, knockout, entries, prizepool, tourneyStartTime
|
, fee, knockout, entries, prizepool, tourneyStartTime
|
||||||
|
@ -157,7 +154,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
||||||
, positions, cardValues, cardSuits, boardValues, boardSuits
|
, positions, cardValues, cardSuits, boardValues, boardSuits
|
||||||
, winnings, rakes, actionTypes, allIns, actionAmounts
|
, winnings, rakes, actionTypes, allIns, actionAmounts
|
||||||
, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
||||||
elif base=="stud":
|
elif base == "stud":
|
||||||
result = fpdb_save_to_db.tourney_stud(
|
result = fpdb_save_to_db.tourney_stud(
|
||||||
config, backend, db, cursor, base, category, siteTourneyNo
|
config, backend, db, cursor, base, category, siteTourneyNo
|
||||||
, buyin, fee, knockout, entries, prizepool, tourneyStartTime
|
, buyin, fee, knockout, entries, prizepool, tourneyStartTime
|
||||||
|
@ -167,9 +164,9 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
||||||
, allIns, actionAmounts, actionNos, hudImportData, maxSeats
|
, allIns, actionAmounts, actionNos, hudImportData, maxSeats
|
||||||
, tableName, seatNos)
|
, tableName, seatNos)
|
||||||
else:
|
else:
|
||||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
raise fpdb_simple.FpdbError("unrecognised category") # it's impossible to get here, but w/e
|
||||||
else:
|
else:
|
||||||
if base=="hold":
|
if base == "hold":
|
||||||
result = fpdb_save_to_db.ring_holdem_omaha(
|
result = fpdb_save_to_db.ring_holdem_omaha(
|
||||||
config, backend, db, cursor, base, category, siteHandNo
|
config, backend, db, cursor, base, category, siteHandNo
|
||||||
, gametypeID, handStartTime, names, playerIDs
|
, gametypeID, handStartTime, names, playerIDs
|
||||||
|
@ -177,7 +174,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
||||||
, boardValues, boardSuits, winnings, rakes
|
, boardValues, boardSuits, winnings, rakes
|
||||||
, actionTypes, allIns, actionAmounts, actionNos
|
, actionTypes, allIns, actionAmounts, actionNos
|
||||||
, hudImportData, maxSeats, tableName, seatNos)
|
, hudImportData, maxSeats, tableName, seatNos)
|
||||||
elif base=="stud":
|
elif base == "stud":
|
||||||
result = fpdb_save_to_db.ring_stud(
|
result = fpdb_save_to_db.ring_stud(
|
||||||
config, backend, db, cursor, base, category, siteHandNo, gametypeID
|
config, backend, db, cursor, base, category, siteHandNo, gametypeID
|
||||||
, handStartTime, names, playerIDs, startCashes, antes
|
, handStartTime, names, playerIDs, startCashes, antes
|
||||||
|
@ -185,7 +182,7 @@ def mainParser(backend, db, cursor, site, category, hand, config):
|
||||||
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
|
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
|
||||||
, seatNos)
|
, seatNos)
|
||||||
else:
|
else:
|
||||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
raise fpdb_simple.FpdbError ("unrecognised category") # also impossible to get here
|
||||||
db.commit()
|
db.commit()
|
||||||
return result
|
return result
|
||||||
#end def mainParser
|
#end def mainParser
|
||||||
|
|
Loading…
Reference in New Issue
Block a user