From 85cc5a5471ed07b7dd45c72380d20d0f8b3384b0 Mon Sep 17 00:00:00 2001 From: steffen123 Date: Wed, 14 Jul 2010 22:36:07 +0200 Subject: [PATCH] TOURNEY: DB.createOrUpdateTourney fills in missing fields now --- pyfpdb/Database.py | 31 +++++++++++++++++++++++++------ pyfpdb/SQL.py | 5 ++--- pyfpdb/TourneySummary.py | 6 +++++- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 460d381a..3b5d32e2 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -2033,12 +2033,31 @@ class Database: def createOrUpdateTourney(self, hand, source):#note: this method is used on Hand and TourneySummary objects cursor = self.get_cursor() - cursor.execute (self.sql.query['getTourneyIdByTourneyNo'].replace('%s', self.sql.query['placeholder']), + cursor.execute (self.sql.query['getTourneyByTourneyNo'].replace('%s', self.sql.query['placeholder']), (hand.siteId, hand.tourNo)) + columnNames=[desc[0] for desc in cursor.description] result=cursor.fetchone() - - if result != None and len(result)==1: - tourneyId = result[0] + + if result != None: + expectedValues = ('comment', 'tourneyName', 'matrixIdProcessed', 'totalRebuyCount', 'totalAddOnCount', + 'prizepool', 'startTime', 'entries', 'commentTs', 'endTime') + updateDb=False + resultDict = dict(zip(columnNames, result)) + + tourneyId = resultDict["id"] + if source=="TS": + for ev in expectedValues : + if getattr(hand, ev)==None and resultDict[ev]!=None:#DB has this value but object doesnt, so update object + setattr(hand, ev, resultDict[ev]) + elif getattr(hand, ev)!=None and resultDict[ev]==None:#object has this value but DB doesnt, so update DB + updateDb=True + elif ev=="startTime": + if (resultDict[ev] < hand.startTime): + hand.startTime=resultDict[ev] + if updateDb: + cursor.execute (self.sql.query['updateTourney'].replace('%s', self.sql.query['placeholder']), + (hand.entries, hand.prizepool, hand.startTime, hand.endTime, hand.tourneyName, + hand.matrixIdProcessed, hand.totalRebuyCount, hand.totalAddOnCount, hand.comment, hand.commentTs, tourneyId)) else: if source=="HHC": cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']), @@ -2046,8 +2065,8 @@ class Database: hand.startTime, None, None, None, None, None)) elif source=="TS": cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']), - (hand.tourneyTypeId, hand.tourNo, hand.entries, hand.prizepool, - hand.startTime, hand.endTime, hand.tourneyName, hand.matrixIdProcessed, hand.totalRebuyCount, hand.totalAddOnCount)) + (hand.tourneyTypeId, hand.tourNo, hand.entries, hand.prizepool, hand.startTime, + hand.endTime, hand.tourneyName, hand.matrixIdProcessed, hand.totalRebuyCount, hand.totalAddOnCount)) else: raise FpdbParseError("invalid source in Database.createOrUpdateTourney") tourneyId = self.get_last_insert_id(cursor) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index cf4bb1ee..a3204bea 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -3700,7 +3700,7 @@ class Sql: VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """ - self.query['getTourneyIdByTourneyNo'] = """SELECT t.id + self.query['getTourneyByTourneyNo'] = """SELECT t.* FROM Tourneys t INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id) WHERE tt.siteId=%s AND t.siteTourneyNo=%s @@ -3714,8 +3714,7 @@ class Sql: """ self.query['updateTourney'] = """UPDATE Tourneys - SET tourneyTypeId = %s, - entries = %s, + SET entries = %s, prizepool = %s, startTime = %s, endTime = %s, diff --git a/pyfpdb/TourneySummary.py b/pyfpdb/TourneySummary.py index f10d3993..b8045104 100644 --- a/pyfpdb/TourneySummary.py +++ b/pyfpdb/TourneySummary.py @@ -93,6 +93,8 @@ class TourneySummary(object): self.isDoubleOrNothing = False self.guarantee = 0 self.gametype = {'category':None, 'limitType':None} + self.comment = None + self.commentTs = None # Collections indexed by player names self.playerIds = {} @@ -151,7 +153,9 @@ class TourneySummary(object): ("SNG", self.isSng), ("SATELLITE", self.isSatellite), ("DOUBLE OR NOTHING", self.isDoubleOrNothing), - ("GUARANTEE", self.guarantee) + ("GUARANTEE", self.guarantee), + ("COMMENT", self.comment), + ("COMMENT TIMESTAMP", self.commentTs) ) structs = ( ("PLAYER IDS", self.playerIds),