removed 2 ancient unusued methods and updated TourneysPlayers

tested bulk import for PS and FTP, player stats and positional stats
also fixed a little bug that sqlite created HandsPlayers.actionString
	with type REAL instead of VARCHAR
This commit is contained in:
steffen123 2010-06-22 21:05:33 +02:00
parent e46b0b7a0f
commit 58da99c86c
4 changed files with 33 additions and 142 deletions

View File

@ -397,9 +397,10 @@ tourneys_players_table = Table('TourneysPlayers', metadata,
Column('payinAmount', Integer), # INT NOT NULL Column('payinAmount', Integer), # INT NOT NULL
Column('rank', Integer), # INT NOT NULL Column('rank', Integer), # INT NOT NULL
Column('winnings', Integer), # INT NOT NULL Column('winnings', Integer), # INT NOT NULL
Column('nbRebuys', Integer, default=0), # INT DEFAULT 0 Column('winningsCurrency', Text), # TEXT
Column('nbAddons', Integer, default=0), # INT DEFAULT 0 Column('rebuyCount', Integer, default=0), # INT DEFAULT 0
Column('nbKO', Integer, default=0), # INT DEFAULT 0 Column('addOnCount', Integer, default=0), # INT DEFAULT 0
Column('koCount', Integer, default=0), # INT DEFAULT 0
Column('comment', Text), # TEXT Column('comment', Text), # TEXT
Column('commentTs', DateTime), # DATETIME Column('commentTs', DateTime), # DATETIME
mysql_charset='utf8', mysql_charset='utf8',

View File

@ -1854,48 +1854,6 @@ class Database:
# Finish of NEWIMPORT CODE # Finish of NEWIMPORT CODE
################################# #################################
def store_tourneys_players(self, tourney_id, player_ids, payin_amounts, ranks, winnings):
try:
result=[]
cursor = self.get_cursor()
#print "in store_tourneys_players. tourney_id:",tourney_id
#print "player_ids:",player_ids
#print "payin_amounts:",payin_amounts
#print "ranks:",ranks
#print "winnings:",winnings
for i in xrange(len(player_ids)):
try:
cursor.execute("savepoint ins_tplayer")
cursor.execute("""INSERT INTO TourneysPlayers
(tourneyId, playerId, payinAmount, rank, winnings) VALUES (%s, %s, %s, %s, %s)""".replace('%s', self.sql.query['placeholder']),
(tourney_id, player_ids[i], payin_amounts[i], ranks[i], winnings[i]))
tmp = self.get_last_insert_id(cursor)
result.append(tmp)
#print "created new tourneys_players.id:", tmp
except:
cursor.execute("rollback to savepoint ins_tplayer")
cursor.execute("SELECT id FROM TourneysPlayers WHERE tourneyId=%s AND playerId+0=%s".replace('%s', self.sql.query['placeholder'])
,(tourney_id, player_ids[i]))
tmp = cursor.fetchone()
#print "tried SELECTing tourneys_players.id:", tmp
try:
len(tmp)
result.append(tmp[0])
except:
print "tplayer id not found for tourney,player %s,%s" % (tourney_id, player_ids[i])
pass
except:
raise FpdbError( "store_tourneys_players error: " + str(sys.exc_value) )
cursor.execute("release savepoint ins_tplayer")
#print "store_tourneys_players returning", result
return result
#end def store_tourneys_players
# read HandToWrite objects from q and insert into database # read HandToWrite objects from q and insert into database
def insert_queue_hands(self, q, maxwait=10, commitEachHand=True): def insert_queue_hands(self, q, maxwait=10, commitEachHand=True):
n,fails,maxTries,firstWait = 0,0,4,0.1 n,fails,maxTries,firstWait = 0,0,4,0.1
@ -1971,8 +1929,8 @@ class Database:
print "***Error sending finish: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) print "***Error sending finish: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
# end def send_finish_msg(): # end def send_finish_msg():
def tRecogniseTourneyType(self, tourney): def recogniseTourneyType(self, tourney):
log.debug("Database.tRecogniseTourneyType") log.debug("Database.recogniseTourneyType")
typeId = 1 typeId = 1
# Check if Tourney exists, and if so retrieve TTypeId : in that case, check values of the ttype # Check if Tourney exists, and if so retrieve TTypeId : in that case, check values of the ttype
cursor = self.get_cursor() cursor = self.get_cursor()
@ -2021,7 +1979,7 @@ class Database:
typeId = self.get_last_insert_id(cursor) typeId = self.get_last_insert_id(cursor)
return typeId return typeId
#end def tRecogniseTourneyType #end def recogniseTourneyType

View File

@ -602,7 +602,7 @@ class Sql:
totalProfit INT, totalProfit INT,
comment text, comment text,
commentTs timestamp without time zone, commentTs timestamp without time zone,
tourneysPlayersId BIGINT, tourneysPlayersId BIGINT, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
tourneyTypeId INT NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), tourneyTypeId INT NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
wonWhenSeenStreet1 FLOAT, wonWhenSeenStreet1 FLOAT,
@ -692,9 +692,7 @@ class Sql:
street3Raises SMALLINT, street3Raises SMALLINT,
street4Raises SMALLINT, street4Raises SMALLINT,
actionString VARCHAR(15), actionString VARCHAR(15))"""
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))"""
elif db_server == 'sqlite': elif db_server == 'sqlite':
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -808,7 +806,7 @@ class Sql:
street2Raises INT, street2Raises INT,
street3Raises INT, street3Raises INT,
street4Raises INT, street4Raises INT,
actionString REAL) actionString VARCHAR(15))
""" """
@ -824,9 +822,10 @@ class Sql:
payinAmount INT NOT NULL, payinAmount INT NOT NULL,
rank INT NOT NULL, rank INT NOT NULL,
winnings INT NOT NULL, winnings INT NOT NULL,
nbRebuys INT DEFAULT 0, winningsCurrency VARCHAR(4) NOT NULL,
nbAddons INT DEFAULT 0, rebuyCount INT DEFAULT 0,
nbKO INT DEFAULT 0, addOnCount INT DEFAULT 0,
koCount INT DEFAULT 0,
comment TEXT, comment TEXT,
commentTs DATETIME) commentTs DATETIME)
ENGINE=INNODB""" ENGINE=INNODB"""
@ -838,9 +837,10 @@ class Sql:
payinAmount INT, payinAmount INT,
rank INT, rank INT,
winnings INT, winnings INT,
nbRebuys INT DEFAULT 0, winningsCurrency VARCHAR(4),
nbAddons INT DEFAULT 0, rebuyCount INT DEFAULT 0,
nbKO INT DEFAULT 0, addOnCount INT DEFAULT 0,
koCount INT DEFAULT 0,
comment TEXT, comment TEXT,
commentTs timestamp without time zone)""" commentTs timestamp without time zone)"""
elif db_server == 'sqlite': elif db_server == 'sqlite':
@ -851,9 +851,10 @@ class Sql:
payinAmount INT, payinAmount INT,
rank INT, rank INT,
winnings INT, winnings INT,
nbRebuys INT DEFAULT 0, winningsCurrency VARCHAR(4),
nbAddons INT DEFAULT 0, rebuyCount INT DEFAULT 0,
nbKO INT DEFAULT 0, addOnCount INT DEFAULT 0,
koCount INT DEFAULT 0,
comment TEXT, comment TEXT,
commentTs timestamp without time zone, commentTs timestamp without time zone,
FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
@ -3633,9 +3634,10 @@ class Sql:
payinAmount, payinAmount,
rank, rank,
winnings, winnings,
nbRebuys, winningsCurrency,
nbAddons, rebuyCount,
nbKO, addOnCount,
koCount,
comment, comment,
commentTs commentTs
FROM TourneysPlayers FROM TourneysPlayers
@ -3646,17 +3648,18 @@ class Sql:
SET payinAmount = %s, SET payinAmount = %s,
rank = %s, rank = %s,
winnings = %s, winnings = %s,
nbRebuys = %s, winningsCurrency = %s,
nbAddons = %s, rebuyCount = %s,
nbKO = %s, addOnCount = %s,
koCount = %s,
comment = %s, comment = %s,
commentTs = %s commentTs = %s
WHERE id=%s WHERE id=%s
""" """
self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers
(tourneyId, playerId, payinAmount, rank, winnings, nbRebuys, nbAddons, nbKO, comment, commentTs) (tourneyId, playerId, payinAmount, rank, winnings, winningsCurrency, rebuyCount, addOnCount, koCount, comment, commentTs)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""" """
self.query['selectHandsPlayersWithWrongTTypeId'] = """SELECT id self.query['selectHandsPlayersWithWrongTTypeId'] = """SELECT id

View File

@ -162,7 +162,7 @@ class Tourney(object):
# Starttime may not match the one in the Summary file : HH = time of the first Hand / could be slighltly different from the one in the summary file # Starttime may not match the one in the Summary file : HH = time of the first Hand / could be slighltly different from the one in the summary file
# 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 ?? # 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) dbTourneyTypeId = db.recogniseTourneyType(self)
logging.debug("Tourney Type ID = %d" % dbTourneyTypeId) logging.debug("Tourney Type ID = %d" % dbTourneyTypeId)
dbTourneyId = db.tRecognizeTourney(self, dbTourneyTypeId) dbTourneyId = db.tRecognizeTourney(self, dbTourneyTypeId)
logging.debug("Tourney ID = %d" % dbTourneyId) logging.debug("Tourney ID = %d" % dbTourneyId)
@ -183,81 +183,10 @@ class Tourney(object):
return (stored, duplicates, partial, errors, ttime) return (stored, duplicates, partial, errors, ttime)
def old_insert_from_Hand(self, db):
""" Function to insert Hand into database
Should not commit, and do minimal selects. Callers may want to cache commits
db: a connected Database object"""
# TODO:
# Players - base playerid and siteid tuple
sqlids = db.getSqlPlayerIDs([p[1] for p in self.players], self.siteId)
#Gametypes
gtid = db.getGameTypeId(self.siteId, self.gametype)
# HudCache data to come from DerivedStats class
# HandsActions - all actions for all players for all streets - self.actions
# Hands - Summary information of hand indexed by handId - gameinfo
#This should be moved to prepInsert
hh = {}
hh['siteHandNo'] = self.handid
hh['handStart'] = self.starttime
hh['gameTypeId'] = gtid
# seats TINYINT NOT NULL,
hh['tableName'] = self.tablename
hh['maxSeats'] = self.maxseats
hh['seats'] = len(sqlids)
# Flop turn and river may all be empty - add (likely) too many elements and trim with range
boardcards = self.board['FLOP'] + self.board['TURN'] + self.board['RIVER'] + [u'0x', u'0x', u'0x', u'0x', u'0x']
cards = [Card.encodeCard(c) for c in boardcards[0:5]]
hh['boardcard1'] = cards[0]
hh['boardcard2'] = cards[1]
hh['boardcard3'] = cards[2]
hh['boardcard4'] = cards[3]
hh['boardcard5'] = cards[4]
# texture smallint,
# playersVpi SMALLINT NOT NULL, /* num of players vpi */
# Needs to be recorded
# playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
# Needs to be recorded
# playersAtStreet2 SMALLINT NOT NULL,
# Needs to be recorded
# playersAtStreet3 SMALLINT NOT NULL,
# Needs to be recorded
# playersAtStreet4 SMALLINT NOT NULL,
# Needs to be recorded
# playersAtShowdown SMALLINT NOT NULL,
# Needs to be recorded
# street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
# Needs to be recorded
# street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */
# Needs to be recorded
# street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */
# Needs to be recorded
# street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */
# Needs to be recorded
# street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
# Needs to be recorded
#print "DEBUG: self.getStreetTotals = (%s, %s, %s, %s, %s)" % self.getStreetTotals()
#FIXME: Pot size still in decimal, needs to be converted to cents
(hh['street1Pot'], hh['street2Pot'], hh['street3Pot'], hh['street4Pot'], hh['showdownPot']) = self.getStreetTotals()
# comment TEXT,
# commentTs DATETIME
#print hh
handid = db.storeHand(hh)
# HandsPlayers - ? ... Do we fix winnings?
# Tourneys ?
# TourneysPlayers
pass
def select(self, tourneyId): def select(self, tourneyId):
""" Function to create Tourney object from database """ """ Function to create Tourney object from database """
def addPlayer(self, rank, name, winnings, payinAmount, nbRebuys, nbAddons, nbKO): def addPlayer(self, rank, name, winnings, payinAmount, nbRebuys, nbAddons, nbKO):
"""\ """\
Adds a player to the tourney, and initialises data structures indexed by player. Adds a player to the tourney, and initialises data structures indexed by player.