minor DB changes. recording TourneysPlayers now for FTP and PS

This commit is contained in:
steffen123 2010-07-07 00:52:44 +02:00
parent e4916bc456
commit 04ed65e88c
4 changed files with 39 additions and 34 deletions

View File

@ -75,7 +75,7 @@ except ImportError:
use_numpy = False
DB_VERSION = 125
DB_VERSION = 126
# Variance created as sqlite has a bunch of undefined aggregate functions.
@ -1985,7 +1985,7 @@ class Database:
(tourney.siteId, tourney.tourNo))
result=cursor.fetchone()
if len(result)==1:
if result != None and len(result)==1:
tourneyId = result[0]
else:
cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']),
@ -1996,8 +1996,23 @@ class Database:
return tourneyId
#end def createOrUpdateTourney
def createOrUpdateTourneysPlayers(self, tourney):
print "TODO implement createOrUpdateTourneysPlayers"
def createOrUpdateTourneysPlayers(self, hand, tourney):
tourneysPlayersIds=[]
for player in hand.players:
playerId = hand.dbid_pids[player[1]]
cursor = self.get_cursor()
cursor.execute (self.sql.query['getTourneysPlayersId'].replace('%s', self.sql.query['placeholder']),
(tourney.tourneyId, playerId))
result=cursor.fetchone()
if result != None and len(result)==1:
tourneysPlayersIds.append(result[0])
else:
cursor.execute (self.sql.query['insertTourneysPlayer'].replace('%s', self.sql.query['placeholder']),
(tourney.tourneyId, playerId, None, None, None, None, None, None, None, None))
tourneysPlayersIds.append(self.get_last_insert_id(cursor))
return tourneysPlayersIds
#end def createOrUpdateTourneysPlayers
#end class Database

View File

@ -229,7 +229,6 @@ class Fulltilt(HandHistoryConverter):
hand.buyinCurrency="NA"
hand.buyin = 100*Decimal(n.group('BUYIN'))
hand.fee = 100*Decimal(n.group('FEE'))
print "currency, buyin, fee: ", n.group('CURRENCY'), n.group('BUYIN'), n.group('CURRENCY'), n.group('FEE')
if n.group('TURBO') is not None :
hand.speed = "Turbo"
if n.group('SPECIAL') is not None :

View File

@ -213,13 +213,13 @@ dealt whether they were seen in a 'dealt to' line
#Gametypes
self.dbid_gt = db.getGameTypeId(self.siteId, self.gametype)
if self.tourney!=None:
if self.tourNo!=None:
self.tourney=Tourney.Tourney(self.sitename, self.gametype, None, builtFrom="HHC-HH", hand=self)
self.tourney.tourneyTypeId = db.createOrUpdateTourneyType(self.tourney)
db.commit()
self.tourney.tourneyId = db.createOrUpdateTourney(self.tourney)
db.commit()
self.tourney.tourneysPlayersIds = db.createOrUpdateTourneysPlayers(self.tourney)
self.tourney.tourneysPlayersIds = db.createOrUpdateTourneysPlayers(self, self.tourney)
db.commit()
#end def prepInsert
@ -244,9 +244,8 @@ db: a connected Database object"""
self.dbid_hands = db.storeHand(hh)
db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, self.stats.getHandsPlayers())
# HandsActions - all actions for all players for all streets - self.actions
# TODO HandsActions - all actions for all players for all streets - self.actions
# HudCache data can be generated from HandsActions (HandsPlayers?)
print "TODO: store TourneysPlayers"
else:
log.info("Hand.insert(): hid #: %s is a duplicate" % hh['siteHandNo'])
self.is_duplicate = True # i.e. don't update hudcache

View File

@ -849,12 +849,12 @@ class Sql:
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
rank INT NOT NULL,
winnings INT NOT NULL,
winningsCurrency VARCHAR(4) NOT NULL,
rebuyCount INT DEFAULT 0,
addOnCount INT DEFAULT 0,
koCount INT DEFAULT 0,
rank INT,
winnings INT,
winningsCurrency VARCHAR(4),
rebuyCount INT,
addOnCount INT,
koCount INT,
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
@ -866,9 +866,9 @@ class Sql:
rank INT,
winnings INT,
winningsCurrency VARCHAR(4),
rebuyCount INT DEFAULT 0,
addOnCount INT DEFAULT 0,
koCount INT DEFAULT 0,
rebuyCount INT,
addOnCount INT,
koCount INT,
comment TEXT,
commentTs timestamp without time zone)"""
elif db_server == 'sqlite':
@ -879,9 +879,9 @@ class Sql:
rank INT,
winnings INT,
winningsCurrency VARCHAR(4),
rebuyCount INT DEFAULT 0,
addOnCount INT DEFAULT 0,
koCount INT DEFAULT 0,
rebuyCount INT,
addOnCount INT,
koCount INT,
comment TEXT,
commentTs timestamp without time zone,
FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
@ -1265,13 +1265,13 @@ class Sql:
self.query['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
if db_server == 'mysql':
self.query['addTTypesIndex'] = """ALTER TABLE TourneyTypes ADD UNIQUE INDEX tourneytypes_all(buyin, fee
self.query['addTTypesIndex'] = """ALTER TABLE TourneyTypes ADD UNIQUE INDEX tourneytypes_all(siteId, buyin, fee
, maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
elif db_server == 'postgresql':
self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (buyin, fee
self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (siteId, buyin, fee
, maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
elif db_server == 'sqlite':
self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (buyin, fee
self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (siteId, buyin, fee
, maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
self.query['get_last_hand'] = "select max(id) from Hands"
@ -3647,15 +3647,7 @@ class Sql:
WHERE id=%s
"""
self.query['getTourneysPlayers'] = """SELECT id,
rank,
winnings,
winningsCurrency,
rebuyCount,
addOnCount,
koCount,
comment,
commentTs
self.query['getTourneysPlayersId'] = """SELECT id
FROM TourneysPlayers
WHERE tourneyId=%s AND playerId+0=%s
"""
@ -3672,7 +3664,7 @@ class Sql:
WHERE id=%s
"""
self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers
self.query['insertTourneysPlayer'] = """INSERT INTO TourneysPlayers
(tourneyId, playerId, rank, winnings, winningsCurrency, rebuyCount, addOnCount, koCount, comment, commentTs)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
"""