From 0477c73801e2df4423d293e28678a920138606c8 Mon Sep 17 00:00:00 2001 From: steffen123 Date: Fri, 25 Jun 2010 11:02:01 +0200 Subject: [PATCH] changed TourneyTypes as discussed, some currency-related fixes I haven't expanded all queries etc. to include the new fields as that code is not currently used by anything and can be expanded as needed --- pyfpdb/AlchemyMappings.py | 2 +- pyfpdb/AlchemyTables.py | 13 +++++-- pyfpdb/Database.py | 19 ++++++----- pyfpdb/FulltiltToFpdb.py | 39 +++++++++++---------- pyfpdb/SQL.py | 72 ++++++++++++++++++++++++++------------- pyfpdb/Tourney.py | 38 +++++++++++++-------- 6 files changed, 112 insertions(+), 71 deletions(-) diff --git a/pyfpdb/AlchemyMappings.py b/pyfpdb/AlchemyMappings.py index 87d0f27a..dfb255b4 100644 --- a/pyfpdb/AlchemyMappings.py +++ b/pyfpdb/AlchemyMappings.py @@ -375,7 +375,7 @@ class Tourney(MappedBase): class TourneyType(MappedBase): - """Class reflecting TourneysType db table""" + """Class reflecting TourneyType db table""" @classmethod def get_or_create(cls, session, **kwargs): diff --git a/pyfpdb/AlchemyTables.py b/pyfpdb/AlchemyTables.py index 01f6f4b9..d78fb160 100644 --- a/pyfpdb/AlchemyTables.py +++ b/pyfpdb/AlchemyTables.py @@ -371,16 +371,25 @@ tourney_types_table = Table('TourneyTypes', metadata, Column('siteId', SmallInteger, ForeignKey("Sites.id"), nullable=False), Column('currency', String(4), nullable=False), # varchar(4) NOT NULL Column('buyin', Integer, nullable=False), # INT NOT NULL - Column('fee', Integer, nullable=False, default=0), # INT NOT NULL + Column('fee', Integer, nullable=False), # INT NOT NULL + Column('buyInChips', Integer, nullable=False), # INT NOT NULL Column('maxSeats', Boolean, nullable=False, default=-1), # INT NOT NULL DEFAULT -1 - Column('knockout', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False Column('rebuy', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False + Column('rebuyCost', Integer), # INT + Column('rebuyChips', Integer), # INT Column('addOn', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False + Column('addOnCost', Integer), # INT + Column('addOnChips', Integer), # INT + Column('knockout', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False + Column('koBounty', Integer), # INT Column('speed', String(10)), # varchar(10) Column('headsUp', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False Column('shootout', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False Column('matrix', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False Column('sng', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False + Column('satellite', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False + Column('doubleOrNothing', Boolean, nullable=False, default=False), # BOOLEAN NOT NULL DEFAULT False + Column('guarantee', Integer, nullable=False, default=0), # INT NOT NULL DEFAULT 0 mysql_charset='utf8', mysql_engine='InnoDB', ) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index ba4d1c3c..dbca1db4 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -75,7 +75,7 @@ except ImportError: use_numpy = False -DB_VERSION = 120 +DB_VERSION = 121 # Variance created as sqlite has a bunch of undefined aggregate functions. @@ -1357,18 +1357,17 @@ class Database: c.execute("INSERT INTO Sites (name,code) VALUES ('Carbon', 'CA')") c.execute("INSERT INTO Sites (name,code) VALUES ('PKR', 'PK')") if self.backend == self.SQLITE: - c.execute("""INSERT INTO TourneyTypes (id, siteId, buyin, fee, maxSeats, knockout + c.execute("""INSERT INTO TourneyTypes (id, siteId, currency, buyin, fee, buyInChips, maxSeats, knockout ,rebuy, addOn, speed, headsUp, shootout, matrix) - VALUES (NULL, 1, 0, 0, False, False, False, NULL, False, False, False);""") + VALUES (NULL, 1, 'USD', 0, 0, 0, False, False, False, NULL, False, False, False);""") elif self.backend == self.PGSQL: - c.execute("""insert into TourneyTypes(siteId, buyin, fee, maxSeats, knockout + c.execute("""insert into TourneyTypes(siteId, currency, buyin, fee, buyInChips, maxSeats, knockout ,rebuy, addOn, speed, headsUp, shootout, matrix) - values (1, 0, 0, 0, False, False, False, null, False, False, False);""") + values (1, 'USD', 0, 0, 0, 0, False, False, False, null, False, False, False);""") elif self.backend == self.MYSQL_INNODB: - c.execute("""insert into TourneyTypes(id, siteId, buyin, fee, maxSeats, knockout + c.execute("""insert into TourneyTypes(id, siteId, currency, buyin, fee, buyInChips, maxSeats, knockout ,rebuy, addOn, speed, headsUp, shootout, matrix) - values (DEFAULT, 1, 0, 0, 0, False, False, False, null, False, False, False);""") - + values (DEFAULT, 1, 'USD', 0, 0, 0, 0, False, False, False, null, False, False, False);""") #end def fillDefaultData def rebuild_indexes(self, start=None): @@ -1376,6 +1375,7 @@ class Database: self.createAllIndexes() self.dropAllForeignKeys() self.createAllForeignKeys() + #end def rebuild_indexes def rebuild_hudcache(self, h_start=None, v_start=None): """clears hudcache and rebuilds from the individual handsplayers records""" @@ -1795,8 +1795,9 @@ class Database: hilo = "s" elif game['category'] in ['razz','27_3draw','badugi']: hilo = "l" - tmp = self.insertGameTypes( (siteid, game['type'], game['base'], game['category'], game['limitType'], hilo, + tmp = self.insertGameTypes( (siteid, 'USD', game['type'], game['base'], game['category'], game['limitType'], hilo, int(Decimal(game['sb'])*100), int(Decimal(game['bb'])*100), 0, 0) ) + #FIXME: recognise currency return tmp[0] def getSqlPlayerIDs(self, pnames, siteid): diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index b99cc073..5ee24db0 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -87,8 +87,8 @@ class Fulltilt(HandHistoryConverter): re_TourneyBuyInChips = re.compile("Buy-In Chips: (?P\d+)") re_TourneyEntries = re.compile("(?P\d+) Entries") re_TourneyPrizePool = re.compile("Total Prize Pool: (?P\$|)?(?P[.,0-9]+)") - re_TourneyRebuyAmount = re.compile("Rebuy: (?P\$|)?(?P[.,0-9]+)") - re_TourneyAddOnAmount = re.compile("Add-On: (?P\$|)?(?P[.,0-9]+)") + re_TourneyRebuyCost = re.compile("Rebuy: (?P\$|)?(?P[.,0-9]+)") + re_TourneyAddOnCost = re.compile("Add-On: (?P\$|)?(?P[.,0-9]+)") re_TourneyRebuyCount = re.compile("performed (?P\d+) Rebuy") re_TourneyAddOnCount = re.compile("performed (?P\d+) Add-On") re_TourneyRebuysTotal = re.compile("Total Rebuys: (?P\d+)") @@ -96,7 +96,7 @@ class Fulltilt(HandHistoryConverter): re_TourneyRebuyChips = re.compile("Rebuy Chips: (?P\d+)") re_TourneyAddOnChips = re.compile("Add-On Chips: (?P\d+)") re_TourneyKOBounty = re.compile("Knockout Bounty: (?P\$|)?(?P[.,0-9]+)") - re_TourneyCountKO = re.compile("received (?P\d+) Knockout Bounty Award(s)?") + re_TourneyKoCount = re.compile("received (?P\d+) Knockout Bounty Award(s)?") re_TourneyTimeInfo = re.compile("Tournament started: (?P.*)\nTournament ((?Pis still in progress)?|(finished:(?P.*))?)$") re_TourneysPlayersSummary = re.compile("^(?P(Still Playing|\d+))( - |: )(?P[^\n,]+)(, )?(?P\$|)?(?P[.\d]+)?", re.MULTILINE) @@ -430,7 +430,7 @@ class Fulltilt(HandHistoryConverter): if m: # info list should be 2 lines : Tourney infos & Finsihing postions with winnings if (len(summaryInfoList) != 2 ): - log.info("Too many lines (%d) in file '%s' : '%s'" % (len(summaryInfoList), self.in_path, summaryInfoList) ) + log.info("Too many or too few lines (%d) in file '%s' : '%s'" % (len(summaryInfoList), self.in_path, summaryInfoList) ) self.status = False else: self.tourney = Tourney.Tourney(sitename = self.sitename, gametype = None, summaryText = summaryInfoList, builtFrom = "HHC") @@ -566,8 +566,8 @@ class Fulltilt(HandHistoryConverter): dictRegex = { "BUYINCHIPS" : self.re_TourneyBuyInChips, "ENTRIES" : self.re_TourneyEntries, "PRIZEPOOL" : self.re_TourneyPrizePool, - "REBUY_AMOUNT" : self.re_TourneyRebuyAmount, - "ADDON_AMOUNT" : self.re_TourneyAddOnAmount, + "REBUY_COST" : self.re_TourneyRebuyCost, + "ADDON_COST" : self.re_TourneyAddOnCost, "REBUY_TOTAL" : self.re_TourneyRebuysTotal, "ADDONS_TOTAL" : self.re_TourneyAddOnsTotal, "REBUY_CHIPS" : self.re_TourneyRebuyChips, @@ -580,8 +580,8 @@ class Fulltilt(HandHistoryConverter): dictHolders = { "BUYINCHIPS" : "buyInChips", "ENTRIES" : "entries", "PRIZEPOOL" : "prizepool", - "REBUY_AMOUNT" : "rebuyAmount", - "ADDON_AMOUNT" : "addOnAmount", + "REBUY_COST" : "rebuyCost", + "ADDON_COST" : "addOnCost", "REBUY_TOTAL" : "totalRebuyCount", "ADDONS_TOTAL" : "totalAddOnCount", "REBUY_CHIPS" : "rebuyChips", @@ -607,37 +607,36 @@ class Fulltilt(HandHistoryConverter): if m is not None: mg = m.groupdict() if mg['REBUY_COUNT'] is not None : - tourney.countRebuys.update( { tourney.hero : Decimal(mg['REBUY_COUNT']) } ) + tourney.rebuyCounts.update( { tourney.hero : Decimal(mg['REBUY_COUNT']) } ) m = self.re_TourneyAddOnCount.search(tourneyText) if m is not None: mg = m.groupdict() if mg['ADDON_COUNT'] is not None : - tourney.countAddOns.update( { tourney.hero : Decimal(mg['ADDON_COUNT']) } ) - m = self.re_TourneyCountKO.search(tourneyText) + tourney.addOnCounts.update( { tourney.hero : Decimal(mg['ADDON_COUNT']) } ) + m = self.re_TourneyKoCount.search(tourneyText) if m is not None: mg = m.groupdict() if mg['COUNT_KO'] is not None : - tourney.countKO.update( { tourney.hero : Decimal(mg['COUNT_KO']) } ) + tourney.koCounts.update( { tourney.hero : Decimal(mg['COUNT_KO']) } ) # Deal with money amounts tourney.koBounty = 100*Decimal(re.sub(u',', u'', "%s" % tourney.koBounty)) tourney.prizepool = 100*Decimal(re.sub(u',', u'', "%s" % tourney.prizepool)) - tourney.rebuyAmount = 100*Decimal(re.sub(u',', u'', "%s" % tourney.rebuyAmount)) - tourney.addOnAmount = 100*Decimal(re.sub(u',', u'', "%s" % tourney.addOnAmount)) + tourney.rebuyCost = 100*Decimal(re.sub(u',', u'', "%s" % tourney.rebuyCost)) + tourney.addOnCost = 100*Decimal(re.sub(u',', u'', "%s" % tourney.addOnCost)) # Calculate payin amounts and update winnings -- not possible to take into account nb of rebuys, addons or Knockouts for other players than hero on FTP for p in tourney.players : - tourney.payinAmounts[p] = tourney.buyin + tourney.fee + (tourney.rebuyAmount * tourney.countRebuys[p]) + (tourney.addOnAmount * tourney.countAddOns[p]) + tourney.payinAmounts[p] = tourney.buyin + tourney.fee + (tourney.rebuyCost * tourney.rebuyCounts[p]) + (tourney.addOnCost * tourney.addOnCounts[p]) #print " player %s : payinAmount = %d" %( p, tourney.payinAmounts[p]) if tourney.isKO : - #tourney.incrementPlayerWinnings(tourney.players[p], Decimal(tourney.koBounty)*Decimal(tourney.countKO[p])) - tourney.winnings[p] += Decimal(tourney.koBounty)*Decimal(tourney.countKO[p]) + #tourney.incrementPlayerWinnings(tourney.players[p], Decimal(tourney.koBounty)*Decimal(tourney.koCounts[p])) + tourney.winnings[p] += Decimal(tourney.koBounty)*Decimal(tourney.koCounts[p]) #print "player %s : winnings %d" % (p, tourney.winnings[p]) - - #print mg return True + #end def determineTourneyType def getPlayersPositionsAndWinnings(self, tourney): playersText = tourney.summaryText[1] @@ -656,7 +655,7 @@ class Fulltilt(HandHistoryConverter): else: winnings = "0" - tourney.addPlayer(rank, a.group('PNAME'), winnings, 0, 0, 0, 0) + tourney.addPlayer(rank, a.group('PNAME'), winnings, "USD", 0, 0, 0, 0) #TODO: make it store actual winnings currency else: print "FullTilt: Player finishing stats unreadable : %s" % a diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 9ba87fbb..d624ee26 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -360,21 +360,29 @@ class Sql: if db_server == 'mysql': self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( - id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), - currency varchar(4) NOT NULL, - buyin INT NOT NULL, - fee INT NOT NULL, - maxSeats INT NOT NULL DEFAULT -1, - knockout BOOLEAN NOT NULL DEFAULT False, - rebuy BOOLEAN NOT NULL DEFAULT False, - addOn BOOLEAN NOT NULL DEFAULT False, - speed varchar(10), - headsUp BOOLEAN NOT NULL DEFAULT False, - shootout BOOLEAN NOT NULL DEFAULT False, - matrix BOOLEAN NOT NULL DEFAULT False, - sng BOOLEAN NOT NULL DEFAULT False - ) + id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), + currency varchar(4) NOT NULL, + buyIn INT NOT NULL, + fee INT NOT NULL, + buyInChips INT NOT NULL, + maxSeats INT NOT NULL DEFAULT -1, + rebuy BOOLEAN NOT NULL DEFAULT False, + rebuyCost INT, + rebuyChips INT, + addOn BOOLEAN NOT NULL DEFAULT False, + addOnCost INT, + addOnChips INT, + knockout BOOLEAN NOT NULL DEFAULT False, + koBounty INT, + speed varchar(10), + headsUp BOOLEAN NOT NULL DEFAULT False, + shootout BOOLEAN NOT NULL DEFAULT False, + matrix BOOLEAN NOT NULL DEFAULT False, + sng BOOLEAN NOT NULL DEFAULT False, + satellite BOOLEAN NOT NULL DEFAULT False, + doubleOrNothing BOOLEAN NOT NULL DEFAULT False, + guarantee INT) ENGINE=INNODB""" elif db_server == 'postgresql': self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( @@ -383,33 +391,49 @@ class Sql: currency varchar(4) NOT NULL, buyin INT NOT NULL, fee INT NOT NULL, + buyInChips INT NOT NULL, maxSeats INT NOT NULL DEFAULT -1, - knockout BOOLEAN NOT NULL DEFAULT False, rebuy BOOLEAN NOT NULL DEFAULT False, + rebuyCost INT, + rebuyChips INT, addOn BOOLEAN NOT NULL DEFAULT False, + addOnCost INT, + addOnChips INT, + knockout BOOLEAN NOT NULL DEFAULT False, + koBounty INT, speed varchar(10), headsUp BOOLEAN NOT NULL DEFAULT False, shootout BOOLEAN NOT NULL DEFAULT False, matrix BOOLEAN NOT NULL DEFAULT False, - sng BOOLEAN NOT NULL DEFAULT False - )""" + sng BOOLEAN NOT NULL DEFAULT False, + satellite BOOLEAN NOT NULL DEFAULT False, + doubleOrNothing BOOLEAN NOT NULL DEFAULT False, + guarantee INT)""" elif db_server == 'sqlite': self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( id INTEGER PRIMARY KEY, siteId INT NOT NULL, - currency TEXT NOT NULL, + currency VARCHAR(4) NOT NULL, buyin INT NOT NULL, fee INT NOT NULL, + buyInChips INT NOT NULL, maxSeats INT NOT NULL DEFAULT -1, - knockout BOOLEAN NOT NULL DEFAULT 0, rebuy BOOLEAN NOT NULL DEFAULT 0, + rebuyCost INT, + rebuyChips INT, addOn BOOLEAN NOT NULL DEFAULT 0, + addOnCost INT, + addOnChips INT, + knockout BOOLEAN NOT NULL DEFAULT 0, + koBounty INT, speed TEXT, headsUp BOOLEAN NOT NULL DEFAULT 0, shootout BOOLEAN NOT NULL DEFAULT 0, matrix BOOLEAN NOT NULL DEFAULT 0, - sng BOOLEAN NOT NULL DEFAULT 0 - )""" + sng BOOLEAN NOT NULL DEFAULT 0, + satellite BOOLEAN NOT NULL DEFAULT 0, + doubleOrNothing BOOLEAN NOT NULL DEFAULT 0, + guarantee INT)""" ################################ # Create Tourneys @@ -3552,9 +3576,9 @@ class Sql: """ self.query['insertGameTypes'] = """INSERT INTO Gametypes - (siteId, type, base, category, limitType + (siteId, currency, type, base, category, limitType ,hiLo, smallBlind, bigBlind, smallBet, bigBet) - 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['isAlreadyInDB'] = """SELECT id FROM Hands WHERE gametypeId=%s AND siteHandNo=%s diff --git a/pyfpdb/Tourney.py b/pyfpdb/Tourney.py index 7e3e317f..ad1130c3 100644 --- a/pyfpdb/Tourney.py +++ b/pyfpdb/Tourney.py @@ -74,22 +74,26 @@ class Tourney(object): self.subTourneyFee = None self.rebuyChips = 0 self.addOnChips = 0 - self.rebuyAmount = 0 - self.addOnAmount = 0 + self.rebuyCost = 0 + self.addOnCost = 0 self.totalRebuyCount = 0 self.totalAddOnCount = 0 self.koBounty = 0 self.tourneyComment = None self.players = [] + self.isSng = False + self.isSatellite = False + self.isDoubleOrNothing = False + self.guarantee = 0 # Collections indexed by player names self.finishPositions = {} self.winnings = {} self.winningsCurrency = {} self.payinAmounts = {} - self.countRebuys = {} - self.countAddOns = {} - self.countKO = {} + self.rebuyCounts = {} + self.addOnCounts = {} + self.koCounts = {} # currency symbol for this summary self.sym = None @@ -121,12 +125,16 @@ class Tourney(object): ("SUB TOURNEY FEE", self.subTourneyFee), ("REBUY CHIPS", self.rebuyChips), ("ADDON CHIPS", self.addOnChips), - ("REBUY AMOUNT", self.rebuyAmount), - ("ADDON AMOUNT", self.addOnAmount), + ("REBUY COST", self.rebuyCost), + ("ADDON COST", self.addOnCost), ("TOTAL REBUYS", self.totalRebuyCount), ("TOTAL ADDONS", self.totalAddOnCount), ("KO BOUNTY", self.koBounty), - ("TOURNEY COMMENT", self.tourneyComment) + ("TOURNEY COMMENT", self.tourneyComment), + ("SNG", self.isSng), + ("SATELLITE", self.isSatellite), + ("DOUBLE OR NOTHING", self.isDoubleOrNothing), + ("GUARANTEE", self.guarantee) ) structs = ( ("GAMETYPE", self.gametype), @@ -134,9 +142,9 @@ class Tourney(object): ("PAYIN AMOUNTS", self.payinAmounts), ("POSITIONS", self.finishPositions), ("WINNINGS", self.winnings), - ("COUNT REBUYS", self.countRebuys), - ("COUNT ADDONS", self.countAddOns), - ("NB OF KO", self.countKO) + ("COUNT REBUYS", self.rebuyCounts), + ("COUNT ADDONS", self.addOnCounts), + ("NB OF KO", self.koCounts) ) str = '' for (name, var) in vars: @@ -199,11 +207,11 @@ winnings (decimal) the money the player ended the tourney with (can be 0, or self.players.append(name) self.finishPositions.update( { name : Decimal(rank) } ) self.winnings.update( { name : Decimal(winnings) } ) - self.winningsCurrency.update( { name : String(winningsCurrency) } ) + self.winningsCurrency.update( { name : winningsCurrency } ) self.payinAmounts.update( {name : Decimal(payinAmount) } ) - self.countRebuys.update( {name: Decimal(rebuyCount) } ) - self.countAddOns.update( {name: Decimal(addOnCount) } ) - self.countKO.update( {name : Decimal(koCount) } ) + self.rebuyCounts.update( {name: Decimal(rebuyCount) } ) + self.addOnCounts.update( {name: Decimal(addOnCount) } ) + self.koCounts.update( {name : Decimal(koCount) } ) def incrementPlayerWinnings(self, name, additionnalWinnings):