more tourney work

- moved HH-based tourney handling completely into Hand
- renamed Tourney.py to TourneySummaries
- changed many DB fields to allow NULL and removed defaults
This commit is contained in:
steffen123 2010-07-07 04:01:40 +02:00
parent 18faa5288c
commit eb3233ac98
6 changed files with 96 additions and 94 deletions

View File

@ -53,7 +53,6 @@ log = logging.getLogger("db")
# FreePokerTools modules
import SQL
import Card
import Tourney
import Charset
from Exceptions import *
import Configuration
@ -75,7 +74,7 @@ except ImportError:
use_numpy = False
DB_VERSION = 126
DB_VERSION = 127
# Variance created as sqlite has a bunch of undefined aggregate functions.
@ -1933,13 +1932,13 @@ class Database:
print "***Error sending finish: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
# end def send_finish_msg():
def createOrUpdateTourneyType(self, tourney):
def createOrUpdateTourneyType(self, hand):
tourneyTypeId = 1
# Check if Tourney exists, and if so retrieve TTypeId : in that case, check values of the ttype
cursor = self.get_cursor()
cursor.execute (self.sql.query['getTourneyTypeIdByTourneyNo'].replace('%s', self.sql.query['placeholder']),
(tourney.tourNo, tourney.siteId)
(hand.tourNo, hand.siteId)
)
result=cursor.fetchone()
@ -1951,8 +1950,8 @@ class Database:
tourneyTypeId = result[0]
log.debug("Tourney found in db with Tourney_Type_ID = %d" % tourneyTypeId)
for ev in expectedValues :
if ( getattr( tourney, expectedValues.get(ev) ) <> result[ev] ):
log.debug("TypeId mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValues.get(ev), getattr( tourney, expectedValues.get(ev)), result[ev]) )
if ( getattr( hand, expectedValues.get(ev) ) <> result[ev] ):
log.debug("TypeId mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValues.get(ev), getattr( hand, expectedValues.get(ev)), result[ev]) )
tourneyTypeIdMatch = False
#break
except:
@ -1962,8 +1961,8 @@ class Database:
if tourneyTypeIdMatch == False :
# Check for an existing TTypeId that matches tourney info, if not found create it
cursor.execute (self.sql.query['getTourneyTypeId'].replace('%s', self.sql.query['placeholder']),
(tourney.siteId, tourney.currency, tourney.buyin, tourney.fee, tourney.isKO,
tourney.isRebuy, tourney.isAddOn, tourney.speed, tourney.isShootout, tourney.isMatrix)
(hand.siteId, hand.buyinCurrency, hand.buyin, hand.fee, hand.isKO,
hand.isRebuy, hand.isRebuy, hand.speed, hand.isShootout, hand.isMatrix)
)
result=cursor.fetchone()
@ -1971,46 +1970,46 @@ class Database:
tourneyTypeId = result[0]
except TypeError: #this means we need to create a new entry
cursor.execute (self.sql.query['insertTourneyType'].replace('%s', self.sql.query['placeholder']),
(tourney.siteId, tourney.currency, tourney.buyin, tourney.fee, tourney.buyInChips,
tourney.isKO, tourney.isRebuy,
tourney.isAddOn, tourney.speed, tourney.isShootout, tourney.isMatrix)
(hand.siteId, hand.buyinCurrency, hand.buyin, hand.fee, hand.buyInChips,
hand.isKO, hand.isRebuy,
hand.isAddOn, hand.speed, hand.isShootout, hand.isMatrix)
)
tourneyTypeId = self.get_last_insert_id(cursor)
return tourneyTypeId
#end def createOrUpdateTourneyType
def createOrUpdateTourney(self, tourney):
def createOrUpdateTourney(self, hand):
cursor = self.get_cursor()
cursor.execute (self.sql.query['getTourneyIdByTourneyNo'].replace('%s', self.sql.query['placeholder']),
(tourney.siteId, tourney.tourNo))
(hand.siteId, hand.tourNo))
result=cursor.fetchone()
if result != None and len(result)==1:
tourneyId = result[0]
else:
cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']),
(tourney.tourneyTypeId, tourney.tourNo, tourney.entries, tourney.prizepool,
tourney.startTime, tourney.endTime, tourney.tourneyName, None,
tourney.totalRebuyCount, tourney.totalAddOnCount))
(hand.tourneyTypeId, hand.tourNo, None, None,
hand.startTime, None, None, None,
None, None))
tourneyId = self.get_last_insert_id(cursor)
return tourneyId
#end def createOrUpdateTourney
def createOrUpdateTourneysPlayers(self, hand, tourney):
def createOrUpdateTourneysPlayers(self, hand):
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))
(hand.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))
(hand.tourneyId, playerId, None, None, None, None, None, None, None, None))
tourneysPlayersIds.append(self.get_last_insert_id(cursor))
return tourneysPlayersIds
#end def createOrUpdateTourneysPlayers

View File

@ -20,6 +20,7 @@
import logging
from HandHistoryConverter import *
import TourneySummary
# Fulltilt HH Format converter
@ -227,8 +228,8 @@ class Fulltilt(HandHistoryConverter):
hand.buyinCurrency="EUR"
else:
hand.buyinCurrency="NA"
hand.buyin = 100*Decimal(n.group('BUYIN'))
hand.fee = 100*Decimal(n.group('FEE'))
hand.buyin = int(100*Decimal(n.group('BUYIN')))
hand.fee = int(100*Decimal(n.group('FEE')))
if n.group('TURBO') is not None :
hand.speed = "Turbo"
if n.group('SPECIAL') is not None :
@ -440,7 +441,7 @@ class Fulltilt(HandHistoryConverter):
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")
self.tourney = TourneySummary.TourneySummary(sitename = self.sitename, gametype = None, summaryText = summaryInfoList, builtFrom = "HHC")
self.status = self.getPlayersPositionsAndWinnings(self.tourney)
if self.status == True :
self.status = self.determineTourneyType(self.tourney)

View File

@ -71,15 +71,18 @@ class Hand(object):
self.buttonpos = 0
#tourney stuff
self.tourney = None
self.tourNo = None
self.tourneyId = None
self.tourneyTypeId = None
self.buyin = None
self.buyinCurrency = None
self.buyInChips = None
self.fee = None # the Database code is looking for this one .. ?
self.level = None
self.mixed = None
self.speed = "Normal"
self.isRebuy = False
self.isAddOn = False
self.isKO = False
self.isMatrix = False
self.isShootout = False
@ -88,6 +91,7 @@ class Hand(object):
self.seating = []
self.players = []
self.posted = []
self.tourneysPlayersIds = []
# Collections indexed by street names
self.bets = {}
@ -137,10 +141,6 @@ class Hand(object):
("TABLE NAME", self.tablename),
("HERO", self.hero),
("MAXSEATS", self.maxseats),
("TOURNAMENT NO", self.tourNo),
("BUYIN", self.buyin),
("BUYIN CURRENCY", self.buyinCurrency),
("FEE", self.fee),
("LEVEL", self.level),
("MIXED", self.mixed),
("LASTBET", self.lastBet),
@ -157,6 +157,19 @@ class Hand(object):
("TOTAL COLLECTED", self.totalcollected),
("RAKE", self.rake),
("START TIME", self.startTime),
("TOURNAMENT NO", self.tourNo),
("TOURNEY ID", self.tourneyId),
("TOURNEY TYPE ID", self.tourneyTypeId),
("BUYIN", self.buyin),
("BUYIN CURRENCY", self.buyinCurrency),
("BUYIN CHIPS", self.buyInChips),
("FEE", self.fee),
("IS REBUY", self.isRebuy),
("IS ADDON", self.isAddOn),
("IS KO", self.isKO),
("IS MATRIX", self.isMatrix),
("IS SHOOTOUT", self.isShootout),
("TOURNEY COMMENT", self.tourneyComment),
)
structs = ( ("PLAYERS", self.players),
@ -171,6 +184,7 @@ class Hand(object):
("BOARD", self.board),
("DISCARDS", self.discards),
("HOLECARDS", self.holecards),
("TOURNEYS PLAYER IDS", self.tourneysPlayersIds),
)
str = ''
for (name, var) in vars:
@ -214,12 +228,11 @@ dealt whether they were seen in a 'dealt to' line
self.dbid_gt = db.getGameTypeId(self.siteId, self.gametype)
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)
self.tourneyTypeId = db.createOrUpdateTourneyType(self)
db.commit()
self.tourney.tourneyId = db.createOrUpdateTourney(self.tourney)
self.tourneyId = db.createOrUpdateTourney(self)
db.commit()
self.tourney.tourneysPlayersIds = db.createOrUpdateTourneysPlayers(self, self.tourney)
self.tourneysPlayersIds = db.createOrUpdateTourneysPlayers(self)
db.commit()
#end def prepInsert

View File

@ -256,8 +256,8 @@ class PokerStars(HandHistoryConverter):
hand.buyinCurrency="NA" #FIXME: handle other currencies, FPP, play money
info[key]=info[key][:-4]
middle=info[key].find("+")
hand.buyin = 100*Decimal(info[key][1:middle])
hand.fee = 100*Decimal(info[key][middle+2:])
hand.buyin = int(100*Decimal(info[key][1:middle]))
hand.fee = int(100*Decimal(info[key][middle+2:]))
if key == 'LEVEL':
hand.level = info[key]

View File

@ -368,22 +368,22 @@ 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,
rebuy BOOLEAN NOT NULL DEFAULT False,
buyInChips INT,
maxSeats INT,
rebuy BOOLEAN,
rebuyCost INT,
rebuyChips INT,
addOn BOOLEAN NOT NULL DEFAULT False,
addOn BOOLEAN,
addOnCost INT,
addOnChips INT,
knockout BOOLEAN NOT NULL DEFAULT False,
knockout BOOLEAN,
koBounty INT,
speed varchar(10),
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,
shootout BOOLEAN,
matrix BOOLEAN,
sng BOOLEAN,
satellite BOOLEAN,
doubleOrNothing BOOLEAN,
guarantee INT)
ENGINE=INNODB"""
elif db_server == 'postgresql':
@ -393,22 +393,22 @@ 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,
rebuy BOOLEAN NOT NULL DEFAULT False,
buyInChips INT,
maxSeats INT,
rebuy BOOLEAN,
rebuyCost INT,
rebuyChips INT,
addOn BOOLEAN NOT NULL DEFAULT False,
addOn BOOLEAN,
addOnCost INT,
addOnChips INT,
knockout BOOLEAN NOT NULL DEFAULT False,
knockout BOOLEAN,
koBounty INT,
speed varchar(10),
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,
shootout BOOLEAN,
matrix BOOLEAN,
sng BOOLEAN,
satellite BOOLEAN,
doubleOrNothing BOOLEAN,
guarantee INT)"""
elif db_server == 'sqlite':
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
@ -417,22 +417,22 @@ 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,
rebuy BOOLEAN NOT NULL DEFAULT 0,
buyInChips INT,
maxSeats INT,
rebuy BOOLEAN,
rebuyCost INT,
rebuyChips INT,
addOn BOOLEAN NOT NULL DEFAULT 0,
addOn BOOLEAN,
addOnCost INT,
addOnChips INT,
knockout BOOLEAN NOT NULL DEFAULT 0,
knockout BOOLEAN,
koBounty INT,
speed TEXT,
shootout BOOLEAN NOT NULL DEFAULT 0,
matrix BOOLEAN NOT NULL DEFAULT 0,
sng BOOLEAN NOT NULL DEFAULT 0,
satellite BOOLEAN NOT NULL DEFAULT 0,
doubleOrNothing BOOLEAN NOT NULL DEFAULT 0,
shootout BOOLEAN,
matrix BOOLEAN,
sng BOOLEAN,
satellite BOOLEAN,
doubleOrNothing BOOLEAN,
guarantee INT)"""
################################
@ -442,23 +442,23 @@ class Sql:
if db_server == 'mysql':
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
siteTourneyNo BIGINT NOT NULL,
entries INT NOT NULL,
prizepool INT NOT NULL,
entries INT,
prizepool INT,
startTime DATETIME NOT NULL,
endTime DATETIME,
tourneyName varchar(40),
matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
totalRebuyCount INT DEFAULT 0,
totalAddOnCount INT DEFAULT 0,
totalRebuyCount INT,
totalAddOnCount INT,
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
id SERIAL, PRIMARY KEY (id),
tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
siteTourneyNo BIGINT,
entries INT,
prizepool INT,
@ -466,14 +466,14 @@ class Sql:
endTime timestamp without time zone,
tourneyName varchar(40),
matrixIdProcessed SMALLINT DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
totalRebuyCount INT DEFAULT 0,
totalAddOnCount INT DEFAULT 0,
totalRebuyCount INT,
totalAddOnCount INT,
comment TEXT,
commentTs timestamp without time zone)"""
elif db_server == 'sqlite':
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
id INTEGER PRIMARY KEY,
tourneyTypeId INT DEFAULT 1,
tourneyTypeId INT,
siteTourneyNo INT,
entries INT,
prizepool INT,
@ -481,8 +481,8 @@ class Sql:
endTime REAL,
tourneyName TEXT,
matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
totalRebuyCount INT DEFAULT 0,
totalAddOnCount INT DEFAULT 0,
totalRebuyCount INT,
totalAddOnCount INT,
comment TEXT,
commentTs REAL)"""
################################

View File

@ -34,7 +34,7 @@ import Card
log = logging.getLogger("parser")
class Tourney(object):
class TourneySummary(object):
################################################################
# Class Variables
@ -45,7 +45,7 @@ class Tourney(object):
SITEIDS = {'Fulltilt':1, 'PokerStars':2, 'Everleaf':3, 'Win2day':4, 'OnGame':5, 'UltimateBet':6, 'Betfair':7, 'Absolute':8, 'PartyPoker':9 }
def __init__(self, sitename, gametype, summaryText, builtFrom = "HHC", hand=None):
def __init__(self, sitename, gametype, summaryText, builtFrom = "HHC"):
self.sitename = sitename
self.siteId = self.SITEIDS[sitename]
self.gametype = gametype
@ -54,23 +54,12 @@ class Tourney(object):
self.tourneyName = None
self.tourneyTypeId = None
self.tourneyId = None
if builtFrom=="HHC":
self.startTime = None
self.endTime = None
self.tourNo = None
self.currency = None
self.buyin = None
self.fee = None
elif builtFrom=="HHC-HH":
self.startTime = hand.startTime
#since tourney.startTime should only be stored to DB when the first hand of a tourney is imported this should actually be correct
self.endTime = hand.startTime #TODO parse this
self.tourNo = hand.tourNo
self.currency = hand.buyinCurrency
self.buyin = int(hand.buyin)
self.fee = int(hand.fee)
else:
print "need to bail"
self.startTime = None
self.endTime = None
self.tourNo = None
self.currency = None
self.buyin = None
self.fee = None
self.hero = None
self.maxseats = None
self.entries = 0