Tourney import : tRecogniseTourneyType implemented

modified:   Database.py
	* tRecogniseTourneyType : implemented
	modified:   FulltiltToFpdb.py
	* buyin, fee, rebuyAmount, addOnAmount : converted using fpdb_simple.float2int
	modified:   SQL.py
	* Added queries for Database.tRecogniseTourneyType (getTourneyTypeIdByTourneyNo modified to return all data, getTourneyTypeId and insertTourneyTypes added)
This commit is contained in:
PassThePeas 2009-09-01 02:35:52 +02:00
parent 3323d25ce7
commit b00a58249f
3 changed files with 94 additions and 18 deletions

View File

@ -1836,12 +1836,57 @@ class Database:
def tRecogniseTourneyType(self, tourney):
print "Database.tRecogniseTourneyType"
typeId = 1
# Check for an existing TTypeId that matches tourney info (buyin/fee, knockout, rebuy, speed, matrix, shootout)
# if not found create it
# Check if Tourney exists, and if so retrieve TTypeId : in that case, check values of the ttype
cursor = self.get_cursor()
cursor.execute (self.sql.query['getTourneyTypeIdByTourneyNo'].replace('%s', self.sql.query['placeholder']),
(tourney.tourNo, tourney.siteId)
)
result=cursor.fetchone()
expectedValues = { 1 : "buyin", 2 : "fee", 4 : "isKO", 5 : "isRebuy", 6 : "speed",
7 : "isHU", 8 : "isShootout", 9 : "isMatrix" }
typeIdMatch = True
try:
len(result)
typeId = result[0]
print "Tourney found in db with Tourney_Type_ID = %d" % typeId
for ev in expectedValues :
print "ev : %s" % ev
if ( getattr( tourney, expectedValues.get(ev) ) <> result[ev] ):
print "TypeId mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValues.get(ev), getattr( tourney, expectedValues.get(ev)), result[ev] )
typeIdMatch = False
#break
except:
# Tourney not found : a TourneyTypeId has to be found or created for that specific tourney
typeIdMatch = False
if typeIdMatch == False :
# Check for an existing TTypeId that matches tourney info (buyin/fee, knockout, rebuy, speed, matrix, shootout)
# if not found create it
print "Searching for a TourneyTypeId matching TourneyType data"
cursor.execute (self.sql.query['getTourneyTypeId'].replace('%s', self.sql.query['placeholder']),
(tourney.siteId, tourney.buyin, tourney.fee, tourney.isKO,
tourney.isRebuy, tourney.speed, tourney.isHU, tourney.isShootout, tourney.isMatrix)
)
result=cursor.fetchone()
#print "tried SELECTing gametypes.id, result:",result
# Checks for an existing tourney with tourney.siteId and tourney.tourNo (and get the tourneyTypeId)
# if the two TTypeId don't match, update the Tourneys.tourneyTypeId
return typeId
try:
len(result)
typeId = result[0]
print "Existing Tourney Type Id found : %d" % typeId
except TypeError: #this means we need to create a new entry
print "Tourney Type Id not found : create one"
cursor.execute (self.sql.query['insertTourneyTypes'].replace('%s', self.sql.query['placeholder']),
(tourney.siteId, tourney.buyin, tourney.fee, tourney.isKO, tourney.isRebuy,
tourney.speed, tourney.isHU, tourney.isShootout, tourney.isMatrix)
)
typeId = self.get_last_insert_id(cursor)
return typeId
#end def tRecogniseTourneyType
def tRecognizeTourney(self, tourney, dbTourneyTypeId):
print "Database.tRecognizeTourney"
@ -1849,7 +1894,7 @@ class Database:
# Check if tourney exists in db (based on tourney.siteId and tourney.tourNo)
# If not => create it with the tourneyTypeId given as input
# if found => retrieve data (in the first query) and check if an update is needed, if so do it
# rem : Tourney Specific data = entries, prizepool, buyinchips, rebuychips, addonchips, totalrebuys, totaladdons, kobounty
# rem : Tourney Specific data = tourneyTypeId, entries, prizepool, buyinchips, rebuychips, addonchips, totalrebuys, totaladdons, kobounty
return tourneyID
def tStoreTourneyPlayers(self, tourney, dbTourneyId):

View File

@ -20,6 +20,7 @@
import sys
import logging
import fpdb_simple
from HandHistoryConverter import *
# Fulltilt HH Format converter
@ -475,10 +476,10 @@ class Fulltilt(HandHistoryConverter):
# Additional info can be stored in the tourney object
if mg['BUYIN'] is not None:
tourney.buyin = mg['BUYIN']
tourney.buyin = fpdb_simple.float2int(mg['BUYIN'])
tourney.fee = 0
if mg['FEE'] is not None:
tourney.fee = mg['FEE']
tourney.fee = fpdb_simple.float2int(mg['FEE'])
if mg['TOURNAMENT_NAME'] is not None:
# Tournament Name can have a trailing space at the end (depending on the tournament description)
tourney.tourneyName = mg['TOURNAMENT_NAME'].rstrip()
@ -523,24 +524,24 @@ class Fulltilt(HandHistoryConverter):
mg = m.groupdict()
if tourney.isMatrix :
if mg['BUYIN'] is not None:
tourney.subTourneyBuyin = mg['BUYIN']
tourney.subTourneyBuyin = fpdb_simple.float2int(mg['BUYIN'])
tourney.subTourneyFee = 0
if mg['FEE'] is not None:
tourney.subTourneyFee = mg['FEE']
tourney.subTourneyFee = fpdb_simple.float2int(mg['FEE'])
else :
if mg['BUYIN'] is not None:
if tourney.buyin is None:
tourney.buyin = mg['BUYIN']
tourney.buyin = fpdb_simple.float2int(mg['BUYIN'])
else :
if mg['BUYIN'] != tourney.buyin:
log.error( "Conflict between buyins read in topline (%s) and in BuyIn field (%s)" % (touney.buyin, mg['BUYIN']) )
tourney.subTourneyBuyin = mg['BUYIN']
if fpdb_simple.float2int(mg['BUYIN']) != tourney.buyin:
log.error( "Conflict between buyins read in topline (%s) and in BuyIn field (%s)" % (touney.buyin, fpdb_simple.float2int(mg['BUYIN'])) )
tourney.subTourneyBuyin = fpdb_simple.float2int(mg['BUYIN'])
if mg['FEE'] is not None:
if tourney.fee is None:
tourney.fee = mg['FEE']
tourney.fee = fpdb_simple.float2int(mg['FEE'])
else :
if mg['FEE'] != tourney.fee:
log.error( "Conflict between fees read in topline (%s) and in BuyIn field (%s)" % (touney.fee, mg['FEE']) )
if fpdb_simple.float2int(mg['FEE']) != tourney.fee:
log.error( "Conflict between fees read in topline (%s) and in BuyIn field (%s)" % (touney.fee, fpdb_simple.float2int(mg['FEE'])) )
tourney.subTourneyFee = mg['FEE']
if tourney.buyin is None:
@ -596,6 +597,9 @@ class Fulltilt(HandHistoryConverter):
if mg['IN_PROGRESS'] is not None or mg['ENDTIME'] is not None:
# Assign endtime to tourney (if None, that's ok, it's because the tourney wans't over over when the summary file was produced)
tourney.endtime = mg['ENDTIME']
tourney.rebuyAmount = fpdb_simple.float2int("%s" % tourney.rebuyAmount)
tourney.addOnAmount = fpdb_simple.float2int("%s" % tourney.addOnAmount)
#print mg
return True

View File

@ -2816,11 +2816,38 @@ class Sql:
WHERE gametypeId=%s AND siteHandNo=%s
"""
self.query['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id
self.query['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id,
tt.buyin,
tt.fee,
tt.maxSeats,
tt.knockout,
tt.rebuyOrAddon,
tt.speed,
tt.headsUp,
tt.shootout,
tt.matrix
FROM TourneyTypes tt
INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id)
WHERE t.siteTourneyNo=%s AND tt.siteId=%s
"""
self.query['getTourneyTypeId'] = """SELECT id
FROM TourneyTypes
WHERE siteId=%s
AND buyin=%s
AND fee=%s
AND knockout=%s
AND rebuyOrAddon=%s
AND speed=%s
AND headsUp=%s
AND shootout=%s
AND matrix=%s
"""
self.query['insertTourneyTypes'] = """INSERT INTO TourneyTypes
(siteId, buyin, fee, knockout, rebuyOrAddon
,speed, headsUp, shootout, matrix)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
if db_server == 'mysql':
self.query['placeholder'] = u'%s'