Merge branch 'master' of git://git.assembla.com/free_poker_tools
Conflicts: pyfpdb/Database.py
This commit is contained in:
commit
2a3a5f0601
|
@ -452,7 +452,7 @@ class Database:
|
||||||
|
|
||||||
def get_player_id(self, config, site, player_name):
|
def get_player_id(self, config, site, player_name):
|
||||||
c = self.connection.cursor()
|
c = self.connection.cursor()
|
||||||
c.execute(self.sql.query['get_player_id'], {'player': player_name, 'site': site})
|
c.execute(self.sql.query['get_player_id'], (player_name, site))
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
if row:
|
if row:
|
||||||
return row[0]
|
return row[0]
|
||||||
|
@ -813,9 +813,11 @@ class Database:
|
||||||
self.fillDefaultData()
|
self.fillDefaultData()
|
||||||
self.commit()
|
self.commit()
|
||||||
except:
|
except:
|
||||||
print "Error creating tables: ", str(sys.exc_value)
|
#print "Error creating tables: ", str(sys.exc_value)
|
||||||
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||||
|
print "***Error creating tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||||
self.rollback()
|
self.rollback()
|
||||||
raise fpdb_simple.FpdbError( "Error creating tables " + str(sys.exc_value) )
|
raise
|
||||||
#end def disconnect
|
#end def disconnect
|
||||||
|
|
||||||
def drop_tables(self):
|
def drop_tables(self):
|
||||||
|
@ -845,8 +847,9 @@ class Database:
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
except:
|
except:
|
||||||
print "Error dropping tables: " + str(sys.exc_value)
|
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||||
raise fpdb_simple.FpdbError( "Error dropping tables " + str(sys.exc_value) )
|
self.rollback()
|
||||||
|
raise
|
||||||
#end def drop_tables
|
#end def drop_tables
|
||||||
|
|
||||||
def createAllIndexes(self):
|
def createAllIndexes(self):
|
||||||
|
@ -918,7 +921,10 @@ class Database:
|
||||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('Everleaf', 'USD')")
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('Everleaf', 'USD')")
|
||||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('Win2day', 'USD')")
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('Win2day', 'USD')")
|
||||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('Absolute', 'USD')")
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('Absolute', 'USD')")
|
||||||
c.execute("INSERT INTO TourneyTypes VALUES (DEFAULT, 1, 0, 0, 0, False);")
|
if self.backend == self.SQLITE:
|
||||||
|
c.execute("INSERT INTO TourneyTypes VALUES (NULL, 1, 0, 0, 0, 0);")
|
||||||
|
else:
|
||||||
|
c.execute("INSERT INTO TourneyTypes VALUES (DEFAULT, 1, 0, 0, 0, False);")
|
||||||
#c.execute("""INSERT INTO TourneyTypes
|
#c.execute("""INSERT INTO TourneyTypes
|
||||||
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
||||||
# (1,0,0,0,?)""",(False,) )
|
# (1,0,0,0,?)""",(False,) )
|
||||||
|
@ -1795,6 +1801,8 @@ if __name__=="__main__":
|
||||||
print "database connection object = ", db_connection.connection
|
print "database connection object = ", db_connection.connection
|
||||||
print "database type = ", db_connection.type
|
print "database type = ", db_connection.type
|
||||||
|
|
||||||
|
db_connection.recreate_tables()
|
||||||
|
|
||||||
h = db_connection.get_last_hand()
|
h = db_connection.get_last_hand()
|
||||||
print "last hand = ", h
|
print "last hand = ", h
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
#In the "official" distribution you can find the license in
|
#In the "official" distribution you can find the license in
|
||||||
#agpl-3.0.txt in the docs folder of the package.
|
#agpl-3.0.txt in the docs folder of the package.
|
||||||
|
|
||||||
|
#fpdb modules
|
||||||
|
import Card
|
||||||
|
|
||||||
class DerivedStats():
|
class DerivedStats():
|
||||||
def __init__(self, hand):
|
def __init__(self, hand):
|
||||||
self.hand = hand
|
self.hand = hand
|
||||||
|
@ -88,6 +91,70 @@ class DerivedStats():
|
||||||
self.street3CheckCallRaiseDone = 0
|
self.street3CheckCallRaiseDone = 0
|
||||||
self.street4CheckCallRaiseChance = 0
|
self.street4CheckCallRaiseChance = 0
|
||||||
self.street4CheckCallRaiseDone = 0
|
self.street4CheckCallRaiseDone = 0
|
||||||
|
|
||||||
|
self.hands = {}
|
||||||
|
self.handsplayers = {}
|
||||||
|
|
||||||
def getStats():
|
def getStats(self, hand):
|
||||||
pass
|
|
||||||
|
for player in hand.players:
|
||||||
|
self.handsplayers[player[1]] = {}
|
||||||
|
|
||||||
|
self.assembleHands(self.hand)
|
||||||
|
self.assembleHandsPlayers(self.hand)
|
||||||
|
|
||||||
|
print "hands =", self.hands
|
||||||
|
print "handsplayers =", self.handsplayers
|
||||||
|
|
||||||
|
def assembleHands(self, hand):
|
||||||
|
self.hands['tableName'] = hand.tablename
|
||||||
|
self.hands['siteHandNo'] = hand.handid
|
||||||
|
self.hands['gametypeId'] = None # Leave None, handled later after checking db
|
||||||
|
self.hands['handStart'] = hand.starttime # format this!
|
||||||
|
self.hands['importTime'] = None
|
||||||
|
self.hands['seats'] = self.countPlayers(hand)
|
||||||
|
self.hands['maxSeats'] = hand.maxseats
|
||||||
|
self.hands['boardcard1'] = None
|
||||||
|
self.hands['boardcard2'] = None
|
||||||
|
self.hands['boardcard3'] = None
|
||||||
|
self.hands['boardcard4'] = None
|
||||||
|
self.hands['boardcard5'] = None
|
||||||
|
|
||||||
|
boardCard = 1
|
||||||
|
for street in hand.communityStreets:
|
||||||
|
for card in hand.board[street]:
|
||||||
|
self.hands['boardcard%s' % str(boardCard)] = Card.encodeCard(card)
|
||||||
|
boardCard += 1
|
||||||
|
|
||||||
|
def assembleHandsPlayers(self, hand):
|
||||||
|
self.vpip(self.hand)
|
||||||
|
for i, street in enumerate(hand.actionStreets[1:]):
|
||||||
|
self.aggr(self.hand, i)
|
||||||
|
|
||||||
|
def vpip(self, hand):
|
||||||
|
vpipers = set()
|
||||||
|
for act in hand.actions[hand.actionStreets[1]]:
|
||||||
|
if act[1] in ('calls','bets', 'raises'):
|
||||||
|
vpipers.add(act[0])
|
||||||
|
|
||||||
|
for player in hand.players:
|
||||||
|
if player[1] in vpipers:
|
||||||
|
self.handsplayers[player[1]]['vpip'] = True
|
||||||
|
else:
|
||||||
|
self.handsplayers[player[1]]['vpip'] = False
|
||||||
|
self.hands['playersVpi'] = len(vpipers)
|
||||||
|
|
||||||
|
def aggr(self, hand, i):
|
||||||
|
aggrers = set()
|
||||||
|
for act in hand.actions[hand.actionStreets[i]]:
|
||||||
|
if act[1] in ('completes', 'raises'):
|
||||||
|
aggrers.add(act[0])
|
||||||
|
|
||||||
|
for player in hand.players:
|
||||||
|
if player[1] in aggrers:
|
||||||
|
self.handsplayers[player[1]]['street%sAggr' % i] = True
|
||||||
|
else:
|
||||||
|
self.handsplayers[player[1]]['street%sAggr' % i] = False
|
||||||
|
|
||||||
|
def countPlayers(self, hand):
|
||||||
|
pass
|
|
@ -74,7 +74,7 @@ class GuiBulkImport():
|
||||||
cb_hmodel = self.cb_drophudcache.get_model()
|
cb_hmodel = self.cb_drophudcache.get_model()
|
||||||
cb_hindex = self.cb_drophudcache.get_active()
|
cb_hindex = self.cb_drophudcache.get_active()
|
||||||
|
|
||||||
self.lab_info.set_text("Importing")
|
self.lab_info.set_text("Importing") # doesn't display :-(
|
||||||
if cb_index:
|
if cb_index:
|
||||||
self.importer.setDropIndexes(cb_model[cb_index][0])
|
self.importer.setDropIndexes(cb_model[cb_index][0])
|
||||||
else:
|
else:
|
||||||
|
@ -95,6 +95,13 @@ class GuiBulkImport():
|
||||||
print 'GuiBulkImport.load done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %.0f/sec'\
|
print 'GuiBulkImport.load done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %.0f/sec'\
|
||||||
% (stored, dups, partial, errs, ttime, (stored+0.0) / ttime)
|
% (stored, dups, partial, errs, ttime, (stored+0.0) / ttime)
|
||||||
self.importer.clearFileList()
|
self.importer.clearFileList()
|
||||||
|
if self.n_hands_in_db == 0 and stored > 0:
|
||||||
|
self.cb_dropindexes.set_sensitive(True)
|
||||||
|
self.cb_dropindexes.set_active(0)
|
||||||
|
self.lab_drop.set_sensitive(True)
|
||||||
|
self.cb_drophudcache.set_sensitive(True)
|
||||||
|
self.cb_drophudcache.set_active(0)
|
||||||
|
self.lab_hdrop.set_sensitive(True)
|
||||||
|
|
||||||
self.lab_info.set_text("Import finished")
|
self.lab_info.set_text("Import finished")
|
||||||
except:
|
except:
|
||||||
|
@ -213,11 +220,11 @@ class GuiBulkImport():
|
||||||
self.cbfilter.show()
|
self.cbfilter.show()
|
||||||
|
|
||||||
# label - drop hudcache
|
# label - drop hudcache
|
||||||
self.lab_drop = gtk.Label("Drop HudCache:")
|
self.lab_hdrop = gtk.Label("Drop HudCache:")
|
||||||
self.table.attach(self.lab_drop, 3, 4, 2, 3, xpadding = 0, ypadding = 0, yoptions=gtk.SHRINK)
|
self.table.attach(self.lab_hdrop, 3, 4, 2, 3, xpadding = 0, ypadding = 0, yoptions=gtk.SHRINK)
|
||||||
self.lab_drop.show()
|
self.lab_hdrop.show()
|
||||||
self.lab_drop.set_justify(gtk.JUSTIFY_RIGHT)
|
self.lab_hdrop.set_justify(gtk.JUSTIFY_RIGHT)
|
||||||
self.lab_drop.set_alignment(1.0, 0.5)
|
self.lab_hdrop.set_alignment(1.0, 0.5)
|
||||||
|
|
||||||
# ComboBox - drop hudcache
|
# ComboBox - drop hudcache
|
||||||
self.cb_drophudcache = gtk.combo_box_new_text()
|
self.cb_drophudcache = gtk.combo_box_new_text()
|
||||||
|
@ -258,7 +265,7 @@ class GuiBulkImport():
|
||||||
self.lab_drop.set_sensitive(False)
|
self.lab_drop.set_sensitive(False)
|
||||||
self.cb_drophudcache.set_active(2)
|
self.cb_drophudcache.set_active(2)
|
||||||
self.cb_drophudcache.set_sensitive(False)
|
self.cb_drophudcache.set_sensitive(False)
|
||||||
self.lab_drop.set_sensitive(False)
|
self.lab_hdrop.set_sensitive(False)
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
"""main can also be called in the python interpreter, by supplying the command line as the argument."""
|
"""main can also be called in the python interpreter, by supplying the command line as the argument."""
|
||||||
|
|
|
@ -60,7 +60,7 @@ class HandHistoryConverter():
|
||||||
out_dir = os.path.dirname(self.out_path)
|
out_dir = os.path.dirname(self.out_path)
|
||||||
if not os.path.isdir(out_dir):
|
if not os.path.isdir(out_dir):
|
||||||
logging.info("Creatin directory '%s'" % out_dir)
|
logging.info("Creatin directory '%s'" % out_dir)
|
||||||
os.makedirs(out_dir)
|
# os.makedirs(out_dir)
|
||||||
self.out_fh = open(self.out_path, 'w')
|
self.out_fh = open(self.out_path, 'w')
|
||||||
|
|
||||||
self.sitename = sitename
|
self.sitename = sitename
|
||||||
|
@ -204,7 +204,9 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
|
||||||
logging.info("Unsupported game type: %s" % gametype)
|
logging.info("Unsupported game type: %s" % gametype)
|
||||||
|
|
||||||
if hand:
|
if hand:
|
||||||
|
# uncomment these to calculate some stats
|
||||||
# print hand
|
# print hand
|
||||||
|
# hand.stats.getStats(hand)
|
||||||
hand.writeHand(self.out_fh)
|
hand.writeHand(self.out_fh)
|
||||||
return hand
|
return hand
|
||||||
else:
|
else:
|
||||||
|
|
5151
pyfpdb/SQL.py
5151
pyfpdb/SQL.py
File diff suppressed because it is too large
Load Diff
|
@ -155,7 +155,7 @@ class fpdb_db:
|
||||||
return (self.host, self.database, self.user, self.password)
|
return (self.host, self.database, self.user, self.password)
|
||||||
#end def get_db_info
|
#end def get_db_info
|
||||||
|
|
||||||
def getLastInsertId(self):
|
def getLastInsertId(self, cursor=None):
|
||||||
try:
|
try:
|
||||||
if self.backend == self.MYSQL_INNODB:
|
if self.backend == self.MYSQL_INNODB:
|
||||||
ret = self.db.insert_id()
|
ret = self.db.insert_id()
|
||||||
|
@ -177,9 +177,7 @@ class fpdb_db:
|
||||||
else:
|
else:
|
||||||
ret = row[0]
|
ret = row[0]
|
||||||
elif self.backend == fpdb_db.SQLITE:
|
elif self.backend == fpdb_db.SQLITE:
|
||||||
# don't know how to do this in sqlite
|
ret = cursor.lastrowid
|
||||||
print "getLastInsertId(): not coded for sqlite yet"
|
|
||||||
ret = -1
|
|
||||||
else:
|
else:
|
||||||
print "getLastInsertId(): unknown backend ", self.backend
|
print "getLastInsertId(): unknown backend ", self.backend
|
||||||
ret = -1
|
ret = -1
|
||||||
|
|
|
@ -48,37 +48,6 @@ class FpdbError(Exception):
|
||||||
self.value = value
|
self.value = value
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
# gets value for last auto-increment key generated
|
|
||||||
# returns -1 if a problem occurs
|
|
||||||
def getLastInsertId(backend, conn, cursor):
|
|
||||||
if backend == MYSQL_INNODB:
|
|
||||||
ret = conn.insert_id()
|
|
||||||
if ret < 1 or ret > 999999999:
|
|
||||||
print "getLastInsertId(): problem fetching insert_id? ret=", ret
|
|
||||||
ret = -1
|
|
||||||
elif backend == PGSQL:
|
|
||||||
# some options:
|
|
||||||
# currval(hands_id_seq) - use name of implicit seq here
|
|
||||||
# lastval() - still needs sequences set up?
|
|
||||||
# insert ... returning is useful syntax (but postgres specific?)
|
|
||||||
# see rules (fancy trigger type things)
|
|
||||||
cursor.execute ("SELECT lastval()")
|
|
||||||
row = cursor.fetchone()
|
|
||||||
if not row:
|
|
||||||
print "getLastInsertId(%s): problem fetching lastval? row=" % seq, row
|
|
||||||
ret = -1
|
|
||||||
else:
|
|
||||||
ret = row[0]
|
|
||||||
elif backend == SQLITE:
|
|
||||||
# don't know how to do this in sqlite
|
|
||||||
print "getLastInsertId(): not coded for sqlite yet"
|
|
||||||
ret = -1
|
|
||||||
else:
|
|
||||||
print "getLastInsertId(): unknown backend ", backend
|
|
||||||
ret = -1
|
|
||||||
return ret
|
|
||||||
#end def getLastInsertId
|
|
||||||
|
|
||||||
#returns an array of the total money paid. intending to add rebuys/addons here
|
#returns an array of the total money paid. intending to add rebuys/addons here
|
||||||
def calcPayin(count, buyin, fee):
|
def calcPayin(count, buyin, fee):
|
||||||
|
|
42
utils/fix_table_desc.py
Normal file
42
utils/fix_table_desc.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
desc = """
|
||||||
|
+-------------+---------------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+-------------+---------------------+------+-----+---------+----------------+
|
||||||
|
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
|
||||||
|
| tourneyId | int(10) unsigned | NO | MUL | NULL | |
|
||||||
|
| playerId | int(10) unsigned | NO | MUL | NULL | |
|
||||||
|
| payinAmount | int(11) | NO | | NULL | |
|
||||||
|
| rank | int(11) | NO | | NULL | |
|
||||||
|
| winnings | int(11) | NO | | NULL | |
|
||||||
|
| comment | text | YES | | NULL | |
|
||||||
|
| commentTs | datetime | YES | | NULL | |
|
||||||
|
+-------------+---------------------+------+-----+---------+----------------+
|
||||||
|
"""
|
||||||
|
|
||||||
|
table = """
|
||||||
|
{| border="1"
|
||||||
|
|+Gametypes Table
|
||||||
|
"""
|
||||||
|
|
||||||
|
# get rid of the verticle spacing and clean up
|
||||||
|
desc = re.sub("[\+\-]+", "", desc)
|
||||||
|
desc = re.sub("^\n+", "", desc) # there's probably a better way
|
||||||
|
desc = re.sub("\n\n", "\n", desc)
|
||||||
|
|
||||||
|
# the first line is the header info
|
||||||
|
temp, desc = re.split("\n", desc, 1)
|
||||||
|
temp = re.sub("\|", "!", temp)
|
||||||
|
temp = re.sub(" !", " !!", temp)
|
||||||
|
table += temp + " Comments\n"
|
||||||
|
|
||||||
|
# the rest is he body of the table
|
||||||
|
for line in re.split("\n", desc):
|
||||||
|
line = re.sub(" \|", " ||", line)
|
||||||
|
table += "|+\n" + line + "\n"
|
||||||
|
|
||||||
|
table += "|}\n"
|
||||||
|
print table
|
Loading…
Reference in New Issue
Block a user