Merge branch 'master' of git://git.assembla.com/free_poker_tools.git

This commit is contained in:
eblade 2009-07-30 15:28:41 -04:00
commit 98e376a956
9 changed files with 308 additions and 106 deletions

View File

@ -106,8 +106,23 @@ def valueSuitFromCard(card):
, '2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s', 'Ts', 'Js', 'Qs', 'Ks', 'As'
][card] )
def encodeCard(cardString):
"""Take a card string (Ah) and convert it to the db card code (1)."""
try:
return {'2h': 1, '3h': 2, '4h': 3, '5h': 4, '6h': 5, '7h': 6, '8h': 7, '9h': 8, 'Th': 9, 'Jh': 10, 'Qh': 11, 'Kh': 12, 'Ah': 13,
'2d': 14, '3d': 15, '4d': 16, '5d': 17, '6d': 18, '7d': 19, '8d': 20, '9d': 21, 'Td': 22, 'Jd': 23, 'Qd': 24, 'Kd': 25, 'Ad': 26,
'2c': 27, '3c': 28, '4c': 29, '5c': 30, '6c': 31, '7c': 32, '8c': 33, '9c': 34, 'Tc': 35, 'Jc': 36, 'Qc': 27, 'Kc': 38, 'Ac': 39,
'2s': 40, '3s': 41, '4s': 42, '5s': 43, '6s': 44, '7s': 45, '8s': 46, '9s': 47, 'Ts': 48, 'Js': 49, 'Qs': 50, 'Ks': 51, 'As': 52,
' ': 0
}[cardString]
except:
return 0 # everthing that isn't known is a unknown!
if __name__ == '__main__':
print "fpdb card encoding(same as pokersource)"
for i in xrange(1, 14):
print "card %2d = %s card %2d = %s card %2d = %s card %2d = %s" % \
(i, valueSuitFromCard(i), i+13, valueSuitFromCard(i+13), i+26, valueSuitFromCard(i+26), i+39, valueSuitFromCard(i+39))
print
print encodeCard('7c')

View File

@ -64,11 +64,15 @@ class Database:
, [ # indexes for mysql (list index 2)
{'tab':'Players', 'col':'name', 'drop':0}
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
, {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
, {'tab':'HandsPlayers', 'col':'handId', 'drop':0} # not needed, handled by fk
, {'tab':'HandsPlayers', 'col':'playerId', 'drop':0} # not needed, handled by fk
, {'tab':'HandsPlayers', 'col':'tourneysTypeId', 'drop':0}
, {'tab':'HandsPlayers', 'col':'tourneysPlayersId', 'drop':0}
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0}
]
, [ # indexes for postgres (list index 3)
{'tab':'Boardcards', 'col':'handId', 'drop':0}
, {'tab':'Gametypes', 'col':'siteId', 'drop':0}
{'tab':'Gametypes', 'col':'siteId', 'drop':0}
, {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
, {'tab':'HandsActions', 'col':'handsPlayerId', 'drop':0}
@ -589,16 +593,17 @@ class Database:
"""Drop some indexes/foreign keys to prepare for bulk import.
Currently keeping the standalone indexes as needed to import quickly"""
stime = time()
c = self.get_cursor()
# sc: don't think autocommit=0 is needed, should already be in that mode
if self.backend == self.MYSQL_INNODB:
self.get_cursor().execute("SET foreign_key_checks=0")
self.get_cursor().execute("SET autocommit=0")
c.execute("SET foreign_key_checks=0")
c.execute("SET autocommit=0")
return
if self.backend == self.PGSQL:
self.connection.set_isolation_level(0) # allow table/index operations to work
for fk in self.foreignKeys[self.backend]:
if fk['drop'] == 1:
if self.backend == self.MYSQL_INNODB:
c = self.get_cursor()
c.execute("SELECT constraint_name " +
"FROM information_schema.KEY_COLUMN_USAGE " +
#"WHERE REFERENCED_TABLE_SCHEMA = 'fpdb'
@ -608,13 +613,13 @@ class Database:
"AND referenced_column_name = %s ",
(fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) )
cons = c.fetchone()
#print "preparebulk: cons=", cons
print "preparebulk find fk: cons=", cons
if cons:
print "dropping mysql fk", cons[0], fk['fktab'], fk['fkcol']
try:
c.execute("alter table " + fk['fktab'] + " drop foreign key " + cons[0])
except:
pass
print " drop failed: " + str(sys.exc_info())
elif self.backend == self.PGSQL:
# DON'T FORGET TO RECREATE THEM!!
print "dropping pg fk", fk['fktab'], fk['fkcol']
@ -640,16 +645,18 @@ class Database:
print "Only MySQL and Postgres supported so far"
return -1
for idx in indexes[self.backend]:
for idx in self.indexes[self.backend]:
if idx['drop'] == 1:
if self.backend == self.MYSQL_INNODB:
print "dropping mysql index ", idx['tab'], idx['col']
try:
# apparently nowait is not implemented in mysql so this just hands if there are locks
# apparently nowait is not implemented in mysql so this just hangs if there are locks
# preventing the index drop :-(
c.execute( "alter table %s drop index %s", (idx['tab'],idx['col']) )
c.execute( "alter table %s drop index %s;", (idx['tab'],idx['col']) )
except:
pass
print " drop index failed: " + str(sys.exc_info())
# ALTER TABLE `fpdb`.`handsplayers` DROP INDEX `playerId`;
# using: 'HandsPlayers' drop index 'playerId'
elif self.backend == self.PGSQL:
# DON'T FORGET TO RECREATE THEM!!
print "dropping pg index ", idx['tab'], idx['col']
@ -684,8 +691,8 @@ class Database:
"""Re-create any dropped indexes/foreign keys after bulk import"""
stime = time()
if self.backend == self.MYSQL_INNODB:
c = self.get_cursor()
if self.backend == self.MYSQL_INNODB:
c.execute("SET foreign_key_checks=1")
c.execute("SET autocommit=1")
return
@ -714,7 +721,7 @@ class Database:
+ fk['fkcol'] + ") references " + fk['rtab'] + "("
+ fk['rcol'] + ")")
except:
pass
print " create fk failed: " + str(sys.exc_info())
elif self.backend == self.PGSQL:
print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol']
try:
@ -723,12 +730,12 @@ class Database:
+ " foreign key (" + fk['fkcol']
+ ") references " + fk['rtab'] + "(" + fk['rcol'] + ")")
except:
pass
print " create fk failed: " + str(sys.exc_info())
else:
print "Only MySQL and Postgres supported so far"
return -1
for idx in indexes[self.backend]:
for idx in self.indexes[self.backend]:
if idx['drop'] == 1:
if self.backend == self.MYSQL_INNODB:
print "creating mysql index ", idx['tab'], idx['col']
@ -736,7 +743,7 @@ class Database:
c.execute( "alter table %s add index %s(%s)"
, (idx['tab'],idx['col'],idx['col']) )
except:
pass
print " create fk failed: " + str(sys.exc_info())
elif self.backend == self.PGSQL:
# pass
# mod to use tab_col for index name?
@ -746,8 +753,7 @@ class Database:
c.execute( "create index %s_%s_idx on %s(%s)"
% (idx['tab'], idx['col'], idx['tab'], idx['col']) )
except:
print " ERROR! :-("
pass
print " create index failed: " + str(sys.exc_info())
else:
print "Only MySQL and Postgres supported so far"
return -1
@ -823,12 +829,12 @@ class Database:
"""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 = self.get_cursor()
c.execute(self.sql.query['list_tables'])
for table in c:
c.execute(self.sql.query['drop_table'] + table[0])
@ -974,6 +980,62 @@ class Database:
#end def lock_for_insert
def store_the_hand(self, h):
"""Take a HandToWrite object and store it in the db"""
# Following code writes hands to database and commits (or rolls back if there is an error)
try:
result = None
if h.isTourney:
ranks = map(lambda x: 0, h.names) # create an array of 0's equal to the length of names
payin_amounts = fpdb_simple.calcPayin(len(h.names), h.buyin, h.fee)
if h.base == "hold":
result = self.tourney_holdem_omaha(
h.config, h.settings, h.base, h.category, h.siteTourneyNo, h.buyin
, h.fee, h.knockout, h.entries, h.prizepool, h.tourneyStartTime
, h.payin_amounts, h.ranks, h.tourneyTypeId, h.siteID, h.siteHandNo
, h.gametypeID, h.handStartTime, h.names, h.playerIDs, h.startCashes
, h.positions, h.cardValues, h.cardSuits, h.boardValues, h.boardSuits
, h.winnings, h.rakes, h.actionTypes, h.allIns, h.actionAmounts
, h.actionNos, h.hudImportData, h.maxSeats, h.tableName, h.seatNos)
elif h.base == "stud":
result = self.tourney_stud(
h.config, h.settings, h.base, h.category, h.siteTourneyNo
, h.buyin, h.fee, h.knockout, h.entries, h.prizepool, h.tourneyStartTime
, h.payin_amounts, h.ranks, h.tourneyTypeId, h.siteID, h.siteHandNo
, h.gametypeID, h.handStartTime, h.names, h.playerIDs, h.startCashes
, h.antes, h.cardValues, h.cardSuits, h.winnings, h.rakes, h.actionTypes
, h.allIns, h.actionAmounts, h.actionNos, h.hudImportData, h.maxSeats
, h.tableName, h.seatNos)
else:
raise fpself.simple.Fpself.rror("unrecognised category")
else:
if h.base == "hold":
result = self.ring_holdem_omaha(
h.config, h.settings, h.base, h.category, h.siteHandNo
, h.gametypeID, h.handStartTime, h.names, h.playerIDs
, h.startCashes, h.positions, h.cardValues, h.cardSuits
, h.boardValues, h.boardSuits, h.winnings, h.rakes
, h.actionTypes, h.allIns, h.actionAmounts, h.actionNos
, h.hudImportData, h.maxSeats, h.tableName, h.seatNos)
elif h.base == "stud":
result = self.ring_stud(
h.config, h.settings, h.base, h.category, h.siteHandNo, h.gametypeID
, h.handStartTime, h.names, h.playerIDs, h.startCashes, h.antes
, h.cardValues, h.cardSuits, h.winnings, h.rakes, h.actionTypes, h.allIns
, h.actionAmounts, h.actionNos, h.hudImportData, h.maxSeats, h.tableName
, h.seatNos)
else:
raise fpself.simple.Fpself.rror ("unrecognised category")
self.commit()
except:
print "Error storing hand: " + str(sys.exc_value)
self.rollback()
return result
#end def store_the_hand
def storeHands(self, backend, site_hand_no, gametype_id
,hand_start_time, names, tableName, maxSeats, hudCache
,board_values, board_suits):
@ -1514,6 +1576,157 @@ class Database:
#end def store_tourneys_players
# 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
class HandToWrite:
def __init__(self, finished = False): # db_name and game not used any more
try:
self.finished = finished
self.config = None
self.settings = None
self.base = None
self.category = None
self.siteTourneyNo = None
self.buyin = None
self.fee = None
self.knockout = None
self.entries = None
self.prizepool = None
self.tourneyStartTime = None
self.isTourney = None
self.tourneyTypeId = None
self.siteID = None
self.siteHandNo = None
self.gametypeID = None
self.handStartTime = None
self.names = None
self.playerIDs = None
self.startCashes = None
self.positions = None
self.antes = None
self.cardValues = None
self.cardSuits = None
self.boardValues = None
self.boardSuits = None
self.winnings = None
self.rakes = None
self.actionTypes = None
self.allIns = None
self.actionAmounts = None
self.actionNos = None
self.hudImportData = None
self.maxSeats = None
self.tableName = None
self.seatNos = None
except:
print "htw.init error: " + str(sys.exc_info())
raise
# end def __init__
def set_all( self, config, settings, base, category, siteTourneyNo, buyin
, fee, knockout, entries, prizepool, tourneyStartTime
, isTourney, tourneyTypeId, siteID, siteHandNo
, gametypeID, handStartTime, names, playerIDs, startCashes
, positions, antes, cardValues, cardSuits, boardValues, boardSuits
, winnings, rakes, actionTypes, allIns, actionAmounts
, actionNos, hudImportData, maxSeats, tableName, seatNos):
try:
self.config = config
self.settings = settings
self.base = base
self.category = category
self.siteTourneyNo = siteTourneyNo
self.buyin = buyin
self.fee = fee
self.knockout = knockout
self.entries = entries
self.prizepool = prizepool
self.tourneyStartTime = tourneyStartTime
self.isTourney = isTourney
self.tourneyTypeId = tourneyTypeId
self.siteID = siteID
self.siteHandNo = siteHandNo
self.gametypeID = gametypeID
self.handStartTime = handStartTime
self.names = names
self.playerIDs = playerIDs
self.startCashes = startCashes
self.positions = positions
self.antes = antes
self.cardValues = cardValues
self.cardSuits = cardSuits
self.boardValues = boardValues
self.boardSuits = boardSuits
self.winnings = winnings
self.rakes = rakes
self.actionTypes = actionTypes
self.allIns = allIns
self.actionAmounts = actionAmounts
self.actionNos = actionNos
self.hudImportData = hudImportData
self.maxSeats = maxSeats
self.tableName = tableName
self.seatNos = seatNos
except:
print "htw.set_all error: " + str(sys.exc_info())
raise
# end def set_hand
def set_ring_holdem_omaha( self, config, settings, base, category, siteHandNo
, gametypeID, handStartTime, names, playerIDs
, startCashes, positions, cardValues, cardSuits
, boardValues, boardSuits, winnings, rakes
, actionTypes, allIns, actionAmounts, actionNos
, hudImportData, maxSeats, tableName, seatNos ):
self.config = config
self.settings = settings
self.base = base
self.category = category
self.siteHandNo = siteHandNo
self.gametypeID = gametypeID
self.handStartTime = handStartTime
self.names = names
self.playerIDs = playerIDs
self.startCashes = startCashes
self.positions = positions
self.cardValues = cardValues
self.cardSuits = cardSuits
self.boardValues = boardValues
self.boardSuits = boardSuits
self.winnings = winnings
self.rakes = rakes
self.actionTypes = actionTypes
self.allIns = allIns
self.actionAmounts = actionAmounts
self.actionNos = actionNos
self.hudImportData = hudImportData
self.maxSeats = maxSeats
self.tableName = tableName
self.seatNos = seatNos
# end def set_ring_holdem_omaha
def send_ring_holdem_omaha(self, db):
result = db.ring_holdem_omaha(
self.config, self.settings, self.base, self.category, self.siteHandNo
, self.gametypeID, self.handStartTime, self.names, self.playerIDs
, self.startCashes, self.positions, self.cardValues, self.cardSuits
, self.boardValues, self.boardSuits, self.winnings, self.rakes
, self.actionTypes, self.allIns, self.actionAmounts, self.actionNos
, self.hudImportData, self.maxSeats, self.tableName, self.seatNos)
# end def send_ring_holdem_omaha
def get_finished(self):
return( self.finished )
# end def get_finished
def get_siteHandNo(self):
return( self.siteHandNo )
# end def get_siteHandNo
if __name__=="__main__":
c = Configuration.Config()

View File

@ -34,6 +34,7 @@ import Configuration
class GuiBulkImport():
# not used
def import_dir(self):
"""imports a directory, non-recursive. todo: move this to fpdb_import so CLI can use it"""
@ -80,7 +81,7 @@ class GuiBulkImport():
ttime = time() - starttime
if ttime == 0:
ttime = 1
print 'GuiBulkImport.import_dir done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %d/sec'\
print 'GuiBulkImport.load done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %d/sec'\
% (stored, dups, partial, errs, ttime, stored / ttime)
self.importer.clearFileList()
@ -96,10 +97,10 @@ class GuiBulkImport():
"""returns the vbox of this thread"""
return self.vbox
def __init__(self, settings, config):
def __init__(self, settings, config, sql = None):
self.settings = settings
self.config = config
self.importer = fpdb_import.Importer(self, self.settings, config)
self.importer = fpdb_import.Importer(self, self.settings, config, sql)
self.vbox = gtk.VBox(False, 0)
self.vbox.show()

View File

@ -235,12 +235,8 @@ class Hud:
# does the user have a fav_seat?
if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0:
try:
sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat))
fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
sys.stderr.write("found fav seat = %d\n" % fav_seat)
# actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
actual_seat = self.get_actual_seat(config.supported_sites[self.table.site].screen_name)
sys.stderr.write("found actual seat = %d\n" % actual_seat)
for i in xrange(0, self.max + 1):
j = actual_seat + i
if j > self.max:
@ -273,7 +269,6 @@ class Hud:
self.cards = cards
sys.stderr.write("------------------------------------------------------------\nCreating hud from hand %s\n" % hand)
adj = self.adj_seats(hand, config)
sys.stderr.write("adj = %s\n" % adj)
loc = self.config.get_locations(self.table.site, self.max)
# create the stat windows
@ -282,7 +277,6 @@ class Hud:
if i in self.stat_windows:
self.stat_windows[i].relocate(x, y)
else:
sys.stderr.write("actual seat = %d, x = %d, y= %d\n" % (i, x, y))
self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game],
parent = self,
table = self.table,

View File

@ -294,6 +294,7 @@ class Stud_cards:
def update_gui(self, new_hand_id):
self.clear()
for c, cards in self.parent.hud.cards.iteritems():
if c == 'common': continue
self.grid_contents[(1, c - 1)].set_text(self.get_screen_name(c))
for i in ((0, cards[0]), (1, cards[1]), (2, cards[2]), (3, cards[3]),
(4, cards[4]), (5, cards[5]), (6, cards[6])):
@ -462,7 +463,6 @@ class Flop_Mucked(Aux_Seats):
if n_cards > 0 and i != 'common':
n_sd = n_sd + 1
if n_sd < 2:
print "skipping, n_sd =", n_sd
return
super(Flop_Mucked, self).update_gui(new_hand_id)

View File

@ -165,9 +165,10 @@ class Sql:
################################
# List tables
################################
print "db_server =", db_server
if db_server == 'mysql':
self.query['list_tables'] = """SHOW TABLES"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"""
elif db_server == 'sqlite': # what is the correct value here?
self.query['list_tables'] = """SELECT name FROM sqlite_master
@ -188,7 +189,7 @@ class Sql:
self.query['createSettingsTable'] = """CREATE TABLE Settings (
version SMALLINT NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT)"""
elif db_server == 'sqlite': # what is the correct value here?
@ -206,7 +207,7 @@ class Sql:
name varchar(32) NOT NULL,
currency char(3) NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createSitesTable'] = """CREATE TABLE Sites (
id SERIAL, PRIMARY KEY (id),
name varchar(32),
@ -236,7 +237,7 @@ class Sql:
smallBet int NOT NULL,
bigBet int NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
id SERIAL, PRIMARY KEY (id),
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
@ -277,7 +278,7 @@ class Sql:
comment text,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createPlayersTable'] = """CREATE TABLE Players (
id SERIAL, PRIMARY KEY (id),
name VARCHAR(32),
@ -308,7 +309,7 @@ class Sql:
ratingTime DATETIME NOT NULL,
handCount int NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
id BIGSERIAL, PRIMARY KEY (id),
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
@ -360,7 +361,7 @@ class Sql:
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createHandsTable'] = """CREATE TABLE Hands (
id BIGSERIAL, PRIMARY KEY (id),
tableName VARCHAR(20) NOT NULL,
@ -422,7 +423,7 @@ class Sql:
knockout INT NOT NULL,
rebuyOrAddon BOOLEAN NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
id SERIAL, PRIMARY KEY (id),
siteId INT, FOREIGN KEY (siteId) REFERENCES Sites(id),
@ -449,7 +450,7 @@ class Sql:
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
id SERIAL, PRIMARY KEY (id),
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
@ -591,7 +592,7 @@ class Sql:
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
id BIGSERIAL, PRIMARY KEY (id),
handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
@ -727,7 +728,7 @@ class Sql:
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
id BIGSERIAL, PRIMARY KEY (id),
tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
@ -757,7 +758,7 @@ class Sql:
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id BIGSERIAL, PRIMARY KEY (id),
handsPlayerId BIGINT, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
@ -877,7 +878,7 @@ class Sql:
street4Raises INT)
ENGINE=INNODB"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
id BIGSERIAL, PRIMARY KEY (id),
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
@ -981,21 +982,21 @@ class Sql:
if db_server == 'mysql':
self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['addTourneyIndex'] = """CREATE INDEX siteTourneyNo ON Tourneys (siteTourneyNo)"""
elif db_server == 'sqlite': # what is the correct value here?
self.query['addHandsIndex'] = """ """
if db_server == 'mysql':
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['addHandsIndex'] = """CREATE INDEX siteHandNo ON Hands (siteHandNo)"""
elif db_server == 'sqlite': # what is the correct value here?
self.query['addHandsIndex'] = """ """
if db_server == 'mysql':
self.query['addPlayersIndex'] = """ALTER TABLE Players ADD INDEX name(name)"""
elif db_server == 'postgres': # what is the correct value here?
elif db_server == 'postgresql': # what is the correct value here?
self.query['addPlayersIndex'] = """CREATE INDEX name ON Players (name)"""
elif db_server == 'sqlite': # what is the correct value here?
self.query['addPlayersIndex'] = """ """

View File

@ -430,7 +430,6 @@ class fpdb:
self.status_bar.set_text("Status: Connected to %s database named %s on host %s" % (self.db.get_backend_name(),self.db.fdb.database, self.db.fdb.host))
# Database connected to successfully, load queries to pass on to other classes
self.querydict = FpdbSQLQueries.FpdbSQLQueries(self.db.get_backend_name())
self.db.connection.rollback()
#end def load_profile
@ -477,7 +476,7 @@ class fpdb:
def tab_bulk_import(self, widget, data=None):
"""opens a tab for bulk importing"""
#print "start of tab_bulk_import"
new_import_thread=GuiBulkImport.GuiBulkImport(self.settings, self.config)
new_import_thread = GuiBulkImport.GuiBulkImport(self.settings, self.config, self.sql)
self.threads.append(new_import_thread)
bulk_tab=new_import_thread.get_vbox()
self.add_and_display_tab(bulk_tab, "Bulk Import")

View File

@ -54,11 +54,13 @@ except:
class Importer:
def __init__(self, caller, settings, config):
def __init__(self, caller, settings, config, sql = None):
"""Constructor"""
self.settings = settings
self.caller = caller
self.config = config
self.sql = sql
self.database = None # database will be the main db interface eventually
self.filelist = {}
self.dirlist = {}
@ -76,7 +78,7 @@ class Importer:
self.settings.setdefault("minPrint", 30)
self.settings.setdefault("handCount", 0)
self.database = Database.Database(self.config) # includes .connection and .sql variables
self.database = Database.Database(self.config, sql = self.sql) # includes .connection and .sql variables
self.NEWIMPORT = False
self.allow_hudcache_rebuild = False

View File

@ -15,15 +15,20 @@
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
#methods that are specific to holdem but not trivial
#parses an in-memory fpdb hand history and calls db routine to store it
import sys
import fpdb_simple
import Database
from time import time, strftime
#parses a holdem hand
def mainParser(settings, siteID, category, hand, config, db = None):
#print "mainparser"
# fdb is not used now - to be removed ...
t0 = time()
#print "mainparser"
backend = settings['db-backend']
@ -51,7 +56,6 @@ def mainParser(settings, siteID, category, hand, config, db = None):
if line[-2:] == "$0": continue
smallBlindLine = i
break
#print "small blind line:",smallBlindLine
gametypeID = fpdb_simple.recogniseGametypeID(backend, db, db.get_cursor(), hand[0], hand[smallBlindLine], siteID, category, isTourney)
if isTourney:
@ -65,6 +69,17 @@ def mainParser(settings, siteID, category, hand, config, db = None):
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(db.get_cursor(), siteID, buyin, fee, knockout, rebuyOrAddon)
else:
siteTourneyNo = -1
buyin = -1
fee = -1
entries = -1
prizepool = -1
knockout = 0
tourneyStartTime= None
rebuyOrAddon = -1
tourneyTypeId = 1
fpdb_simple.isAlreadyInDB(db.get_cursor(), gametypeID, siteHandNo)
@ -145,63 +160,25 @@ def mainParser(settings, siteID, category, hand, config, db = None):
, allIns, actionTypeByNo, winnings, totalWinnings, None
, actionTypes, actionAmounts, antes)
#print "parse: hand data prepared" # only reads up to here apart from inserting new players
try:
db.commit() # need to commit new players as different db connection used
# for other writes. maybe this will change maybe not ...
except:
print "parse: error during rollback: " + str(sys.exc_value)
print "parse: error during commit: " + str(sys.exc_value)
# Following code writes hands to database and commits (or rolls back if there is an error)
try:
if isTourney:
ranks = map(lambda x: 0, names) # create an array of 0's equal to the length of names
payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee)
if base == "hold":
result = db.tourney_holdem_omaha(
config, settings, base, category, siteTourneyNo, buyin
# save data structures in a HandToWrite instance and then insert into database:
htw = Database.HandToWrite()
htw.set_all( config, settings, base, category, siteTourneyNo, buyin
, fee, knockout, entries, prizepool, tourneyStartTime
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
, isTourney, tourneyTypeId, siteID, siteHandNo
, gametypeID, handStartTime, names, playerIDs, startCashes
, positions, cardValues, cardSuits, boardValues, boardSuits
, positions, antes, cardValues, cardSuits, boardValues, boardSuits
, winnings, rakes, actionTypes, allIns, actionAmounts
, actionNos, hudImportData, maxSeats, tableName, seatNos)
elif base == "stud":
result = db.tourney_stud(
config, settings, base, category, siteTourneyNo
, buyin, fee, knockout, entries, prizepool, tourneyStartTime
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
, gametypeID, handStartTime, names, playerIDs, startCashes
, antes, cardValues, cardSuits, winnings, rakes, actionTypes
, allIns, actionAmounts, actionNos, hudImportData, maxSeats
, tableName, seatNos)
else:
raise fpdb_simple.FpdbError("unrecognised category")
else:
if base == "hold":
result = db.ring_holdem_omaha(
config, settings, base, category, siteHandNo
, gametypeID, handStartTime, names, playerIDs
, startCashes, positions, cardValues, cardSuits
, boardValues, boardSuits, winnings, rakes
, actionTypes, allIns, actionAmounts, actionNos
, hudImportData, maxSeats, tableName, seatNos)
elif base == "stud":
result = db.ring_stud(
config, settings, base, category, siteHandNo, gametypeID
, handStartTime, names, playerIDs, startCashes, antes
, cardValues, cardSuits, winnings, rakes, actionTypes, allIns
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
, seatNos)
else:
raise fpdb_simple.FpdbError ("unrecognised category")
db.commit()
except:
print "Error storing hand: " + str(sys.exc_value)
db.rollback()
result = db.store_the_hand(htw)
t9 = time()
#print "parse and save=(%4.3f)" % (t9-t0)
return result