Last part of core tourney import
Database.py : tStoreTourneyPlayers and tUpdateTourneysHandsPlayers implemented HandHistoryConverter.py : fix for 0-byte summary files SQL.py : new queries Tourney.py : cleanup stdout
This commit is contained in:
parent
4853b888a6
commit
91ebbe79e1
|
@ -1968,21 +1968,101 @@ class Database:
|
|||
endtime, tourney.buyInChips, tourney.tourneyName, 0, tourney.rebuyChips, tourney.addOnChips,
|
||||
tourney.rebuyAmount, tourney.addOnAmount, tourney.totalRebuys, tourney.totalAddOns, tourney.koBounty,
|
||||
tourney.tourneyComment, tCommentTs, tourneyID)
|
||||
)
|
||||
)
|
||||
|
||||
return tourneyID
|
||||
#end def tRecognizeTourney
|
||||
|
||||
def tStoreTourneyPlayers(self, tourney, dbTourneyId):
|
||||
print "Database.tStoreTourneyPlayers"
|
||||
tourneyPlayersIds=[]
|
||||
# Look for existing players in TourneysPlayers
|
||||
# For the ones not in db insert with all data (nbrebuys, nbaddons, nbKO, payinAmount, rank, winnings)
|
||||
# For the others, get data and check if an update is needed, if so, do it
|
||||
return tourneyPlayersIds
|
||||
logging.debug("Database.tStoreTourneyPlayers")
|
||||
# First, get playerids for the players and specifically the one for hero :
|
||||
playersIds = fpdb_simple.recognisePlayerIDs(self, tourney.players, tourney.siteId)
|
||||
# hero may be None for matrix tourneys summaries
|
||||
# hero = [ tourney.hero ]
|
||||
# heroId = fpdb_simple.recognisePlayerIDs(self, hero , tourney.siteId)
|
||||
# logging.debug("hero Id = %s - playersId = %s" % (heroId , playersIds))
|
||||
|
||||
tourneyPlayersIds=[]
|
||||
try:
|
||||
cursor = self.get_cursor()
|
||||
|
||||
for i in xrange(len(playersIds)):
|
||||
cursor.execute(self.sql.query['getTourneysPlayers'].replace('%s', self.sql.query['placeholder'])
|
||||
,(dbTourneyId, playersIds[i]))
|
||||
result=cursor.fetchone()
|
||||
#print "tried SELECTing tourneys_players.id:",tmp
|
||||
|
||||
try:
|
||||
len(result)
|
||||
# checking data
|
||||
logging.debug("TourneysPlayers found : checking data")
|
||||
expectedValuesDecimal = { 1 : "payinAmounts", 2 : "finishPositions", 3 : "winnings", 4 : "countRebuys",
|
||||
5 : "countAddOns", 6 : "countKO" }
|
||||
|
||||
tourneyPlayersIds.append(result[0]);
|
||||
|
||||
tourneysPlayersDataMatch = True
|
||||
for evD in expectedValuesDecimal :
|
||||
if ( Decimal(getattr( tourney, expectedValuesDecimal.get(evD))[tourney.players[i]] ) <> result[evD] ):
|
||||
logging.debug("TourneysPlayers data mismatch for TourneysPlayer id=%d, name=%s : wrong %s : Tourney=%s / db=%s" % (result[0], tourney.players[i], expectedValuesDecimal.get(evD), getattr( tourney, expectedValuesDecimal.get(evD))[tourney.players[i]], result[evD]) )
|
||||
tourneysPlayersDataMatch = False
|
||||
#break
|
||||
|
||||
if tourneysPlayersDataMatch == False:
|
||||
logging.debug("TourneysPlayers data update needed")
|
||||
cursor.execute (self.sql.query['updateTourneysPlayers'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.payinAmounts[tourney.players[i]], tourney.finishPositions[tourney.players[i]],
|
||||
tourney.winnings[tourney.players[i]] , tourney.countRebuys[tourney.players[i]],
|
||||
tourney.countAddOns[tourney.players[i]] , tourney.countKO[tourney.players[i]],
|
||||
result[7], result[8], result[0])
|
||||
)
|
||||
|
||||
except TypeError:
|
||||
logging.debug("TourneysPlayers not found : need insert")
|
||||
cursor.execute (self.sql.query['insertTourneysPlayers'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyId, playersIds[i],
|
||||
tourney.payinAmounts[tourney.players[i]], tourney.finishPositions[tourney.players[i]],
|
||||
tourney.winnings[tourney.players[i]] , tourney.countRebuys[tourney.players[i]],
|
||||
tourney.countAddOns[tourney.players[i]] , tourney.countKO[tourney.players[i]],
|
||||
None, None)
|
||||
)
|
||||
tourneyPlayersIds.append(self.get_last_insert_id(cursor))
|
||||
|
||||
except:
|
||||
raise fpdb_simple.FpdbError( "tStoreTourneyPlayers error: " + str(sys.exc_value) )
|
||||
|
||||
return tourneyPlayersIds
|
||||
#end def tStoreTourneyPlayers
|
||||
|
||||
def tUpdateTourneysHandsPlayers(self, tourney, dbTourneysPlayersIds, dbTourneyTypeId):
|
||||
logging.debug("Database.tCheckTourneysHandsPlayers")
|
||||
try:
|
||||
# Massive update seems to take quite some time ...
|
||||
# query = self.sql.query['updateHandsPlayersForTTypeId2'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner'].join([self.sql.query['placeholder'] for id in dbTourneysPlayersIds]) )
|
||||
# cursor = self.get_cursor()
|
||||
# cursor.execute (query, dbTourneysPlayersIds)
|
||||
|
||||
query = self.sql.query['selectHandsPlayersWithWrongTTypeId'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner'].join([self.sql.query['placeholder'] for id in dbTourneysPlayersIds]) )
|
||||
#print "query : %s" % query
|
||||
cursor = self.get_cursor()
|
||||
cursor.execute (query, dbTourneysPlayersIds)
|
||||
result=cursor.fetchall()
|
||||
|
||||
if (len(result) > 0):
|
||||
logging.debug("%d lines need update : %s" % (len(result), result) )
|
||||
listIds = []
|
||||
for i in result:
|
||||
listIds.append(i[0])
|
||||
|
||||
query2 = self.sql.query['updateHandsPlayersForTTypeId'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner_id'].join([self.sql.query['placeholder'] for id in listIds]) )
|
||||
cursor.execute (query2, listIds)
|
||||
else:
|
||||
logging.debug("No need to update, HandsPlayers are correct")
|
||||
|
||||
except:
|
||||
raise fpdb_simple.FpdbError( "tStoreTourneyPlayers error: " + str(sys.exc_value) )
|
||||
#end def tUpdateTourneysHandsPlayers
|
||||
|
||||
def tCheckTourneysHandsPlayers(self, tourney, dbTourneysPlayersIds, dbTourneyTypeId):
|
||||
print "Database.tCheckTourneysHandsPlayers"
|
||||
# Make a direct update of lines from HandsPlayers where touneyplayersid=<input> and tourneyTypeId <> dbTourneyTypeId, set tourneyTypeId=dbTourneyTypeId
|
||||
|
||||
# Class used to hold all the data needed to write a hand to the db
|
||||
# mainParser() in fpdb_parse_logic.py creates one of these and then passes it to
|
||||
|
|
|
@ -139,7 +139,8 @@ Otherwise, finish at EOF.
|
|||
handsList = self.allHandsAsList()
|
||||
log.info("Parsing %d hands" % len(handsList))
|
||||
# Determine if we're dealing with a HH file or a Summary file
|
||||
if self.isSummary(handsList[0]) == False:
|
||||
# quick fix : empty files make the handsList[0] fail ==> If empty file, go on with HH parsing
|
||||
if len(handsList) == 0 or self.isSummary(handsList[0]) == False:
|
||||
self.parsedObjectType = "HH"
|
||||
for handText in handsList:
|
||||
try:
|
||||
|
|
|
@ -2902,6 +2902,55 @@ class Sql:
|
|||
WHERE id=%s
|
||||
"""
|
||||
|
||||
self.query['getTourneysPlayers'] = """SELECT id,
|
||||
payinAmount,
|
||||
rank,
|
||||
winnings,
|
||||
nbRebuys,
|
||||
nbAddons,
|
||||
nbKO,
|
||||
comment,
|
||||
commentTs
|
||||
FROM TourneysPlayers
|
||||
WHERE tourneyId=%s AND playerId+0=%s
|
||||
"""
|
||||
|
||||
self.query['updateTourneysPlayers'] = """UPDATE TourneysPlayers
|
||||
SET payinAmount = %s,
|
||||
rank = %s,
|
||||
winnings = %s,
|
||||
nbRebuys = %s,
|
||||
nbAddons = %s,
|
||||
nbKO = %s,
|
||||
comment = %s,
|
||||
commentTs = %s
|
||||
WHERE id=%s
|
||||
"""
|
||||
|
||||
self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers
|
||||
(tourneyId, playerId, payinAmount, rank, winnings, nbRebuys, nbAddons, nbKO, comment, commentTs)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
self.query['selectHandsPlayersWithWrongTTypeId'] = """SELECT id
|
||||
FROM HandsPlayers
|
||||
WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s)
|
||||
"""
|
||||
|
||||
# self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers
|
||||
# SET tourneyTypeId= %s
|
||||
# WHERE (TourneysPlayersId+0=%s)
|
||||
# """
|
||||
|
||||
self.query['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers
|
||||
SET tourneyTypeId= %s
|
||||
WHERE (id=%s)
|
||||
"""
|
||||
|
||||
|
||||
self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
|
||||
self.query['handsPlayersTTypeId_joiner_id'] = " OR id="
|
||||
|
||||
|
||||
|
||||
if db_server == 'mysql':
|
||||
|
|
|
@ -151,7 +151,6 @@ class Tourney(object):
|
|||
pass
|
||||
|
||||
def insert(self, db):
|
||||
print "TODO: Insert Tourney in DB"
|
||||
# First : check all needed info is filled in the object, especially for the initial select
|
||||
|
||||
# Notes on DB Insert
|
||||
|
@ -163,15 +162,18 @@ class Tourney(object):
|
|||
# Note: If the TourneyNo could be a unique id .... this would really be a relief to deal with matrix matches ==> Ask on the IRC / Ask Fulltilt ??
|
||||
|
||||
dbTourneyTypeId = db.tRecogniseTourneyType(self)
|
||||
print "Tourney Type ID = %d" % dbTourneyTypeId
|
||||
logging.debug("Tourney Type ID = %d" % dbTourneyTypeId)
|
||||
dbTourneyId = db.tRecognizeTourney(self, dbTourneyTypeId)
|
||||
print "Tourney ID = %d" % dbTourneyId
|
||||
logging.debug("Tourney ID = %d" % dbTourneyId)
|
||||
dbTourneysPlayersIds = db.tStoreTourneyPlayers(self, dbTourneyId)
|
||||
db.tCheckTourneysHandsPlayers(self, dbTourneysPlayersIds, dbTourneyTypeId)
|
||||
logging.debug("TourneysPlayersId = %s" % dbTourneysPlayersIds)
|
||||
db.tUpdateTourneysHandsPlayers(self, dbTourneysPlayersIds, dbTourneyTypeId)
|
||||
logging.debug("tUpdateTourneysHandsPlayers done")
|
||||
logging.debug("Tourney Insert done")
|
||||
|
||||
# TO DO : Return what has been done (tourney created, updated, nothing)
|
||||
# ?? stored = 1 if tourney is fully created / duplicates = 1, if everything was already here and correct / partial=1 if some things were already here (between tourney, tourneyPlayers and handsplayers)
|
||||
# if so, prototypes may need changes to know what has been done
|
||||
# if so, prototypes may need changes to know what has been done or make some kind of dict in Tourney object that could be updated during the insert process to store that information
|
||||
stored = 0
|
||||
duplicates = 0
|
||||
partial = 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user