Merge branch 'master' of git://git.assembla.com/fpdb-eric
This commit is contained in:
commit
ac46c9a990
|
@ -42,6 +42,7 @@ import fpdb_simple
|
|||
import Configuration
|
||||
import SQL
|
||||
import Card
|
||||
import Tourney
|
||||
from Exceptions import *
|
||||
|
||||
import logging, logging.config
|
||||
|
@ -608,7 +609,7 @@ class Database:
|
|||
hands_players_ids = self.store_hands_players_holdem_omaha_tourney(
|
||||
self.backend, category, hands_id, player_ids, start_cashes, positions
|
||||
, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids
|
||||
, hudImportData)
|
||||
, hudImportData, tourneyTypeId)
|
||||
|
||||
#print "tourney holdem, backend=%d" % backend
|
||||
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
|
||||
|
@ -636,7 +637,7 @@ class Database:
|
|||
|
||||
hands_players_ids = self.store_hands_players_stud_tourney(self.backend, hands_id
|
||||
, playerIds, startCashes, antes, cardValues, cardSuits
|
||||
, winnings, rakes, seatNos, tourneys_players_ids)
|
||||
, winnings, rakes, seatNos, tourneys_players_ids, tourneyTypeId)
|
||||
|
||||
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
|
||||
self.storeHudCache(self.backend, base, category, gametypeId, hand_start_time, playerIds, hudImportData)
|
||||
|
@ -883,35 +884,51 @@ class Database:
|
|||
|
||||
def drop_tables(self):
|
||||
"""Drops the fpdb tables from the current db"""
|
||||
|
||||
try:
|
||||
c = self.get_cursor()
|
||||
if(self.get_backend_name() == 'MySQL InnoDB'):
|
||||
#Databases with FOREIGN KEY support need this switched of before you can drop tables
|
||||
self.drop_referential_integrity()
|
||||
|
||||
# Query the DB to see what tables exist
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
for table in c:
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
elif(self.get_backend_name() == 'PostgreSQL'):
|
||||
self.commit()# I have no idea why this makes the query work--REB 07OCT2008
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
tables = c.fetchall()
|
||||
for table in tables:
|
||||
c.execute(self.sql.query['drop_table'] + table[0] + ' cascade')
|
||||
elif(self.get_backend_name() == 'SQLite'):
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
for table in c.fetchall():
|
||||
log.debug(self.sql.query['drop_table'] + table[0])
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
|
||||
self.commit()
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
raise
|
||||
print "*** Error unable to get cursor"
|
||||
else:
|
||||
backend = self.get_backend_name()
|
||||
if backend == 'MySQL InnoDB': # what happens if someone is using MyISAM?
|
||||
try:
|
||||
self.drop_referential_integrity() # needed to drop tables with foreign keys
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
tables = c.fetchall()
|
||||
for table in tables:
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
elif backend == 'PostgreSQL':
|
||||
try:
|
||||
self.commit()
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
tables = c.fetchall()
|
||||
for table in tables:
|
||||
c.execute(self.sql.query['drop_table'] + table[0] + ' cascade')
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
elif backend == 'SQLite':
|
||||
try:
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
for table in c.fetchall():
|
||||
log.debug(self.sql.query['drop_table'] + table[0])
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
try:
|
||||
self.commit()
|
||||
except:
|
||||
print "*** Error in committing table drop"
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
#end def drop_tables
|
||||
|
||||
def createAllIndexes(self):
|
||||
|
@ -995,12 +1012,10 @@ class Database:
|
|||
c.execute("INSERT INTO Sites (name,currency) VALUES ('Absolute', 'USD')")
|
||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('PartyPoker', 'USD')")
|
||||
if self.backend == self.SQLITE:
|
||||
c.execute("INSERT INTO TourneyTypes VALUES (NULL, 1, 0, 0, 0, 0);")
|
||||
c.execute("INSERT INTO TourneyTypes (id, siteId, buyin, fee) VALUES (NULL, 1, 0, 0);")
|
||||
else:
|
||||
c.execute("INSERT INTO TourneyTypes VALUES (DEFAULT, 1, 0, 0, 0, False);")
|
||||
#c.execute("""INSERT INTO TourneyTypes
|
||||
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
||||
# (1,0,0,0,?)""",(False,) )
|
||||
c.execute("insert into tourneytypes values (0,1,0,0,0,0,0,null,0,0,0);")
|
||||
|
||||
#end def fillDefaultData
|
||||
|
||||
def rebuild_hudcache(self):
|
||||
|
@ -1314,7 +1329,7 @@ class Database:
|
|||
raise FpdbError("invalid category")
|
||||
|
||||
inserts.append( (
|
||||
hands_id, player_ids[i], start_cashes[i], positions[i], 1, # tourneytypeid
|
||||
hands_id, player_ids[i], start_cashes[i], positions[i],
|
||||
card1, card2, card3, card4, startCards,
|
||||
winnings[i], rakes[i], seatNos[i], hudCache['totalProfit'][i],
|
||||
hudCache['street0VPI'][i], hudCache['street0Aggr'][i],
|
||||
|
@ -1345,7 +1360,7 @@ class Database:
|
|||
c = self.get_cursor()
|
||||
c.executemany ("""
|
||||
INSERT INTO HandsPlayers
|
||||
(handId, playerId, startCash, position, tourneyTypeId,
|
||||
(handId, playerId, startCash, position,
|
||||
card1, card2, card3, card4, startCards, winnings, rake, seatNo, totalProfit,
|
||||
street0VPI, street0Aggr, street0_3BChance, street0_3BDone,
|
||||
street1Seen, street2Seen, street3Seen, street4Seen, sawShowdown,
|
||||
|
@ -1366,7 +1381,7 @@ class Database:
|
|||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""".replace('%s', self.sql.query['placeholder'])
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s)""".replace('%s', self.sql.query['placeholder'])
|
||||
,inserts )
|
||||
result.append( self.get_last_insert_id(c) ) # wrong? not used currently
|
||||
except:
|
||||
|
@ -1416,7 +1431,7 @@ class Database:
|
|||
def store_hands_players_holdem_omaha_tourney(self, backend, category, hands_id, player_ids
|
||||
,start_cashes, positions, card_values, card_suits
|
||||
,winnings, rakes, seatNos, tourneys_players_ids
|
||||
,hudCache):
|
||||
,hudCache, tourneyTypeId):
|
||||
#stores hands_players for tourney holdem/omaha hands
|
||||
|
||||
try:
|
||||
|
@ -1438,7 +1453,7 @@ class Database:
|
|||
else:
|
||||
raise FpdbError ("invalid card_values length:"+str(len(card_values[0])))
|
||||
|
||||
inserts.append( (hands_id, player_ids[i], start_cashes[i], positions[i], 1, # tourneytypeid
|
||||
inserts.append( (hands_id, player_ids[i], start_cashes[i], positions[i], tourneyTypeId,
|
||||
card1, card2, card3, card4, startCards,
|
||||
winnings[i], rakes[i], tourneys_players_ids[i], seatNos[i], hudCache['totalProfit'][i],
|
||||
hudCache['street0VPI'][i], hudCache['street0Aggr'][i],
|
||||
|
@ -1507,7 +1522,7 @@ class Database:
|
|||
#end def store_hands_players_holdem_omaha_tourney
|
||||
|
||||
def store_hands_players_stud_tourney(self, backend, hands_id, player_ids, start_cashes,
|
||||
antes, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids):
|
||||
antes, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids, tourneyTypeId):
|
||||
#stores hands_players for tourney stud/razz hands
|
||||
|
||||
try:
|
||||
|
@ -1519,14 +1534,14 @@ class Database:
|
|||
card1Value, card1Suit, card2Value, card2Suit,
|
||||
card3Value, card3Suit, card4Value, card4Suit,
|
||||
card5Value, card5Suit, card6Value, card6Suit,
|
||||
card7Value, card7Suit, winnings, rake, tourneysPlayersId, seatNo)
|
||||
card7Value, card7Suit, winnings, rake, tourneysPlayersId, seatNo, tourneyTypeId)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, %s, %s, %s, %s, %s)""".replace('%s', self.sql.query['placeholder']),
|
||||
%s, %s, %s, %s, %s, %s, %s)""".replace('%s', self.sql.query['placeholder']),
|
||||
(hands_id, player_ids[i], start_cashes[i], antes[i],
|
||||
card_values[i][0], card_suits[i][0], card_values[i][1], card_suits[i][1],
|
||||
card_values[i][2], card_suits[i][2], card_values[i][3], card_suits[i][3],
|
||||
card_values[i][4], card_suits[i][4], card_values[i][5], card_suits[i][5],
|
||||
card_values[i][6], card_suits[i][6], winnings[i], rakes[i], tourneys_players_ids[i], seatNos[i]))
|
||||
card_values[i][6], card_suits[i][6], winnings[i], rakes[i], tourneys_players_ids[i], seatNos[i], tourneyTypeId))
|
||||
#cursor.execute("SELECT id FROM HandsPlayers WHERE handId=%s AND playerId+0=%s", (hands_id, player_ids[i]))
|
||||
#result.append(cursor.fetchall()[0][0])
|
||||
result.append( self.get_last_insert_id(c) )
|
||||
|
@ -1865,6 +1880,236 @@ class Database:
|
|||
print "***Error sending finish: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
# end def send_finish_msg():
|
||||
|
||||
def tRecogniseTourneyType(self, tourney):
|
||||
logging.debug("Database.tRecogniseTourneyType")
|
||||
typeId = 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)
|
||||
)
|
||||
result=cursor.fetchone()
|
||||
|
||||
expectedValues = { 1 : "buyin", 2 : "fee", 4 : "isKO", 5 : "isRebuy", 6 : "speed",
|
||||
7 : "isHU", 8 : "isShootout", 9 : "isMatrix" }
|
||||
typeIdMatch = True
|
||||
|
||||
try:
|
||||
len(result)
|
||||
typeId = result[0]
|
||||
logging.debug("Tourney found in db with Tourney_Type_ID = %d" % typeId)
|
||||
for ev in expectedValues :
|
||||
if ( getattr( tourney, expectedValues.get(ev) ) <> result[ev] ):
|
||||
logging.debug("TypeId mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValues.get(ev), getattr( tourney, expectedValues.get(ev)), result[ev]) )
|
||||
typeIdMatch = False
|
||||
#break
|
||||
except:
|
||||
# Tourney not found : a TourneyTypeId has to be found or created for that specific tourney
|
||||
typeIdMatch = False
|
||||
|
||||
if typeIdMatch == False :
|
||||
# Check for an existing TTypeId that matches tourney info (buyin/fee, knockout, rebuy, speed, matrix, shootout)
|
||||
# if not found create it
|
||||
logging.debug("Searching for a TourneyTypeId matching TourneyType data")
|
||||
cursor.execute (self.sql.query['getTourneyTypeId'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.siteId, tourney.buyin, tourney.fee, tourney.isKO,
|
||||
tourney.isRebuy, tourney.speed, tourney.isHU, tourney.isShootout, tourney.isMatrix)
|
||||
)
|
||||
result=cursor.fetchone()
|
||||
|
||||
try:
|
||||
len(result)
|
||||
typeId = result[0]
|
||||
logging.debug("Existing Tourney Type Id found : %d" % typeId)
|
||||
except TypeError: #this means we need to create a new entry
|
||||
logging.debug("Tourney Type Id not found : create one")
|
||||
cursor.execute (self.sql.query['insertTourneyTypes'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.siteId, tourney.buyin, tourney.fee, tourney.isKO, tourney.isRebuy,
|
||||
tourney.speed, tourney.isHU, tourney.isShootout, tourney.isMatrix)
|
||||
)
|
||||
typeId = self.get_last_insert_id(cursor)
|
||||
|
||||
return typeId
|
||||
#end def tRecogniseTourneyType
|
||||
|
||||
|
||||
def tRecognizeTourney(self, tourney, dbTourneyTypeId):
|
||||
logging.debug("Database.tRecognizeTourney")
|
||||
tourneyID = 1
|
||||
# Check if tourney exists in db (based on tourney.siteId and tourney.tourNo)
|
||||
# If so retrieve all data to check for consistency
|
||||
cursor = self.get_cursor()
|
||||
cursor.execute (self.sql.query['getTourney'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.tourNo, tourney.siteId)
|
||||
)
|
||||
result=cursor.fetchone()
|
||||
|
||||
expectedValuesDecimal = { 2 : "entries", 3 : "prizepool", 6 : "buyInChips", 9 : "rebuyChips",
|
||||
10 : "addOnChips", 11 : "rebuyAmount", 12 : "addOnAmount", 13 : "totalRebuys",
|
||||
14 : "totalAddOns", 15 : "koBounty" }
|
||||
expectedValues = { 7 : "tourneyName", 16 : "tourneyComment" }
|
||||
|
||||
tourneyDataMatch = True
|
||||
tCommentTs = None
|
||||
starttime = None
|
||||
endtime = None
|
||||
|
||||
try:
|
||||
len(result)
|
||||
tourneyID = result[0]
|
||||
logging.debug("Tourney found in db with TourneyID = %d" % tourneyID)
|
||||
if result[1] <> dbTourneyTypeId:
|
||||
tourneyDataMatch = False
|
||||
logging.debug("Tourney has wrong type ID (expected : %s - found : %s)" % (dbTourneyTypeId, result[1]))
|
||||
if (tourney.starttime is None and result[4] is not None) or ( tourney.starttime is not None and fpdb_simple.parseHandStartTime("- %s" % tourney.starttime) <> result[4]) :
|
||||
tourneyDataMatch = False
|
||||
logging.debug("Tourney data mismatch : wrong starttime : Tourney=%s / db=%s" % (tourney.starttime, result[4]))
|
||||
if (tourney.endtime is None and result[5] is not None) or ( tourney.endtime is not None and fpdb_simple.parseHandStartTime("- %s" % tourney.endtime) <> result[5]) :
|
||||
tourneyDataMatch = False
|
||||
logging.debug("Tourney data mismatch : wrong endtime : Tourney=%s / db=%s" % (tourney.endtime, result[5]))
|
||||
|
||||
for ev in expectedValues :
|
||||
if ( getattr( tourney, expectedValues.get(ev) ) <> result[ev] ):
|
||||
logging.debug("Tourney data mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValues.get(ev), getattr( tourney, expectedValues.get(ev)), result[ev]) )
|
||||
tourneyDataMatch = False
|
||||
#break
|
||||
for evD in expectedValuesDecimal :
|
||||
if ( Decimal(getattr( tourney, expectedValuesDecimal.get(evD)) ) <> result[evD] ):
|
||||
logging.debug("Tourney data mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValuesDecimal.get(evD), getattr( tourney, expectedValuesDecimal.get(evD)), result[evD]) )
|
||||
tourneyDataMatch = False
|
||||
#break
|
||||
|
||||
# TO DO : Deal with matrix summary mutliple parsings
|
||||
|
||||
except:
|
||||
# Tourney not found : create
|
||||
logging.debug("Tourney is not found : create")
|
||||
if tourney.tourneyComment is not None :
|
||||
tCommentTs = datetime.today()
|
||||
if tourney.starttime is not None :
|
||||
starttime = fpdb_simple.parseHandStartTime("- %s" % tourney.starttime)
|
||||
if tourney.endtime is not None :
|
||||
endtime = fpdb_simple.parseHandStartTime("- %s" % tourney.endtime)
|
||||
# TODO : deal with matrix Id processed
|
||||
cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyTypeId, tourney.tourNo, tourney.entries, tourney.prizepool, starttime,
|
||||
endtime, tourney.buyInChips, tourney.tourneyName, 0, tourney.rebuyChips, tourney.addOnChips,
|
||||
tourney.rebuyAmount, tourney.addOnAmount, tourney.totalRebuys, tourney.totalAddOns, tourney.koBounty,
|
||||
tourney.tourneyComment, tCommentTs)
|
||||
)
|
||||
tourneyID = self.get_last_insert_id(cursor)
|
||||
|
||||
|
||||
# Deal with inconsistent tourney in db
|
||||
if tourneyDataMatch == False :
|
||||
# Update Tourney
|
||||
if result[16] <> tourney.tourneyComment :
|
||||
tCommentTs = datetime.today()
|
||||
if tourney.starttime is not None :
|
||||
starttime = fpdb_simple.parseHandStartTime("- %s" % tourney.starttime)
|
||||
if tourney.endtime is not None :
|
||||
endtime = fpdb_simple.parseHandStartTime("- %s" % tourney.endtime)
|
||||
|
||||
cursor.execute (self.sql.query['updateTourney'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyTypeId, tourney.entries, tourney.prizepool, starttime,
|
||||
endtime, tourney.buyInChips, tourney.tourneyName, 0, tourney.rebuyChips, tourney.addOnChips,
|
||||
tourney.rebuyAmount, tourney.addOnAmount, tourney.totalRebuys, tourney.totalAddOns, tourney.koBounty,
|
||||
tourney.tourneyComment, tCommentTs, tourneyID)
|
||||
)
|
||||
|
||||
return tourneyID
|
||||
#end def tRecognizeTourney
|
||||
|
||||
def tStoreTourneyPlayers(self, tourney, dbTourneyId):
|
||||
logging.debug("Database.tStoreTourneyPlayers")
|
||||
# First, get playerids for the players and specifically the one for hero :
|
||||
playersIds = fpdb_simple.recognisePlayerIDs(self, tourney.players, tourney.siteId)
|
||||
# hero may be None for matrix tourneys summaries
|
||||
# hero = [ tourney.hero ]
|
||||
# heroId = fpdb_simple.recognisePlayerIDs(self, hero , tourney.siteId)
|
||||
# logging.debug("hero Id = %s - playersId = %s" % (heroId , playersIds))
|
||||
|
||||
tourneyPlayersIds=[]
|
||||
try:
|
||||
cursor = self.get_cursor()
|
||||
|
||||
for i in xrange(len(playersIds)):
|
||||
cursor.execute(self.sql.query['getTourneysPlayers'].replace('%s', self.sql.query['placeholder'])
|
||||
,(dbTourneyId, playersIds[i]))
|
||||
result=cursor.fetchone()
|
||||
#print "tried SELECTing tourneys_players.id:",tmp
|
||||
|
||||
try:
|
||||
len(result)
|
||||
# checking data
|
||||
logging.debug("TourneysPlayers found : checking data")
|
||||
expectedValuesDecimal = { 1 : "payinAmounts", 2 : "finishPositions", 3 : "winnings", 4 : "countRebuys",
|
||||
5 : "countAddOns", 6 : "countKO" }
|
||||
|
||||
tourneyPlayersIds.append(result[0]);
|
||||
|
||||
tourneysPlayersDataMatch = True
|
||||
for evD in expectedValuesDecimal :
|
||||
if ( Decimal(getattr( tourney, expectedValuesDecimal.get(evD))[tourney.players[i]] ) <> result[evD] ):
|
||||
logging.debug("TourneysPlayers data mismatch for TourneysPlayer id=%d, name=%s : wrong %s : Tourney=%s / db=%s" % (result[0], tourney.players[i], expectedValuesDecimal.get(evD), getattr( tourney, expectedValuesDecimal.get(evD))[tourney.players[i]], result[evD]) )
|
||||
tourneysPlayersDataMatch = False
|
||||
#break
|
||||
|
||||
if tourneysPlayersDataMatch == False:
|
||||
logging.debug("TourneysPlayers data update needed")
|
||||
cursor.execute (self.sql.query['updateTourneysPlayers'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.payinAmounts[tourney.players[i]], tourney.finishPositions[tourney.players[i]],
|
||||
tourney.winnings[tourney.players[i]] , tourney.countRebuys[tourney.players[i]],
|
||||
tourney.countAddOns[tourney.players[i]] , tourney.countKO[tourney.players[i]],
|
||||
result[7], result[8], result[0])
|
||||
)
|
||||
|
||||
except TypeError:
|
||||
logging.debug("TourneysPlayers not found : need insert")
|
||||
cursor.execute (self.sql.query['insertTourneysPlayers'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyId, playersIds[i],
|
||||
tourney.payinAmounts[tourney.players[i]], tourney.finishPositions[tourney.players[i]],
|
||||
tourney.winnings[tourney.players[i]] , tourney.countRebuys[tourney.players[i]],
|
||||
tourney.countAddOns[tourney.players[i]] , tourney.countKO[tourney.players[i]],
|
||||
None, None)
|
||||
)
|
||||
tourneyPlayersIds.append(self.get_last_insert_id(cursor))
|
||||
|
||||
except:
|
||||
raise fpdb_simple.FpdbError( "tStoreTourneyPlayers error: " + str(sys.exc_value) )
|
||||
|
||||
return tourneyPlayersIds
|
||||
#end def tStoreTourneyPlayers
|
||||
|
||||
def tUpdateTourneysHandsPlayers(self, tourney, dbTourneysPlayersIds, dbTourneyTypeId):
|
||||
logging.debug("Database.tCheckTourneysHandsPlayers")
|
||||
try:
|
||||
# Massive update seems to take quite some time ...
|
||||
# query = self.sql.query['updateHandsPlayersForTTypeId2'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner'].join([self.sql.query['placeholder'] for id in dbTourneysPlayersIds]) )
|
||||
# cursor = self.get_cursor()
|
||||
# cursor.execute (query, dbTourneysPlayersIds)
|
||||
|
||||
query = self.sql.query['selectHandsPlayersWithWrongTTypeId'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner'].join([self.sql.query['placeholder'] for id in dbTourneysPlayersIds]) )
|
||||
#print "query : %s" % query
|
||||
cursor = self.get_cursor()
|
||||
cursor.execute (query, dbTourneysPlayersIds)
|
||||
result=cursor.fetchall()
|
||||
|
||||
if (len(result) > 0):
|
||||
logging.debug("%d lines need update : %s" % (len(result), result) )
|
||||
listIds = []
|
||||
for i in result:
|
||||
listIds.append(i[0])
|
||||
|
||||
query2 = self.sql.query['updateHandsPlayersForTTypeId'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner_id'].join([self.sql.query['placeholder'] for id in listIds]) )
|
||||
cursor.execute (query2, listIds)
|
||||
else:
|
||||
logging.debug("No need to update, HandsPlayers are correct")
|
||||
|
||||
except:
|
||||
raise fpdb_simple.FpdbError( "tStoreTourneyPlayers error: " + str(sys.exc_value) )
|
||||
#end def tUpdateTourneysHandsPlayers
|
||||
|
||||
|
||||
# Class used to hold all the data needed to write a hand to the db
|
||||
# mainParser() in fpdb_parse_logic.py creates one of these and then passes it to
|
||||
|
|
|
@ -14,5 +14,8 @@ class FpdbParseError(FpdbError):
|
|||
else:
|
||||
return repr(self.value)
|
||||
|
||||
class FpdbDatabaseError(FpdbError):
|
||||
pass
|
||||
|
||||
class DuplicateError(FpdbError):
|
||||
pass
|
||||
|
|
|
@ -57,6 +57,13 @@ class Fulltilt(HandHistoryConverter):
|
|||
(?P<PARTIAL>\(partial\))?\n
|
||||
(?:.*?\n(?P<CANCELLED>Hand\s\#(?P=HID)\shas\sbeen\scanceled))?
|
||||
''', re.VERBOSE|re.DOTALL)
|
||||
re_TourneyExtraInfo = re.compile('''(((?P<TOURNEY_NAME>[^$]+)?
|
||||
(?P<CURRENCY>\$)?(?P<BUYIN>[.0-9]+)?\s*\+\s*\$?(?P<FEE>[.0-9]+)?
|
||||
(\s(?P<SPECIAL>(KO|Heads\sUp|Matrix\s\dx|Rebuy|Madness)))?
|
||||
(\s(?P<SHOOTOUT>Shootout))?
|
||||
(\s(?P<SNG>Sit\s&\sGo))?
|
||||
(\s\((?P<TURBO>Turbo)\))?)|(?P<UNREADABLE_INFO>.+))
|
||||
''', re.VERBOSE)
|
||||
re_Button = re.compile('^The button is in seat #(?P<BUTTON>\d+)', re.MULTILINE)
|
||||
re_PlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$(?P<CASH>[,.0-9]+)\)$', re.MULTILINE)
|
||||
re_TourneyPlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$?(?P<CASH>[,.0-9]+)\)', re.MULTILINE)
|
||||
|
@ -66,7 +73,7 @@ class Fulltilt(HandHistoryConverter):
|
|||
re_TourneyInfo = re.compile('''Tournament\sSummary\s
|
||||
(?P<TOURNAMENT_NAME>[^$(]+)?\s*
|
||||
((?P<CURRENCY>\$|)?(?P<BUYIN>[.0-9]+)\s*\+\s*\$?(?P<FEE>[.0-9]+)\s)?
|
||||
((?P<SPECIAL>(KO|Heads\sUp|Matrix\s\dx|Rebuy))\s)?
|
||||
((?P<SPECIAL>(KO|Heads\sUp|Matrix\s\dx|Rebuy|Madness))\s)?
|
||||
((?P<SHOOTOUT>Shootout)\s)?
|
||||
((?P<SNG>Sit\s&\sGo)\s)?
|
||||
(\((?P<TURBO1>Turbo)\)\s)?
|
||||
|
@ -202,16 +209,30 @@ class Fulltilt(HandHistoryConverter):
|
|||
if m.group('PLAY') != None:
|
||||
hand.gametype['currency'] = 'play'
|
||||
|
||||
# TODO: if there's a way to figure these out, we should.. otherwise we have to stuff it with unknowns
|
||||
re_SNGBuyInFee = re.compile('''(?P<CURRENCY>\$)?(?P<BUYIN>[.0-9]+) \+ \$?(?P<FEE>[.0-9]+) (?P<EXTRA_INFO>[\sA-Za-z&()]+)?''')
|
||||
# TO DO : See if important info can be retrieved from EXTRA_INFO (sould be things like Turbo, Matrix, KO, ...)
|
||||
try:
|
||||
n = re_SNGBuyInFee.search(m.group('TOURNAMENT'))
|
||||
#print "cur %s BUYIN %s FEE %s EXTRA %s" %(n.group('CURRENCY'), n.group('BUYIN'), n.group('FEE'), n.group('EXTRA_INFO'))
|
||||
hand.buyin = "%s%s+%s%s" %(n.group('CURRENCY'), n.group('BUYIN'), n.group('CURRENCY'), n.group('FEE'))
|
||||
except:
|
||||
#print "Unable to collect BuyIn/Fee Info"
|
||||
logging.info("Unable to collect BuyIn/Fee Info from HandInfo")
|
||||
# Done: if there's a way to figure these out, we should.. otherwise we have to stuff it with unknowns
|
||||
if m.group('TOURNAMENT') is not None:
|
||||
n = self.re_TourneyExtraInfo.search(m.group('TOURNAMENT'))
|
||||
if n.group('UNREADABLE_INFO') is not None:
|
||||
hand.tourneyComment = n.group('UNREADABLE_INFO')
|
||||
else:
|
||||
hand.tourneyComment = n.group('TOURNEY_NAME') # can be None
|
||||
if (n.group('CURRENCY') is not None and n.group('BUYIN') is not None and n.group('FEE') is not None):
|
||||
hand.buyin = "%s%s+%s%s" %(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 :
|
||||
special = n.group('SPECIAL')
|
||||
if special == "Rebuy":
|
||||
hand.isRebuy = True
|
||||
if special == "KO":
|
||||
hand.isKO = True
|
||||
if special == "Head's Up":
|
||||
hand.isHU = True
|
||||
if re.search("Matrix", special):
|
||||
hand.isMatrix = True
|
||||
if special == "Shootout":
|
||||
hand.isShootout = True
|
||||
|
||||
|
||||
if hand.buyin == None:
|
||||
hand.buyin = "$0.00+$0.00"
|
||||
|
@ -405,9 +426,9 @@ class Fulltilt(HandHistoryConverter):
|
|||
self.status = False
|
||||
else:
|
||||
self.tourney = Tourney.Tourney(sitename = self.sitename, gametype = None, summaryText = summaryInfoList, builtFrom = "HHC")
|
||||
self.status = self.determineTourneyType(self.tourney)
|
||||
self.status = self.getPlayersPositionsAndWinnings(self.tourney)
|
||||
if self.status == True :
|
||||
self.status = status = self.getPlayersPositionsAndWinnings(self.tourney)
|
||||
self.status = self.determineTourneyType(self.tourney)
|
||||
#print self.tourney
|
||||
else:
|
||||
log.info("Parsing NOK : rejected")
|
||||
|
@ -454,10 +475,10 @@ class Fulltilt(HandHistoryConverter):
|
|||
|
||||
# Additional info can be stored in the tourney object
|
||||
if mg['BUYIN'] is not None:
|
||||
tourney.buyin = mg['BUYIN']
|
||||
tourney.buyin = 100*Decimal(re.sub(u',', u'', "%s" % mg['BUYIN']))
|
||||
tourney.fee = 0
|
||||
if mg['FEE'] is not None:
|
||||
tourney.fee = mg['FEE']
|
||||
tourney.fee = 100*Decimal(re.sub(u',', u'', "%s" % mg['FEE']))
|
||||
if mg['TOURNAMENT_NAME'] is not None:
|
||||
# Tournament Name can have a trailing space at the end (depending on the tournament description)
|
||||
tourney.tourneyName = mg['TOURNAMENT_NAME'].rstrip()
|
||||
|
@ -472,6 +493,8 @@ class Fulltilt(HandHistoryConverter):
|
|||
tourney.isMatrix = True
|
||||
if special == "Rebuy":
|
||||
tourney.isRebuy = True
|
||||
if special == "Madness":
|
||||
tourney.tourneyComment = "Madness"
|
||||
if mg['SHOOTOUT'] is not None:
|
||||
tourney.isShootout = True
|
||||
if mg['TURBO1'] is not None or mg['TURBO2'] is not None :
|
||||
|
@ -500,25 +523,25 @@ class Fulltilt(HandHistoryConverter):
|
|||
mg = m.groupdict()
|
||||
if tourney.isMatrix :
|
||||
if mg['BUYIN'] is not None:
|
||||
tourney.subTourneyBuyin = mg['BUYIN']
|
||||
tourney.subTourneyBuyin = 100*Decimal(re.sub(u',', u'', "%s" % mg['BUYIN']))
|
||||
tourney.subTourneyFee = 0
|
||||
if mg['FEE'] is not None:
|
||||
tourney.subTourneyFee = mg['FEE']
|
||||
tourney.subTourneyFee = 100*Decimal(re.sub(u',', u'', "%s" % mg['FEE']))
|
||||
else :
|
||||
if mg['BUYIN'] is not None:
|
||||
if tourney.buyin is None:
|
||||
tourney.buyin = mg['BUYIN']
|
||||
tourney.buyin = 100*Decimal(re.sub(u',', u'', "%s" % mg['BUYIN']))
|
||||
else :
|
||||
if mg['BUYIN'] != tourney.buyin:
|
||||
log.error( "Conflict between buyins read in topline (%s) and in BuyIn field (%s)" % (touney.buyin, mg['BUYIN']) )
|
||||
tourney.subTourneyBuyin = mg['BUYIN']
|
||||
if 100*Decimal(re.sub(u',', u'', "%s" % mg['BUYIN'])) != tourney.buyin:
|
||||
log.error( "Conflict between buyins read in topline (%s) and in BuyIn field (%s)" % (touney.buyin, 100*Decimal(re.sub(u',', u'', "%s" % mg['BUYIN']))) )
|
||||
tourney.subTourneyBuyin = 100*Decimal(re.sub(u',', u'', "%s" % mg['BUYIN']))
|
||||
if mg['FEE'] is not None:
|
||||
if tourney.fee is None:
|
||||
tourney.fee = mg['FEE']
|
||||
tourney.fee = 100*Decimal(re.sub(u',', u'', "%s" % mg['FEE']))
|
||||
else :
|
||||
if mg['FEE'] != tourney.fee:
|
||||
log.error( "Conflict between fees read in topline (%s) and in BuyIn field (%s)" % (touney.fee, mg['FEE']) )
|
||||
tourney.subTourneyFee = mg['FEE']
|
||||
if 100*Decimal(re.sub(u',', u'', "%s" % mg['FEE'])) != tourney.fee:
|
||||
log.error( "Conflict between fees read in topline (%s) and in BuyIn field (%s)" % (touney.fee, 100*Decimal(re.sub(u',', u'', "%s" % mg['FEE']))) )
|
||||
tourney.subTourneyFee = 100*Decimal(re.sub(u',', u'', "%s" % mg['FEE']))
|
||||
|
||||
if tourney.buyin is None:
|
||||
log.info( "Unable to affect a buyin to this tournament : assume it's a freeroll" )
|
||||
|
@ -535,15 +558,12 @@ class Fulltilt(HandHistoryConverter):
|
|||
"PRIZEPOOL" : self.re_TourneyPrizePool,
|
||||
"REBUY_AMOUNT" : self.re_TourneyRebuyAmount,
|
||||
"ADDON_AMOUNT" : self.re_TourneyAddOnAmount,
|
||||
"REBUY_COUNT" : self.re_TourneyRebuyCount,
|
||||
"ADDON_COUNT" : self.re_TourneyAddOnCount,
|
||||
"REBUY_TOTAL" : self.re_TourneyRebuysTotal,
|
||||
"ADDONS_TOTAL" : self.re_TourneyAddOnsTotal,
|
||||
"REBUY_CHIPS" : self.re_TourneyRebuyChips,
|
||||
"ADDON_CHIPS" : self.re_TourneyAddOnChips,
|
||||
"STARTTIME" : self.re_TourneyTimeInfo,
|
||||
"KO_BOUNTY_AMOUNT" : self.re_TourneyKOBounty,
|
||||
"COUNT_KO" : self.re_TourneyCountKO
|
||||
}
|
||||
|
||||
|
||||
|
@ -552,15 +572,12 @@ class Fulltilt(HandHistoryConverter):
|
|||
"PRIZEPOOL" : "prizepool",
|
||||
"REBUY_AMOUNT" : "rebuyAmount",
|
||||
"ADDON_AMOUNT" : "addOnAmount",
|
||||
"REBUY_COUNT" : "countRebuys",
|
||||
"ADDON_COUNT" : "countAddOns",
|
||||
"REBUY_TOTAL" : "totalRebuys",
|
||||
"ADDONS_TOTAL" : "totalAddOns",
|
||||
"REBUY_CHIPS" : "rebuyChips",
|
||||
"ADDON_CHIPS" : "addOnChips",
|
||||
"STARTTIME" : "starttime",
|
||||
"KO_BOUNTY_AMOUNT" : "koBounty",
|
||||
"COUNT_KO" : "countKO"
|
||||
"KO_BOUNTY_AMOUNT" : "koBounty"
|
||||
}
|
||||
|
||||
mg = {} # After the loop, mg will contain all the matching groups, including the ones that have not been used, like ENDTIME and IN-PROGRESS
|
||||
|
@ -573,8 +590,43 @@ class Fulltilt(HandHistoryConverter):
|
|||
if mg['IN_PROGRESS'] is not None or mg['ENDTIME'] is not None:
|
||||
# Assign endtime to tourney (if None, that's ok, it's because the tourney wans't over over when the summary file was produced)
|
||||
tourney.endtime = mg['ENDTIME']
|
||||
#print mg
|
||||
|
||||
# Deal with hero specific information
|
||||
if tourney.hero is not None :
|
||||
m = self.re_TourneyRebuyCount.search(tourneyText)
|
||||
if m is not None:
|
||||
mg = m.groupdict()
|
||||
if mg['REBUY_COUNT'] is not None :
|
||||
tourney.countRebuys.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)
|
||||
if m is not None:
|
||||
mg = m.groupdict()
|
||||
if mg['COUNT_KO'] is not None :
|
||||
tourney.countKO.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))
|
||||
|
||||
# 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])
|
||||
#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])
|
||||
#print "player %s : winnings %d" % (p, tourney.winnings[p])
|
||||
|
||||
|
||||
|
||||
#print mg
|
||||
return True
|
||||
|
||||
def getPlayersPositionsAndWinnings(self, tourney):
|
||||
|
@ -590,15 +642,15 @@ class Fulltilt(HandHistoryConverter):
|
|||
rank = Decimal(a.group('RANK'))
|
||||
|
||||
if a.group('WINNING') is not None:
|
||||
winnings = a.group('WINNING')
|
||||
winnings = 100*Decimal(re.sub(u',', u'', "%s" % a.group('WINNING')))
|
||||
else:
|
||||
winnings = "0"
|
||||
|
||||
tourney.addPlayer(rank, a.group('PNAME'), winnings)
|
||||
tourney.addPlayer(rank, a.group('PNAME'), winnings, 0, 0, 0, 0)
|
||||
else:
|
||||
print "Player finishing stats unreadable : %s" % a
|
||||
|
||||
# Deal with KO tournaments for hero winnings calculation
|
||||
# Find Hero
|
||||
n = self.re_TourneyHeroFinishingP.search(playersText)
|
||||
if n is not None:
|
||||
heroName = n.group('HERO_NAME')
|
||||
|
@ -606,9 +658,6 @@ class Fulltilt(HandHistoryConverter):
|
|||
# Is this really useful ?
|
||||
if (tourney.finishPositions[heroName] != Decimal(n.group('HERO_FINISHING_POS'))):
|
||||
print "Bad parsing : finish position incoherent : %s / %s" % (tourney.finishPositions[heroName], n.group('HERO_FINISHING_POS'))
|
||||
if tourney.isKO:
|
||||
#Update the winnings with the (KO amount) * (# of KO)
|
||||
tourney.incrementPlayerWinnings(n.group('HERO_NAME'), Decimal(tourney.koBounty)*Decimal(tourney.countKO))
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -21,7 +21,11 @@ pygtk.require('2.0')
|
|||
import gtk
|
||||
import os
|
||||
from time import time, strftime, localtime
|
||||
from numpy import diff, nonzero
|
||||
try:
|
||||
from numpy import diff, nonzero
|
||||
except:
|
||||
print """Failed to load numpy in Session Viewer"""
|
||||
print """This is of no consequence as the module currently doesn't do anything."""
|
||||
|
||||
import Card
|
||||
import fpdb_import
|
||||
|
|
|
@ -195,7 +195,7 @@ class HUD_main(object):
|
|||
temp_key = tour_number
|
||||
else: # tourney, but can't get number and table
|
||||
print "could not find tournament: skipping "
|
||||
sys.stderr.write("Could not find tournament %d in hand %d. Skipping.\n" % (int(tour_number), int(new_hand_id)))
|
||||
#sys.stderr.write("Could not find tournament %d in hand %d. Skipping.\n" % (int(tour_number), int(new_hand_id)))
|
||||
continue
|
||||
|
||||
else:
|
||||
|
|
|
@ -64,6 +64,15 @@ class Hand(object):
|
|||
self.fee = None # the Database code is looking for this one .. ?
|
||||
self.level = None
|
||||
self.mixed = None
|
||||
# Some attributes for hand from a tourney
|
||||
self.speed = "Normal"
|
||||
self.isRebuy = False
|
||||
self.isKO = False
|
||||
self.isHU = False
|
||||
self.isMatrix = False
|
||||
self.isShootout = False
|
||||
self.tourneyComment = None
|
||||
|
||||
self.seating = []
|
||||
self.players = []
|
||||
self.posted = []
|
||||
|
@ -472,7 +481,6 @@ Add a raise on [street] by [player] to [amountTo]
|
|||
For when a player shows cards for any reason (for showdown or out of choice).
|
||||
Card ranks will be uppercased
|
||||
"""
|
||||
import sys; sys.exit(1)
|
||||
log.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard))
|
||||
if cards is not None:
|
||||
self.addHoleCards(cards,player,shown, mucked)
|
||||
|
|
|
@ -139,7 +139,8 @@ Otherwise, finish at EOF.
|
|||
handsList = self.allHandsAsList()
|
||||
log.info("Parsing %d hands" % len(handsList))
|
||||
# Determine if we're dealing with a HH file or a Summary file
|
||||
if self.isSummary(handsList[0]) == False:
|
||||
# quick fix : empty files make the handsList[0] fail ==> If empty file, go on with HH parsing
|
||||
if len(handsList) == 0 or self.isSummary(handsList[0]) == False:
|
||||
self.parsedObjectType = "HH"
|
||||
for handText in handsList:
|
||||
try:
|
||||
|
|
202
pyfpdb/Hud.py
202
pyfpdb/Hud.py
|
@ -81,6 +81,10 @@ class Hud:
|
|||
(font, font_size) = config.get_default_font(self.table.site)
|
||||
self.colors = config.get_default_colors(self.table.site)
|
||||
|
||||
self.backgroundcolor = gtk.gdk.color_parse(self.colors['hudbgcolor'])
|
||||
self.foregroundcolor = gtk.gdk.color_parse(self.colors['hudfgcolor'])
|
||||
|
||||
|
||||
if font == None:
|
||||
font = "Sans"
|
||||
if font_size == None:
|
||||
|
@ -102,84 +106,66 @@ class Hud:
|
|||
def create_mw(self):
|
||||
|
||||
# Set up a main window for this this instance of the HUD
|
||||
self.main_window = gtk.Window()
|
||||
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
|
||||
self.main_window.set_title("%s FPDBHUD" % (self.table.name))
|
||||
self.main_window.set_decorated(False)
|
||||
self.main_window.set_opacity(self.colors["hudopacity"])
|
||||
self.main_window.set_focus_on_map(False)
|
||||
win = gtk.Window()
|
||||
win.set_gravity(gtk.gdk.GRAVITY_STATIC)
|
||||
win.set_title("%s FPDBHUD" % (self.table.name))
|
||||
win.set_skip_taskbar_hint(True)
|
||||
win.set_decorated(False)
|
||||
win.set_opacity(self.colors["hudopacity"])
|
||||
|
||||
self.ebox = gtk.EventBox()
|
||||
self.label = gtk.Label("FPDB Menu (Right Click)\nLeft-drag to move")
|
||||
eventbox = gtk.EventBox()
|
||||
label = gtk.Label("FPDB Menu - Right click\nLeft-Drag to Move")
|
||||
|
||||
self.backgroundcolor = gtk.gdk.color_parse(self.colors['hudbgcolor'])
|
||||
self.foregroundcolor = gtk.gdk.color_parse(self.colors['hudfgcolor'])
|
||||
win.add(eventbox)
|
||||
eventbox.add(label)
|
||||
|
||||
self.label.modify_bg(gtk.STATE_NORMAL, self.backgroundcolor)
|
||||
self.label.modify_fg(gtk.STATE_NORMAL, self.foregroundcolor)
|
||||
label.modify_bg(gtk.STATE_NORMAL, self.backgroundcolor)
|
||||
label.modify_fg(gtk.STATE_NORMAL, self.foregroundcolor)
|
||||
|
||||
self.main_window.add(self.ebox)
|
||||
self.ebox.add(self.label)
|
||||
|
||||
self.ebox.modify_bg(gtk.STATE_NORMAL, self.backgroundcolor)
|
||||
self.ebox.modify_fg(gtk.STATE_NORMAL, self.foregroundcolor)
|
||||
eventbox.modify_bg(gtk.STATE_NORMAL, self.backgroundcolor)
|
||||
eventbox.modify_fg(gtk.STATE_NORMAL, self.foregroundcolor)
|
||||
|
||||
self.main_window = win
|
||||
self.main_window.move(self.table.x, self.table.y)
|
||||
|
||||
# A popup menu for the main window
|
||||
self.menu = gtk.Menu()
|
||||
self.item1 = gtk.MenuItem('Kill this HUD')
|
||||
self.menu.append(self.item1)
|
||||
menu = gtk.Menu()
|
||||
|
||||
killitem = gtk.MenuItem('Kill This HUD')
|
||||
menu.append(killitem)
|
||||
if self.parent != None:
|
||||
self.item1.connect("activate", self.parent.kill_hud, self.table_name)
|
||||
self.item1.show()
|
||||
killitem.connect("activate", self.parent.kill_hud, self.table_name)
|
||||
|
||||
self.item2 = gtk.MenuItem('Save Layout')
|
||||
self.menu.append(self.item2)
|
||||
self.item2.connect("activate", self.save_layout)
|
||||
self.item2.show()
|
||||
saveitem = gtk.MenuItem('Save HUD Layout')
|
||||
menu.append(saveitem)
|
||||
saveitem.connect("activate", self.save_layout)
|
||||
|
||||
self.item3 = gtk.MenuItem('Reposition Stats')
|
||||
self.menu.append(self.item3)
|
||||
self.item3.connect("activate", self.reposition_windows)
|
||||
self.item3.show()
|
||||
repositem = gtk.MenuItem('Reposition StatWindows')
|
||||
menu.append(repositem)
|
||||
repositem.connect("activate", self.reposition_windows)
|
||||
|
||||
self.item4 = gtk.MenuItem('Debug Stat Windows')
|
||||
self.menu.append(self.item4)
|
||||
self.item4.connect("activate", self.debug_stat_windows)
|
||||
self.item4.show()
|
||||
debugitem = gtk.MenuItem('Debug StatWindows')
|
||||
menu.append(debugitem)
|
||||
debugitem.connect("activate", self.debug_stat_windows)
|
||||
|
||||
self.item5 = gtk.MenuItem('Set max seats')
|
||||
self.menu.append(self.item5)
|
||||
self.item5.show()
|
||||
self.maxSeatsMenu = gtk.Menu()
|
||||
self.item5.set_submenu(self.maxSeatsMenu)
|
||||
item5 = gtk.MenuItem('Set max seats')
|
||||
menu.append(item5)
|
||||
maxSeatsMenu = gtk.Menu()
|
||||
item5.set_submenu(maxSeatsMenu)
|
||||
for i in range(2, 11, 1):
|
||||
item = gtk.MenuItem('%d-max' % i)
|
||||
item.ms = i
|
||||
self.maxSeatsMenu.append(item)
|
||||
maxSeatsMenu.append(item)
|
||||
item.connect("activate", self.change_max_seats)
|
||||
item.show()
|
||||
setattr(self, 'maxSeatsMenuItem%d' % (i-1), item)
|
||||
|
||||
eventbox.connect_object("button-press-event", self.on_button_press, menu)
|
||||
|
||||
|
||||
self.ebox.connect_object("button-press-event", self.on_button_press, self.menu)
|
||||
|
||||
self.main_window.show_all()
|
||||
self.mw_created = True
|
||||
|
||||
# TODO: fold all uses of this type of 'topify' code into a single function, if the differences between the versions don't
|
||||
# create adverse effects?
|
||||
|
||||
if os.name == 'nt':
|
||||
self.topify_window(self.main_window)
|
||||
else:
|
||||
self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gets a gdk handle for poker client
|
||||
self.main_window.gdkhandle = gtk.gdk.window_foreign_new(self.main_window.window.xid) # gets a gdk handle for the hud table window
|
||||
self.main_window.gdkhandle.set_transient_for(self.main_window.parentgdkhandle) #
|
||||
|
||||
self.update_table_position()
|
||||
self.label = label
|
||||
menu.show_all()
|
||||
self.main_window.show_all()
|
||||
self.topify_window(self.main_window)
|
||||
|
||||
def change_max_seats(self, widget):
|
||||
if self.max != widget.ms:
|
||||
|
@ -199,18 +185,18 @@ class Hud:
|
|||
self.parent.kill_hud(self, self.table.name)
|
||||
return False
|
||||
# anyone know how to do this in unix, or better yet, trap the X11 error that is triggered when executing the get_origin() for a closed window?
|
||||
|
||||
(x, y) = self.main_window.parentgdkhandle.get_origin()
|
||||
if self.table.x != x or self.table.y != y:
|
||||
self.table.x = x
|
||||
self.table.y = y
|
||||
self.main_window.move(x, y)
|
||||
adj = self.adj_seats(self.hand, self.config)
|
||||
loc = self.config.get_locations(self.table.site, self.max)
|
||||
# TODO: is stat_windows getting converted somewhere from a list to a dict, for no good reason?
|
||||
for i, w in enumerate(self.stat_windows.itervalues()):
|
||||
(x, y) = loc[adj[i+1]]
|
||||
w.relocate(x, y)
|
||||
if self.table.gdkhandle is not None:
|
||||
(x, y) = self.table.gdkhandle.get_origin()
|
||||
if self.table.x != x or self.table.y != y:
|
||||
self.table.x = x
|
||||
self.table.y = y
|
||||
self.main_window.move(x, y)
|
||||
adj = self.adj_seats(self.hand, self.config)
|
||||
loc = self.config.get_locations(self.table.site, self.max)
|
||||
# TODO: is stat_windows getting converted somewhere from a list to a dict, for no good reason?
|
||||
for i, w in enumerate(self.stat_windows.itervalues()):
|
||||
(x, y) = loc[adj[i+1]]
|
||||
w.relocate(x, y)
|
||||
|
||||
# While we're at it, fix the positions of mucked cards too
|
||||
for aux in self.aux_windows:
|
||||
|
@ -374,30 +360,12 @@ class Hud:
|
|||
Stats.do_tip(window.e_box[r][c], tip)
|
||||
|
||||
def topify_window(self, window):
|
||||
# """Set the specified gtk window to stayontop in MS Windows."""
|
||||
#
|
||||
# def windowEnumerationHandler(hwnd, resultList):
|
||||
# '''Callback for win32gui.EnumWindows() to generate list of window handles.'''
|
||||
# resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
|
||||
# unique_name = 'unique name for finding this window'
|
||||
# real_name = window.get_title()
|
||||
# window.set_title(unique_name)
|
||||
# tl_windows = []
|
||||
# win32gui.EnumWindows(windowEnumerationHandler, tl_windows)
|
||||
#
|
||||
# for w in tl_windows:
|
||||
# if w[1] == unique_name:
|
||||
self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(long(self.table.number))
|
||||
# self.main_window.gdkhandle = gtk.gdk.window_foreign_new(w[0])
|
||||
self.main_window.gdkhandle = self.main_window.window
|
||||
self.main_window.gdkhandle.set_transient_for(self.main_window.parentgdkhandle)
|
||||
window.set_focus_on_map(False)
|
||||
window.set_accept_focus(False)
|
||||
|
||||
style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE)
|
||||
style |= win32con.WS_CLIPCHILDREN
|
||||
win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style)
|
||||
# break
|
||||
|
||||
# window.set_title(real_name)
|
||||
if not self.table.gdkhandle:
|
||||
self.table.gdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gtk handle to poker window
|
||||
window.window.set_transient_for(self.table.gdkhandle)
|
||||
|
||||
class Stat_Window:
|
||||
|
||||
|
@ -419,6 +387,7 @@ class Stat_Window:
|
|||
|
||||
if event.button == 1: # left button event
|
||||
# TODO: make position saving save sizes as well?
|
||||
self.window.show_all()
|
||||
if event.state & gtk.gdk.SHIFT_MASK:
|
||||
self.window.begin_resize_drag(gtk.gdk.WINDOW_EDGE_SOUTH_EAST, event.button, int(event.x_root), int(event.y_root), event.time)
|
||||
else:
|
||||
|
@ -462,7 +431,6 @@ class Stat_Window:
|
|||
|
||||
self.window.set_title("%s" % seat)
|
||||
self.window.set_property("skip-taskbar-hint", True)
|
||||
self.window.set_transient_for(parent.main_window)
|
||||
self.window.set_focus_on_map(False)
|
||||
|
||||
grid = gtk.Table(rows = game.rows, columns = game.cols, homogeneous = False)
|
||||
|
@ -514,11 +482,26 @@ class Stat_Window:
|
|||
self.window.connect("focus-in-event", self.noop)
|
||||
self.window.connect("focus-out-event", self.noop)
|
||||
self.window.connect("button_press_event", self.button_press_cb)
|
||||
self.window.set_focus_on_map(False)
|
||||
self.window.set_accept_focus(False)
|
||||
|
||||
|
||||
self.window.move(self.x, self.y)
|
||||
self.window.realize() # window must be realized before it has a gdkwindow so we can attach it to the table window..
|
||||
self.topify_window(self.window)
|
||||
|
||||
self.window.hide()
|
||||
|
||||
def topify_window(self, window):
|
||||
window.set_focus_on_map(False)
|
||||
window.set_accept_focus(False)
|
||||
|
||||
if not self.table.gdkhandle:
|
||||
self.table.gdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gtk handle to poker window
|
||||
# window.window.reparent(self.table.gdkhandle, 0, 0)
|
||||
window.window.set_transient_for(self.table.gdkhandle)
|
||||
# window.present()
|
||||
|
||||
def destroy(*args): # call back for terminating the main eventloop
|
||||
gtk.main_quit()
|
||||
|
||||
|
@ -534,6 +517,8 @@ class Popup_window:
|
|||
self.window.set_gravity(gtk.gdk.GRAVITY_STATIC)
|
||||
self.window.set_title("popup")
|
||||
self.window.set_property("skip-taskbar-hint", True)
|
||||
self.window.set_focus_on_map(False)
|
||||
self.window.set_accept_focus(False)
|
||||
self.window.set_transient_for(parent.get_toplevel())
|
||||
|
||||
self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
||||
|
@ -599,9 +584,6 @@ class Popup_window:
|
|||
|
||||
self.window.set_transient_for(stat_window.window)
|
||||
|
||||
# if os.name == 'nt':
|
||||
# self.topify_window(self.window)
|
||||
|
||||
def button_press_cb(self, widget, event, *args):
|
||||
# This handles all callbacks from button presses on the event boxes in
|
||||
# the popup windows. There is a bit of an ugly kludge to separate single-
|
||||
|
@ -630,27 +612,15 @@ class Popup_window:
|
|||
top.move(x, y)
|
||||
|
||||
def topify_window(self, window):
|
||||
"""Set the specified gtk window to stayontop in MS Windows."""
|
||||
window.set_focus_on_map(False)
|
||||
window.set_accept_focus(False)
|
||||
|
||||
# def windowEnumerationHandler(hwnd, resultList):
|
||||
# '''Callback for win32gui.EnumWindows() to generate list of window handles.'''
|
||||
# resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
|
||||
if not self.table.gdkhandle:
|
||||
self.table.gdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gtk handle to poker window
|
||||
# window.window.reparent(self.table.gdkhandle, 0, 0)
|
||||
window.window.set_transient_for(self.table.gdkhandle)
|
||||
# window.present()
|
||||
|
||||
# unique_name = 'unique name for finding this window'
|
||||
# real_name = window.get_title()
|
||||
# window.set_title(unique_name)
|
||||
# tl_windows = []
|
||||
# win32gui.EnumWindows(windowEnumerationHandler, tl_windows)
|
||||
|
||||
# for w in tl_windows:
|
||||
# if w[1] == unique_name:
|
||||
# window.set_transient_for(self.parent.window)
|
||||
style = win32gui.GetWindowLong(self.parent.table.number, win32con.GWL_EXSTYLE)
|
||||
style |= win32con.WS_CLIPCHILDREN
|
||||
win32gui.SetWindowLong(self.parent.table.number, win32con.GWL_EXSTYLE, style)
|
||||
# break
|
||||
|
||||
# window.set_title(real_name)
|
||||
|
||||
if __name__== "__main__":
|
||||
main_window = gtk.Window()
|
||||
|
@ -661,7 +631,7 @@ if __name__== "__main__":
|
|||
|
||||
c = Configuration.Config()
|
||||
#tables = Tables.discover(c)
|
||||
t = Tables.discover_table_by_name(c, "Patriot Dr")
|
||||
t = Tables.discover_table_by_name(c, "Corona")
|
||||
if t is None:
|
||||
print "Table not found."
|
||||
db = Database.Database(c, 'fpdb', 'holdem')
|
||||
|
|
224
pyfpdb/SQL.py
224
pyfpdb/SQL.py
|
@ -325,8 +325,14 @@ class Sql:
|
|||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
buyin INT NOT NULL,
|
||||
fee INT NOT NULL,
|
||||
knockout INT NOT NULL,
|
||||
rebuyOrAddon BOOLEAN NOT NULL)
|
||||
maxSeats INT NOT NULL DEFAULT -1,
|
||||
knockout BOOLEAN NOT NULL DEFAULT False,
|
||||
rebuyOrAddon 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
|
||||
)
|
||||
ENGINE=INNODB"""
|
||||
elif db_server == 'postgresql':
|
||||
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||
|
@ -334,16 +340,28 @@ class Sql:
|
|||
siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
buyin INT NOT NULL,
|
||||
fee INT NOT NULL,
|
||||
knockout INT NOT NULL,
|
||||
rebuyOrAddon BOOLEAN NOT NULL)"""
|
||||
maxSeats INT NOT NULL DEFAULT -1,
|
||||
knockout BOOLEAN NOT NULL DEFAULT False,
|
||||
rebuyOrAddon 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
|
||||
)"""
|
||||
elif db_server == 'sqlite':
|
||||
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||
id INTEGER PRIMARY KEY,
|
||||
siteId INT NOT NULL,
|
||||
buyin INT NOT NULL,
|
||||
fee INT NOT NULL,
|
||||
knockout INT NOT NULL,
|
||||
rebuyOrAddon BOOLEAN NOT NULL)"""
|
||||
maxSeats INT NOT NULL DEFAULT -1,
|
||||
knockout BOOLEAN NOT NULL DEFAULT 0,
|
||||
rebuyOrAddon BOOLEAN NOT NULL DEFAULT 0,
|
||||
speed TEXT,
|
||||
headsUp BOOLEAN NOT NULL DEFAULT 0,
|
||||
shootout BOOLEAN NOT NULL DEFAULT 0,
|
||||
matrix BOOLEAN NOT NULL DEFAULT 0
|
||||
)"""
|
||||
|
||||
################################
|
||||
# Create Tourneys
|
||||
|
@ -352,32 +370,65 @@ 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, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
siteTourneyNo BIGINT NOT NULL,
|
||||
entries INT NOT NULL,
|
||||
prizepool INT NOT NULL,
|
||||
startTime DATETIME NOT NULL,
|
||||
endTime DATETIME,
|
||||
buyinChips INT,
|
||||
tourneyName varchar(20),
|
||||
matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
|
||||
rebuyChips INT DEFAULT 0,
|
||||
addonChips INT DEFAULT 0,
|
||||
rebuyAmount INT DEFAULT 0,
|
||||
addonAmount INT DEFAULT 0,
|
||||
totalRebuys INT DEFAULT 0,
|
||||
totalAddons INT DEFAULT 0,
|
||||
koBounty INT DEFAULT 0,
|
||||
comment TEXT,
|
||||
commentTs DATETIME)
|
||||
ENGINE=INNODB"""
|
||||
elif db_server == 'postgresql':
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
siteTourneyNo BIGINT,
|
||||
entries INT,
|
||||
prizepool INT,
|
||||
startTime timestamp without time zone,
|
||||
endTime timestamp without time zone,
|
||||
buyinChips INT,
|
||||
tourneyName varchar(20),
|
||||
matrixIdProcessed SMALLINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
|
||||
rebuyChips INT DEFAULT 0,
|
||||
addonChips INT DEFAULT 0,
|
||||
rebuyAmount INT DEFAULT 0,
|
||||
addonAmount INT DEFAULT 0,
|
||||
totalRebuys INT DEFAULT 0,
|
||||
totalAddons INT DEFAULT 0,
|
||||
koBounty INT DEFAULT 0,
|
||||
comment TEXT,
|
||||
commentTs timestamp without time zone)"""
|
||||
elif db_server == 'sqlite':
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id INTEGER PRIMARY KEY,
|
||||
tourneyTypeId INT,
|
||||
tourneyTypeId INT DEFAULT 1,
|
||||
siteTourneyNo INT,
|
||||
entries INT,
|
||||
prizepool INT,
|
||||
startTime REAL,
|
||||
endTime REAL,
|
||||
buyinChips INT,
|
||||
tourneyName TEXT,
|
||||
matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
|
||||
rebuyChips INT DEFAULT 0,
|
||||
addonChips INT DEFAULT 0,
|
||||
rebuyAmount INT DEFAULT 0,
|
||||
addonAmount INT DEFAULT 0,
|
||||
totalRebuys INT DEFAULT 0,
|
||||
totalAddons INT DEFAULT 0,
|
||||
koBounty INT DEFAULT 0,
|
||||
comment TEXT,
|
||||
commentTs REAL)"""
|
||||
################################
|
||||
|
@ -409,7 +460,7 @@ class Sql:
|
|||
comment text,
|
||||
commentTs DATETIME,
|
||||
tourneysPlayersId BIGINT UNSIGNED,
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
|
||||
wonWhenSeenStreet1 FLOAT,
|
||||
wonWhenSeenStreet2 FLOAT,
|
||||
|
@ -527,7 +578,7 @@ class Sql:
|
|||
comment text,
|
||||
commentTs timestamp without time zone,
|
||||
tourneysPlayersId BIGINT,
|
||||
tourneyTypeId INT NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId INT NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
|
||||
wonWhenSeenStreet1 FLOAT,
|
||||
wonWhenSeenStreet2 FLOAT,
|
||||
|
@ -644,7 +695,7 @@ class Sql:
|
|||
comment TEXT,
|
||||
commentTs REAL,
|
||||
tourneysPlayersId INT,
|
||||
tourneyTypeId INT NOT NULL,
|
||||
tourneyTypeId INT NOT NULL DEFAULT 1,
|
||||
|
||||
wonWhenSeenStreet1 REAL,
|
||||
wonWhenSeenStreet2 REAL,
|
||||
|
@ -749,6 +800,9 @@ class Sql:
|
|||
payinAmount INT NOT NULL,
|
||||
rank INT NOT NULL,
|
||||
winnings INT NOT NULL,
|
||||
nbRebuys INT DEFAULT 0,
|
||||
nbAddons INT DEFAULT 0,
|
||||
nbKO INT DEFAULT 0,
|
||||
comment TEXT,
|
||||
commentTs DATETIME)
|
||||
ENGINE=INNODB"""
|
||||
|
@ -760,6 +814,9 @@ class Sql:
|
|||
payinAmount INT,
|
||||
rank INT,
|
||||
winnings INT,
|
||||
nbRebuys INT DEFAULT 0,
|
||||
nbAddons INT DEFAULT 0,
|
||||
nbKO INT DEFAULT 0,
|
||||
comment TEXT,
|
||||
commentTs timestamp without time zone)"""
|
||||
elif db_server == 'sqlite':
|
||||
|
@ -808,7 +865,7 @@ class Sql:
|
|||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
activeSeats SMALLINT NOT NULL,
|
||||
position CHAR(1),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||
HDs INT NOT NULL,
|
||||
|
||||
|
@ -909,7 +966,7 @@ class Sql:
|
|||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
activeSeats SMALLINT,
|
||||
position CHAR(1),
|
||||
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||
HDs INT,
|
||||
|
||||
|
@ -1008,7 +1065,7 @@ class Sql:
|
|||
playerId INT,
|
||||
activeSeats INT,
|
||||
position TEXT,
|
||||
tourneyTypeId INT,
|
||||
tourneyTypeId INT DEFAULT 1,
|
||||
styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||
HDs INT,
|
||||
|
||||
|
@ -2759,6 +2816,143 @@ class Sql:
|
|||
WHERE gametypeId=%s AND siteHandNo=%s
|
||||
"""
|
||||
|
||||
self.query['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id,
|
||||
tt.buyin,
|
||||
tt.fee,
|
||||
tt.maxSeats,
|
||||
tt.knockout,
|
||||
tt.rebuyOrAddon,
|
||||
tt.speed,
|
||||
tt.headsUp,
|
||||
tt.shootout,
|
||||
tt.matrix
|
||||
FROM TourneyTypes tt
|
||||
INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id)
|
||||
WHERE t.siteTourneyNo=%s AND tt.siteId=%s
|
||||
"""
|
||||
|
||||
self.query['getTourneyTypeId'] = """SELECT id
|
||||
FROM TourneyTypes
|
||||
WHERE siteId=%s
|
||||
AND buyin=%s
|
||||
AND fee=%s
|
||||
AND knockout=%s
|
||||
AND rebuyOrAddon=%s
|
||||
AND speed=%s
|
||||
AND headsUp=%s
|
||||
AND shootout=%s
|
||||
AND matrix=%s
|
||||
"""
|
||||
|
||||
self.query['insertTourneyTypes'] = """INSERT INTO TourneyTypes
|
||||
(siteId, buyin, fee, knockout, rebuyOrAddon
|
||||
,speed, headsUp, shootout, matrix)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
self.query['getTourney'] = """SELECT t.id,
|
||||
t.tourneyTypeId,
|
||||
t.entries,
|
||||
t.prizepool,
|
||||
t.startTime,
|
||||
t.endTime,
|
||||
t.buyinChips,
|
||||
t.tourneyName,
|
||||
t.matrixIdProcessed,
|
||||
t.rebuyChips,
|
||||
t.addonChips,
|
||||
t.rebuyAmount,
|
||||
t.addonAmount,
|
||||
t.totalRebuys,
|
||||
t.totalAddons,
|
||||
t.koBounty,
|
||||
t.comment
|
||||
FROM Tourneys t
|
||||
INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
|
||||
WHERE t.siteTourneyNo=%s AND tt.siteId=%s
|
||||
"""
|
||||
|
||||
self.query['insertTourney'] = """INSERT INTO Tourneys
|
||||
(tourneyTypeId, siteTourneyNo, entries, prizepool,
|
||||
startTime, endTime, buyinChips, tourneyName, matrixIdProcessed,
|
||||
rebuyChips, addonChips, rebuyAmount, addonAmount, totalRebuys,
|
||||
totalAddons, koBounty, comment, commentTs)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
self.query['updateTourney'] = """UPDATE Tourneys
|
||||
SET tourneyTypeId = %s,
|
||||
entries = %s,
|
||||
prizepool = %s,
|
||||
startTime = %s,
|
||||
endTime = %s,
|
||||
buyinChips = %s,
|
||||
tourneyName = %s,
|
||||
matrixIdProcessed = %s,
|
||||
rebuyChips = %s,
|
||||
addonChips = %s,
|
||||
rebuyAmount = %s,
|
||||
addonAmount = %s,
|
||||
totalRebuys = %s,
|
||||
totalAddons = %s,
|
||||
koBounty = %s,
|
||||
comment = %s,
|
||||
commentTs = %s
|
||||
WHERE id=%s
|
||||
"""
|
||||
|
||||
self.query['getTourneysPlayers'] = """SELECT id,
|
||||
payinAmount,
|
||||
rank,
|
||||
winnings,
|
||||
nbRebuys,
|
||||
nbAddons,
|
||||
nbKO,
|
||||
comment,
|
||||
commentTs
|
||||
FROM TourneysPlayers
|
||||
WHERE tourneyId=%s AND playerId+0=%s
|
||||
"""
|
||||
|
||||
self.query['updateTourneysPlayers'] = """UPDATE TourneysPlayers
|
||||
SET payinAmount = %s,
|
||||
rank = %s,
|
||||
winnings = %s,
|
||||
nbRebuys = %s,
|
||||
nbAddons = %s,
|
||||
nbKO = %s,
|
||||
comment = %s,
|
||||
commentTs = %s
|
||||
WHERE id=%s
|
||||
"""
|
||||
|
||||
self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers
|
||||
(tourneyId, playerId, payinAmount, rank, winnings, nbRebuys, nbAddons, nbKO, comment, commentTs)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
self.query['selectHandsPlayersWithWrongTTypeId'] = """SELECT id
|
||||
FROM HandsPlayers
|
||||
WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s)
|
||||
"""
|
||||
|
||||
# self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers
|
||||
# SET tourneyTypeId= %s
|
||||
# WHERE (TourneysPlayersId+0=%s)
|
||||
# """
|
||||
|
||||
self.query['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers
|
||||
SET tourneyTypeId= %s
|
||||
WHERE (id=%s)
|
||||
"""
|
||||
|
||||
|
||||
self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
|
||||
self.query['handsPlayersTTypeId_joiner_id'] = " OR id="
|
||||
|
||||
|
||||
|
||||
if db_server == 'mysql':
|
||||
self.query['placeholder'] = u'%s'
|
||||
elif db_server == 'postgresql':
|
||||
|
|
|
@ -69,6 +69,7 @@ class Table_Window:
|
|||
if 'site' in info: self.site = info['site']
|
||||
if 'title' in info: self.title = info['title']
|
||||
if 'name' in info: self.name = info['name']
|
||||
self.gdkhandle = None
|
||||
|
||||
def __str__(self):
|
||||
# __str__ method for testing
|
||||
|
|
|
@ -46,7 +46,6 @@ class Tourney(object):
|
|||
|
||||
|
||||
def __init__(self, sitename, gametype, summaryText, builtFrom = "HHC"):
|
||||
print "Tourney.__init__"
|
||||
self.sitename = sitename
|
||||
self.siteId = self.SITEIDS[sitename]
|
||||
self.gametype = gametype
|
||||
|
@ -74,21 +73,21 @@ class Tourney(object):
|
|||
self.subTourneyFee = None
|
||||
self.rebuyChips = 0
|
||||
self.addOnChips = 0
|
||||
self.countRebuys = 0
|
||||
self.countAddOns = 0
|
||||
self.rebuyAmount = 0
|
||||
self.addOnAmount = 0
|
||||
self.totalRebuys = 0
|
||||
self.totalAddOns = 0
|
||||
self.koBounty = 0
|
||||
self.countKO = 0 #To use for winnings calculation which is not counted in the rest of the summary file
|
||||
self.tourneyComment = None
|
||||
self.players = []
|
||||
|
||||
# Collections indexed by player names
|
||||
self.finishPositions = {}
|
||||
self.winnings = {}
|
||||
|
||||
|
||||
self.payinAmounts = {}
|
||||
self.countRebuys = {}
|
||||
self.countAddOns = {}
|
||||
self.countKO = {}
|
||||
|
||||
# currency symbol for this summary
|
||||
self.sym = None
|
||||
|
@ -122,20 +121,20 @@ class Tourney(object):
|
|||
("ADDON CHIPS", self.addOnChips),
|
||||
("REBUY AMOUNT", self.rebuyAmount),
|
||||
("ADDON AMOUNT", self.addOnAmount),
|
||||
("COUNT REBUYS", self.countRebuys),
|
||||
("COUNT ADDONS", self.countAddOns),
|
||||
("NB REBUYS", self.countRebuys),
|
||||
("NB ADDONS", self.countAddOns),
|
||||
("TOTAL REBUYS", self.totalRebuys),
|
||||
("TOTAL ADDONS", self.totalAddOns),
|
||||
("KO BOUNTY", self.koBounty),
|
||||
("NB OF KO", self.countKO)
|
||||
("TOURNEY COMMENT", self.tourneyComment)
|
||||
)
|
||||
|
||||
structs = ( ("GAMETYPE", self.gametype),
|
||||
("PLAYERS", self.players),
|
||||
("PAYIN AMOUNTS", self.payinAmounts),
|
||||
("POSITIONS", self.finishPositions),
|
||||
("WINNINGS", self.winnings),
|
||||
("COUNT REBUYS", self.countRebuys),
|
||||
("COUNT ADDONS", self.countAddOns),
|
||||
("NB OF KO", self.countKO)
|
||||
)
|
||||
str = ''
|
||||
for (name, var) in vars:
|
||||
|
@ -152,7 +151,6 @@ class Tourney(object):
|
|||
pass
|
||||
|
||||
def insert(self, db):
|
||||
print "TODO: Insert Tourney in DB"
|
||||
# First : check all needed info is filled in the object, especially for the initial select
|
||||
|
||||
# Notes on DB Insert
|
||||
|
@ -163,6 +161,19 @@ class Tourney(object):
|
|||
# Starttime may not match the one in the Summary file : HH = time of the first Hand / could be slighltly different from the one in the summary file
|
||||
# Note: If the TourneyNo could be a unique id .... this would really be a relief to deal with matrix matches ==> Ask on the IRC / Ask Fulltilt ??
|
||||
|
||||
dbTourneyTypeId = db.tRecogniseTourneyType(self)
|
||||
logging.debug("Tourney Type ID = %d" % dbTourneyTypeId)
|
||||
dbTourneyId = db.tRecognizeTourney(self, dbTourneyTypeId)
|
||||
logging.debug("Tourney ID = %d" % dbTourneyId)
|
||||
dbTourneysPlayersIds = db.tStoreTourneyPlayers(self, dbTourneyId)
|
||||
logging.debug("TourneysPlayersId = %s" % dbTourneysPlayersIds)
|
||||
db.tUpdateTourneysHandsPlayers(self, dbTourneysPlayersIds, dbTourneyTypeId)
|
||||
logging.debug("tUpdateTourneysHandsPlayers done")
|
||||
logging.debug("Tourney Insert done")
|
||||
|
||||
# TO DO : Return what has been done (tourney created, updated, nothing)
|
||||
# ?? stored = 1 if tourney is fully created / duplicates = 1, if everything was already here and correct / partial=1 if some things were already here (between tourney, tourneyPlayers and handsplayers)
|
||||
# if so, prototypes may need changes to know what has been done or make some kind of dict in Tourney object that could be updated during the insert process to store that information
|
||||
stored = 0
|
||||
duplicates = 0
|
||||
partial = 0
|
||||
|
@ -246,18 +257,21 @@ db: a connected fpdb_db object"""
|
|||
|
||||
|
||||
|
||||
def addPlayer(self, rank, name, winnings):
|
||||
def addPlayer(self, rank, name, winnings, payinAmount, nbRebuys, nbAddons, nbKO):
|
||||
"""\
|
||||
Adds a player to the tourney, and initialises data structures indexed by player.
|
||||
rank (int) indicating the finishing rank (can be -1 if unknown)
|
||||
name (string) player name
|
||||
winnings (string) the money the player ended the tourney with (can be 0, or -1 if unknown)
|
||||
winnings (decimal) the money the player ended the tourney with (can be 0, or -1 if unknown)
|
||||
"""
|
||||
log.debug("addPlayer: rank:%s - name : '%s' - Winnings (%s)" % (rank, name, winnings))
|
||||
winnings = re.sub(u',', u'', winnings) #some sites have commas
|
||||
self.players.append(name)
|
||||
self.finishPositions.update( { name : Decimal(rank) } )
|
||||
self.winnings.update( { name : Decimal(winnings) } )
|
||||
self.payinAmounts.update( {name : Decimal(payinAmount) } )
|
||||
self.countRebuys.update( {name: Decimal(nbRebuys) } )
|
||||
self.countAddOns.update( {name: Decimal(nbAddons) } )
|
||||
self.countKO.update( {name : Decimal(nbKO) } )
|
||||
|
||||
|
||||
def incrementPlayerWinnings(self, name, additionnalWinnings):
|
||||
|
@ -270,11 +284,6 @@ winnings (string) the money the player ended the tourney with (can be 0, or -
|
|||
|
||||
self.winnings[name] = oldWins + Decimal(additionnalWinnings)
|
||||
|
||||
|
||||
def calculatePayinAmount(self):
|
||||
return self.buyin + self.fee + (self.rebuyAmount * self.countRebuys) + (self.addOnAmount * self.countAddOns )
|
||||
|
||||
|
||||
def checkPlayerExists(self,player):
|
||||
if player not in [p[1] for p in self.players]:
|
||||
print "checkPlayerExists", player, "fail"
|
||||
|
|
|
@ -55,9 +55,9 @@ try:
|
|||
pgsqlLibFound=True
|
||||
import psycopg2.extensions
|
||||
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
||||
log.debug("Import module: pyscopg2")
|
||||
log.debug("Import module: psycopg2")
|
||||
except:
|
||||
log.debug("Import module: pyscopg2 not found")
|
||||
log.debug("Import module: psycopg2 not found")
|
||||
|
||||
class Importer:
|
||||
|
||||
|
@ -418,10 +418,10 @@ class Importer:
|
|||
else:
|
||||
# conversion didn't work
|
||||
# TODO: appropriate response?
|
||||
return (0, 0, 0, 1, 0, -1)
|
||||
return (0, 0, 0, 1, 0)
|
||||
else:
|
||||
log.warning("Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter))
|
||||
return (0, 0, 0, 1, 0, -1)
|
||||
return (0, 0, 0, 1, 0)
|
||||
|
||||
#This will barf if conv.getStatus != True
|
||||
return (stored, duplicates, partial, errors, ttime)
|
||||
|
|
|
@ -68,7 +68,8 @@ def mainParser(settings, siteID, category, hand, config, db = None, writeq = Non
|
|||
tourneyStartTime= handStartTime #todo: read tourney start time
|
||||
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
||||
|
||||
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(db.get_cursor(), siteID, buyin, fee, knockout, rebuyOrAddon)
|
||||
## The tourney site id has to be searched because it may already be in db with a TourneyTypeId which is different from the one automatically calculated (Summary import first)
|
||||
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(db, siteID, siteTourneyNo, buyin, fee, knockout, rebuyOrAddon)
|
||||
else:
|
||||
siteTourneyNo = -1
|
||||
buyin = -1
|
||||
|
|
|
@ -943,17 +943,28 @@ def recogniseGametypeID(backend, db, cursor, topline, smallBlindLine, site_id, c
|
|||
return result[0]
|
||||
#end def recogniseGametypeID
|
||||
|
||||
def recogniseTourneyTypeId(cursor, siteId, buyin, fee, knockout, rebuyOrAddon):
|
||||
cursor.execute ("SELECT id FROM TourneyTypes WHERE siteId=%s AND buyin=%s AND fee=%s AND knockout=%s AND rebuyOrAddon=%s", (siteId, buyin, fee, knockout, rebuyOrAddon))
|
||||
def recogniseTourneyTypeId(db, siteId, tourneySiteId, buyin, fee, knockout, rebuyOrAddon):
|
||||
cursor = db.get_cursor()
|
||||
# First we try to find the tourney itself (by its tourneySiteId) in case it has already been inserted before (by a summary file for instance)
|
||||
# The reason is that some tourneys may not be identified correctly in the HH toplines (especially Buy-In and Fee which are used to search/create the TourneyTypeId)
|
||||
#TODO: When the summary file will be dumped to BD, if the tourney is already in, Buy-In/Fee may need an update (e.g. creation of a new type and link to the Tourney)
|
||||
cursor.execute (db.sql.query['getTourneyTypeIdByTourneyNo'].replace('%s', db.sql.query['placeholder']), (tourneySiteId, siteId))
|
||||
result=cursor.fetchone()
|
||||
#print "tried SELECTing gametypes.id, result:",result
|
||||
|
||||
try:
|
||||
len(result)
|
||||
except TypeError:#this means we need to create a new entry
|
||||
cursor.execute("""INSERT INTO TourneyTypes (siteId, buyin, fee, knockout, rebuyOrAddon) VALUES (%s, %s, %s, %s, %s)""", (siteId, buyin, fee, knockout, rebuyOrAddon))
|
||||
cursor.execute("SELECT id FROM TourneyTypes WHERE siteId=%s AND buyin=%s AND fee=%s AND knockout=%s AND rebuyOrAddon=%s", (siteId, buyin, fee, knockout, rebuyOrAddon))
|
||||
except:
|
||||
cursor.execute ("SELECT id FROM TourneyTypes WHERE siteId=%s AND buyin=%s AND fee=%s AND knockout=%s AND rebuyOrAddon=%s", (siteId, buyin, fee, knockout, rebuyOrAddon))
|
||||
result=cursor.fetchone()
|
||||
#print "tried SELECTing gametypes.id, result:",result
|
||||
|
||||
try:
|
||||
len(result)
|
||||
except TypeError:#this means we need to create a new entry
|
||||
cursor.execute("""INSERT INTO TourneyTypes (siteId, buyin, fee, knockout, rebuyOrAddon) VALUES (%s, %s, %s, %s, %s)""", (siteId, buyin, fee, knockout, rebuyOrAddon))
|
||||
cursor.execute("SELECT id FROM TourneyTypes WHERE siteId=%s AND buyin=%s AND fee=%s AND knockout=%s AND rebuyOrAddon=%s", (siteId, buyin, fee, knockout, rebuyOrAddon))
|
||||
result=cursor.fetchone()
|
||||
|
||||
return result[0]
|
||||
#end def recogniseTourneyTypeId
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user