2008-08-04 05:44:28 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
#Copyright 2008 Steffen Jobbagy-Felso
|
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
#GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
#You should have received a copy of the GNU Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#In the "official" distribution you can find the license in
|
|
|
|
#agpl-3.0.txt in the docs folder of the package.
|
|
|
|
|
|
|
|
#methods that are specific to holdem but not trivial
|
|
|
|
|
|
|
|
import fpdb_simple
|
|
|
|
import fpdb_save_to_db
|
|
|
|
|
|
|
|
#parses a holdem hand
|
|
|
|
def mainParser(db, cursor, site, category, hand):
|
2008-09-01 06:41:58 +02:00
|
|
|
if (category=="holdem" or category=="omahahi" or category=="omahahilo"):
|
|
|
|
base="hold"
|
|
|
|
else:
|
|
|
|
base="stud"
|
2008-08-04 05:44:28 +02:00
|
|
|
#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)
|
|
|
|
|
2008-08-09 19:53:07 +02:00
|
|
|
cardValues, cardSuits, boardValues, boardSuits, antes, actionTypes, actionAmounts, actionNos, actionTypeByNo, seatLines, winnings, rakes=[], [],[],[],[],[],[],[],[],[],[],[]
|
2008-08-04 05:44:28 +02:00
|
|
|
|
|
|
|
#part 1: read hand no and check for duplicate
|
|
|
|
siteHandNo=fpdb_simple.parseSiteHandNo(hand[0])
|
|
|
|
handStartTime=fpdb_simple.parseHandStartTime(hand[0], site)
|
|
|
|
siteID=fpdb_simple.recogniseSiteID(cursor, site)
|
2008-09-22 00:38:22 +02:00
|
|
|
#print "parse logic, siteID:",siteID,"site:",site
|
2008-08-04 05:44:28 +02:00
|
|
|
|
|
|
|
isTourney=fpdb_simple.isTourney(hand[0])
|
2008-09-24 06:47:17 +02:00
|
|
|
smallBlindLine=0
|
|
|
|
for i in range(len(hand)):
|
|
|
|
if hand[i].find("posts small blind")!=-1 or hand[i].find("posts the small blind")!=-1:
|
|
|
|
smallBlindLine=i
|
|
|
|
#print "found small blind line:",smallBlindLine
|
|
|
|
break
|
|
|
|
#print "small blind line:",smallBlindLine
|
|
|
|
gametypeID=fpdb_simple.recogniseGametypeID(cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
2008-08-04 05:44:28 +02:00
|
|
|
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
|
2008-08-18 06:58:41 +02:00
|
|
|
knockout=0
|
2008-08-04 05:44:28 +02:00
|
|
|
tourneyStartTime=handStartTime #todo: read tourney start time
|
2008-08-18 06:58:41 +02:00
|
|
|
rebuyOrAddon=fpdb_simple.isRebuyOrAddon(hand[0])
|
|
|
|
|
|
|
|
tourneyTypeId=fpdb_simple.recogniseTourneyTypeId(cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
2008-08-04 05:44:28 +02:00
|
|
|
fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo)
|
|
|
|
|
|
|
|
#part 2: classify lines by type (e.g. cards, action, win, sectionchange) and street
|
|
|
|
fpdb_simple.classifyLines(hand, category, lineTypes, lineStreets)
|
2008-09-01 06:41:58 +02:00
|
|
|
|
2008-08-04 05:44:28 +02:00
|
|
|
#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])
|
|
|
|
names=fpdb_simple.parseNames(seatLines)
|
|
|
|
playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID)
|
2008-08-17 05:44:53 +02:00
|
|
|
tmp=fpdb_simple.parseCashesAndSeatNos(seatLines, site)
|
|
|
|
startCashes=tmp['startCashes']
|
|
|
|
seatNos=tmp['seatNos']
|
2008-08-04 05:44:28 +02:00
|
|
|
|
2008-08-09 19:53:07 +02:00
|
|
|
fpdb_simple.createArrays(category, len(names), cardValues, cardSuits, antes, winnings, rakes, actionTypes, actionAmounts, actionNos, actionTypeByNo)
|
|
|
|
|
2008-08-08 23:03:43 +02:00
|
|
|
#3b read positions
|
2008-09-01 06:41:58 +02:00
|
|
|
if base=="hold":
|
2008-08-04 05:44:28 +02:00
|
|
|
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)
|
|
|
|
elif (lineTypes[i]=="action"):
|
2008-10-05 06:04:42 +02:00
|
|
|
fpdb_simple.parseActionLine (site, base, isTourney, hand[i], lineStreets[i], playerIDs, names, actionTypes, actionAmounts, actionNos, actionTypeByNo)
|
2008-08-04 05:44:28 +02:00
|
|
|
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])
|
|
|
|
fpdb_simple.splitRake(winnings, rakes, totalRake)
|
|
|
|
elif (lineTypes[i]=="header" or lineTypes[i]=="rake" or lineTypes[i]=="name" or lineTypes[i]=="ignore"):
|
|
|
|
pass
|
|
|
|
elif (lineTypes[i]=="ante"):
|
2008-10-05 06:04:42 +02:00
|
|
|
fpdb_simple.parseAnteLine(hand[i], site, isTourney, names, antes)
|
2008-08-17 04:18:42 +02:00
|
|
|
elif (lineTypes[i]=="table"):
|
2008-09-18 02:23:38 +02:00
|
|
|
tableResult=fpdb_simple.parseTableLine(site, base, hand[i])
|
2008-08-04 05:44:28 +02:00
|
|
|
else:
|
|
|
|
raise fpdb_simple.FpdbError("unrecognised lineType:"+lineTypes[i])
|
2008-08-18 10:05:22 +02:00
|
|
|
if site=="ftp":
|
2008-09-18 02:23:38 +02:00
|
|
|
tableResult=fpdb_simple.parseTableLine(site, base, hand[0])
|
2008-08-18 10:05:22 +02:00
|
|
|
maxSeats=tableResult['maxSeats']
|
|
|
|
tableName=tableResult['tableName']
|
2008-08-04 05:44:28 +02:00
|
|
|
|
|
|
|
#part 5: final preparations, then call fpdb_save_to_db.saveHoldem with
|
|
|
|
# the arrays as they are - that file will fill them.
|
|
|
|
fpdb_simple.convertCardValues(cardValues)
|
2008-09-01 06:41:58 +02:00
|
|
|
if base=="hold":
|
2008-08-04 05:44:28 +02:00
|
|
|
fpdb_simple.convertCardValuesBoard(boardValues)
|
|
|
|
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
|
|
|
fpdb_simple.checkPositions(positions)
|
|
|
|
|
2008-08-15 02:45:40 +02:00
|
|
|
cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
2008-08-08 23:03:43 +02:00
|
|
|
limit_type=cursor.fetchone()[0]
|
2008-08-04 05:44:28 +02:00
|
|
|
fpdb_simple.convert3B4B(site, category, limit_type, actionTypes, actionAmounts)
|
|
|
|
|
2008-08-07 17:08:23 +02:00
|
|
|
totalWinnings=0
|
|
|
|
for i in range(len(winnings)):
|
|
|
|
totalWinnings+=winnings[i]
|
2008-09-01 06:41:58 +02:00
|
|
|
|
|
|
|
if base=="hold":
|
2008-09-02 02:00:43 +02:00
|
|
|
hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes, actionTypeByNo, winnings, totalWinnings, positions)
|
2008-09-01 06:41:58 +02:00
|
|
|
else:
|
2008-09-02 02:00:43 +02:00
|
|
|
hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes, actionTypeByNo, winnings, totalWinnings, None)
|
2008-08-04 05:44:28 +02:00
|
|
|
|
|
|
|
if isTourney:
|
|
|
|
ranks=[]
|
|
|
|
for i in range (len(names)):
|
|
|
|
ranks.append(0)
|
2008-08-18 06:58:41 +02:00
|
|
|
payin_amounts=fpdb_simple.calcPayin(len(names), buyin, fee)
|
|
|
|
|
2008-09-01 06:41:58 +02:00
|
|
|
if base=="hold":
|
|
|
|
result = fpdb_save_to_db.tourney_holdem_omaha(cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries, prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteID,
|
2008-08-17 05:44:53 +02:00
|
|
|
siteHandNo, gametypeID, handStartTime, names, playerIDs, startCashes, positions, cardValues, cardSuits, boardValues, boardSuits, winnings, rakes, actionTypes, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
2008-09-01 06:41:58 +02:00
|
|
|
elif base=="stud":
|
|
|
|
result = fpdb_save_to_db.tourney_stud(cursor, base, category, siteTourneyNo, buyin, fee,
|
2008-08-04 05:44:28 +02:00
|
|
|
knockout, entries, prizepool, tourneyStartTime, payin_amounts, ranks,
|
|
|
|
siteHandNo, siteID, gametypeID, handStartTime, names, playerIDs,
|
|
|
|
startCashes, antes, cardValues, cardSuits, winnings, rakes,
|
2008-09-01 06:41:58 +02:00
|
|
|
actionTypes, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
|
|
|
else:
|
|
|
|
raise fpdb_simple.FpdbError ("unrecognised category")
|
2008-08-04 05:44:28 +02:00
|
|
|
else:
|
2008-09-01 06:41:58 +02:00
|
|
|
if base=="hold":
|
|
|
|
result = fpdb_save_to_db.ring_holdem_omaha(cursor, base, category, siteHandNo, gametypeID, handStartTime, names, playerIDs, startCashes, positions, cardValues, cardSuits, boardValues, boardSuits, winnings, rakes, actionTypes, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
|
|
|
elif base=="stud":
|
|
|
|
result = fpdb_save_to_db.ring_stud(cursor, base, category, siteHandNo, gametypeID,
|
2008-08-04 05:44:28 +02:00
|
|
|
handStartTime, names, playerIDs, startCashes, antes, cardValues,
|
2008-09-01 06:41:58 +02:00
|
|
|
cardSuits, winnings, rakes, actionTypes, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
2008-08-04 05:44:28 +02:00
|
|
|
else:
|
|
|
|
raise fpdb_simple.FpdbError ("unrecognised category")
|
|
|
|
db.commit()
|
|
|
|
return result
|
|
|
|
#end def mainParser
|
|
|
|
|