From 04ed65e88c072be7a10100591e812ae5ae2d5d0b Mon Sep 17 00:00:00 2001 From: steffen123 Date: Wed, 7 Jul 2010 00:52:44 +0200 Subject: [PATCH] minor DB changes. recording TourneysPlayers now for FTP and PS --- pyfpdb/Database.py | 23 ++++++++++++++++++---- pyfpdb/FulltiltToFpdb.py | 1 - pyfpdb/Hand.py | 7 +++---- pyfpdb/SQL.py | 42 ++++++++++++++++------------------------ 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 381bde4d..fc69f9e3 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -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 diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index 59db6bb4..5ae5713b 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -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 : diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 8932457b..ef48517e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -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 diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 59237187..159408d0 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -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) """