Merge branch 'chaz' of git://github.com/ChazDazzle/fpdb-chaz

This commit is contained in:
Worros 2011-02-17 11:28:44 +08:00
commit e4a3de1272
7 changed files with 332 additions and 121 deletions

View File

@ -125,7 +125,8 @@ class Database:
{'tab':'Gametypes', 'col':'siteId', 'drop':0}
, {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
#, {'tab':'Hands', 'col':'siteHandNo', 'drop':0} unique indexes not dropped
, {'tab':'HandsActions', 'col':'handsPlayerId', 'drop':0}
, {'tab':'HandsActions', 'col':'handId', 'drop':1}
, {'tab':'HandsActions', 'col':'playerId', 'drop':1}
, {'tab':'HandsActions', 'col':'actionId', 'drop':1}
, {'tab':'HandsPlayers', 'col':'handId', 'drop':1}
, {'tab':'HandsPlayers', 'col':'playerId', 'drop':1}
@ -150,7 +151,8 @@ class Database:
, {'tab':'HandsPlayers', 'col':'handId', 'drop':0}
, {'tab':'HandsPlayers', 'col':'playerId', 'drop':0}
, {'tab':'HandsPlayers', 'col':'tourneysPlayersId', 'drop':0}
, {'tab':'HandsActions', 'col':'handsPlayerId', 'drop':0}
, {'tab':'HandsActions', 'col':'handId', 'drop':0}
, {'tab':'HandsActions', 'col':'playerId', 'drop':0}
, {'tab':'HandsActions', 'col':'actionId', 'drop':1}
, {'tab':'HudCache', 'col':'gametypeId', 'drop':1}
, {'tab':'HudCache', 'col':'playerId', 'drop':0}
@ -174,7 +176,8 @@ class Database:
, {'fktab':'HandsPlayers', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
, {'fktab':'HandsPlayers', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
, {'fktab':'HandsPlayers', 'fkcol':'tourneysPlayersId','rtab':'TourneysPlayers','rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'handsPlayerId', 'rtab':'HandsPlayers', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'actionId', 'rtab':'Actions', 'rcol':'id', 'drop':1}
, {'fktab':'HudCache', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
, {'fktab':'HudCache', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':0}
@ -184,7 +187,8 @@ class Database:
{'fktab':'Hands', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
, {'fktab':'HandsPlayers', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
, {'fktab':'HandsPlayers', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'handsPlayerId', 'rtab':'HandsPlayers', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
, {'fktab':'HandsActions', 'fkcol':'actionId', 'rtab':'Actions', 'rcol':'id', 'drop':1}
, {'fktab':'HudCache', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
, {'fktab':'HudCache', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':0}
@ -1727,10 +1731,11 @@ class Database:
c.execute(q, (
p['tableName'],
p['gametypeId'],
p['siteHandNo'],
p['tourneyId'],
p['startTime'],
p['gametypeId'],
p['sessionId'],
p['startTime'],
datetime.utcnow(), #importtime
p['seats'],
p['maxSeats'],
@ -1760,7 +1765,7 @@ class Database:
return self.get_last_insert_id(c)
# def storeHand
def storeHandsPlayers(self, hid, pids, pdata, printdata = False):
def storeHandsPlayers(self, hid, pids, pdata, hp_bulk = None, insert = False, printdata = False):
#print "DEBUG: %s %s %s" %(hid, pids, pdata)
if printdata:
import pprint
@ -1768,7 +1773,6 @@ class Database:
pp.pprint(pdata)
inserts = []
hpid = {}
for p in pdata:
inserts.append( (hid,
pids[p],
@ -1874,23 +1878,16 @@ class Database:
pdata[p]['street4Raises']
) )
q = self.sql.query['store_hands_players']
q = q.replace('%s', self.sql.query['placeholder'])
if insert:
hp_bulk += inserts
q = self.sql.query['store_hands_players']
q = q.replace('%s', self.sql.query['placeholder'])
c = self.get_cursor()
c.executemany(q, hp_bulk)
return inserts
#print "DEBUG: inserts: %s" %inserts
#print "DEBUG: q: %s" % q
c = self.get_cursor()
if self.import_options['saveActions']:
for r in inserts:
c.execute(q, r)
hpid[(r[0], r[1])] = self.get_last_insert_id(c)
else:
c.executemany(q, inserts)
return hpid
def storeHandsActions(self, hid, pids, hpid, adata, printdata = False):
def storeHandsActions(self, hid, pids, adata, ha_bulk = None, insert = False, printdata = False):
#print "DEBUG: %s %s %s" %(hid, pids, adata)
# This can be used to generate test data. Currently unused
@ -1901,8 +1898,8 @@ class Database:
inserts = []
for a in adata:
inserts.append( (hpid[(hid, pids[adata[a]['player']])],
#self.getHandsPlayerId(self.hid, pids[adata[a]['player']]),
inserts.append( (hid,
pids[adata[a]['player']],
adata[a]['street'],
adata[a]['actionNo'],
adata[a]['streetActionNo'],
@ -1915,11 +1912,14 @@ class Database:
adata[a]['allIn']
) )
q = self.sql.query['store_hands_actions']
q = q.replace('%s', self.sql.query['placeholder'])
if insert:
ha_bulk += inserts
q = self.sql.query['store_hands_actions']
q = q.replace('%s', self.sql.query['placeholder'])
c = self.get_cursor()
c.executemany(q, ha_bulk)
c = self.get_cursor()
c.executemany(q, inserts)
return inserts
def storeHudCache(self, gid, pids, starttime, pdata):
"""Update cached statistics. If update fails because no record exists, do an insert."""
@ -2068,10 +2068,9 @@ class Database:
pass
def storeSessionsCache(self, pids, startTime, game, pdata):
"""Update cached sessions. If update fails because no record exists, do an insert"""
"""Update cached sessions. If no record exists, do an insert"""
THRESHOLD = timedelta(seconds=int(self.sessionTimeout * 60))
bigBet = int(Decimal(game['bb'])*200)
select_sessionscache = self.sql.query['select_sessionscache']
select_sessionscache = select_sessionscache.replace('%s', self.sql.query['placeholder'])
@ -2094,6 +2093,9 @@ class Database:
delete_sessions = self.sql.query['delete_sessions']
delete_sessions = delete_sessions.replace('%s', self.sql.query['placeholder'])
update_hands_sessionid = self.sql.query['update_hands_sessionid']
update_hands_sessionid = update_hands_sessionid.replace('%s', self.sql.query['placeholder'])
#Grab playerIds using hero names in HUD_Config.xml
try:
# derive list of program owner's player ids
@ -2123,29 +2125,32 @@ class Database:
if (game['type']=='ring'): line[0] = 1 # count ring hands
if (game['type']=='tour'): line[1] = 1 # count tour hands
if (game['type']=='ring'): line[2] = pdata[p]['totalProfit'] #sum of profit
if (game['type']=='ring'): line[3] = 0 #float(Decimal(pdata[p]['totalProfit'])/Decimal(bigBet)) #sum of big bets won
if (game['type']=='ring' and game['currency']=='USD'): line[2] = pdata[p]['totalProfit'] #sum of ring profit in USD
if (game['type']=='ring' and game['currency']=='EUR'): line[3] = pdata[p]['totalProfit'] #sum of ring profit in EUR
line[4] = startTime
inserts.append(line)
cursor = self.get_cursor()
id = None
for row in inserts:
threshold = []
threshold.append(row[-1]-THRESHOLD)
threshold.append(row[-1]+THRESHOLD)
cursor.execute(select_sessionscache, threshold)
num = cursor.rowcount
session_records = cursor.fetchall()
num = len(session_records)
if (num == 1):
id = session_records[0][0] #grab the sessionId
# Try to do the update first:
#print "DEBUG: found 1 record to update"
update_mid = row + row[-1:]
cursor.execute(select_sessionscache_mid, update_mid[-2:])
mid = cursor.rowcount
mid = len(cursor.fetchall())
if (mid == 0):
update_startend = row[-1:] + row + threshold
cursor.execute(select_sessionscache_start, update_startend[-3:])
start = cursor.rowcount
start = len(cursor.fetchall())
if (start == 0):
#print "DEBUG:", start, " start record found. Update stats and start time"
cursor.execute(update_sessionscache_end, update_startend)
@ -2156,37 +2161,36 @@ class Database:
#print "DEBUG: update stats mid-session"
cursor.execute(update_sessionscache_mid, update_mid)
elif (num > 1):
session_ids = [session_records[0][0], session_records[1][0]]
session_ids.sort()
# Multiple matches found - merge them into one session and update:
#print "DEBUG:", num, "matches found"
cursor.execute(merge_sessionscache, threshold)
# - Obtain the session start and end times for the new combined session
cursor.execute(merge_sessionscache, session_ids)
merge = cursor.fetchone()
cursor.execute(delete_sessions, threshold)
# - Delete the old records
for id in session_ids:
cursor.execute(delete_sessions, id)
# - Insert the new updated record
cursor.execute(insert_sessionscache, merge)
# - Obtain the new sessionId and write over the old ids in Hands
id = self.get_last_insert_id(cursor) #grab the sessionId
update_hands = [id] + session_ids
cursor.execute(update_hands_sessionid, update_hands)
# - Update the newly combined record in SessionsCache with data from this hand
update_mid = row + row[-1:]
cursor.execute(select_sessionscache_mid, update_mid[-2:])
mid = cursor.rowcount
if (mid == 0):
update_startend = row[-1:] + row + threshold
cursor.execute(select_sessionscache_start, update_startend[-3:])
start = cursor.rowcount
if (start == 0):
#print "DEBUG:", start, " start record found. Update stats and start time"
cursor.execute(update_sessionscache_end, update_startend)
else:
#print "DEBUG: 1 end record found. Update stats and end time time"
cursor.execute(update_sessionscache_start, update_startend)
else:
#print "DEBUG: update stats mid-session"
cursor.execute(update_sessionscache_mid, update_mid)
cursor.execute(update_sessionscache_mid, update_mid)
elif (num == 0):
# No matches found, insert new session:
insert = row + row[-1:]
insert = insert[-2:] + insert[:-2]
#print "DEBUG: No matches found. Insert record", insert
cursor.execute(insert_sessionscache, insert)
id = self.get_last_insert_id(cursor) #grab the sessionId
else:
# Something bad happened
pass
pass
return id
def isDuplicate(self, gametypeID, siteHandNo):
dup = False

View File

@ -115,6 +115,7 @@ class DerivedStats():
self.hands['tableName'] = hand.tablename
self.hands['siteHandNo'] = hand.handid
self.hands['gametypeId'] = None # Leave None, handled later after checking db
self.hands['sessionId'] = None # Leave None, added later if caching sessions
self.hands['startTime'] = hand.startTime # format this!
self.hands['importTime'] = None
self.hands['seats'] = self.countPlayers(hand)

View File

@ -211,7 +211,7 @@ Left-Drag to Move"
</layout>
</site>
<site enabled="False"
<site enabled="True"
site_name="Everleaf"
table_finder="Everleaf.exe"
screen_name="Hero"
@ -255,7 +255,7 @@ Left-Drag to Move"
</layout>
</site>
<site enabled="False"
<site enabled="True"
site_name="Win2day"
table_finder="Win2day.exe"
screen_name="Hero"
@ -300,7 +300,7 @@ Left-Drag to Move"
</site>
<site enabled="False"
<site enabled="True"
site_name="Absolute"
table_finder="AbsolutePoker.exe"
screen_name="Hero"
@ -345,7 +345,7 @@ Left-Drag to Move"
</site>
<site enabled="False"
<site enabled="True"
site_name="PartyPoker"
table_finder="PartyGaming.exe"
screen_name="Hero"
@ -390,7 +390,7 @@ Left-Drag to Move"
</site>
<site enabled="False"
<site enabled="True"
site_name="Betfair"
table_finder="Betfair Poker.exe"
screen_name="Hero"
@ -433,6 +433,188 @@ Left-Drag to Move"
<location seat="9" x="70" y="53"> </location>
</layout>
</site>
<site HH_path="C:/Program Files/Carbon Poker/HandHistory/Hero/" converter="CarbonToFpdb" decoder="everleaf_decode_table" enabled="True" screen_name="Hero" site_name="Carbon" site_path="C:/Program Files/Carbin/" supported_games="holdem" table_finder="Carbon Poker.exe">
<layout fav_seat="0" height="547" max="8" width="794">
<location seat="1" x="640" y="64"> </location>
<location seat="2" x="650" y="230"> </location>
<location seat="3" x="650" y="385"> </location>
<location seat="4" x="588" y="425"> </location>
<location seat="5" x="92" y="425"> </location>
<location seat="6" x="0" y="373"> </location>
<location seat="7" x="0" y="223"> </location>
<location seat="8" x="25" y="50"> </location>
</layout>
<layout fav_seat="0" height="547" max="6" width="794">
<location seat="1" x="640" y="58"> </location>
<location seat="2" x="654" y="288"> </location>
<location seat="3" x="615" y="424"> </location>
<location seat="4" x="70" y="421"> </location>
<location seat="5" x="0" y="280"> </location>
<location seat="6" x="70" y="58"> </location>
</layout>
<layout fav_seat="0" height="547" max="2" width="794">
<location seat="1" x="651" y="288"> </location>
<location seat="2" x="10" y="288"> </location>
</layout>
<layout fav_seat="0" height="547" max="9" width="794">
<location seat="1" x="634" y="38"> </location>
<location seat="2" x="667" y="184"> </location>
<location seat="3" x="667" y="321"> </location>
<location seat="4" x="667" y="445"> </location>
<location seat="5" x="337" y="459"> </location>
<location seat="6" x="0" y="400"> </location>
<location seat="7" x="0" y="322"> </location>
<location seat="8" x="0" y="181"> </location>
<location seat="9" x="70" y="53"> </location>
</layout>
</site>
<site HH_path="C:/Program Files/OnGame Sking/HandHistory/Hero/" converter="OnGameToFpdb" decoder="everleaf_decode_table" enabled="True" screen_name="Hero" site_name="OnGame" site_path="C:/Program Files/OnGame/" supported_games="holdem" table_finder="OnGame.exe">
<layout fav_seat="0" height="547" max="8" width="794">
<location seat="1" x="640" y="64"> </location>
<location seat="2" x="650" y="230"> </location>
<location seat="3" x="650" y="385"> </location>
<location seat="4" x="588" y="425"> </location>
<location seat="5" x="92" y="425"> </location>
<location seat="6" x="0" y="373"> </location>
<location seat="7" x="0" y="223"> </location>
<location seat="8" x="25" y="50"> </location>
</layout>
<layout fav_seat="0" height="547" max="6" width="794">
<location seat="1" x="640" y="58"> </location>
<location seat="2" x="654" y="288"> </location>
<location seat="3" x="615" y="424"> </location>
<location seat="4" x="70" y="421"> </location>
<location seat="5" x="0" y="280"> </location>
<location seat="6" x="70" y="58"> </location>
</layout>
<layout fav_seat="0" height="547" max="2" width="794">
<location seat="1" x="651" y="288"> </location>
<location seat="2" x="10" y="288"> </location>
</layout>
<layout fav_seat="0" height="547" max="9" width="794">
<location seat="1" x="634" y="38"> </location>
<location seat="2" x="667" y="184"> </location>
<location seat="3" x="667" y="321"> </location>
<location seat="4" x="667" y="445"> </location>
<location seat="5" x="337" y="459"> </location>
<location seat="6" x="0" y="400"> </location>
<location seat="7" x="0" y="322"> </location>
<location seat="8" x="0" y="181"> </location>
<location seat="9" x="70" y="53"> </location>
</layout>
</site>
<site HH_path="C:/Program Files/PKR/HandHistory/Hero/" converter="PkrToFpdb" decoder="everleaf_decode_table" enabled="True" screen_name="Hero" site_name="PKR" site_path="C:/Program Files/PKR/" supported_games="holdem" table_finder="PKR.exe">
<layout fav_seat="0" height="547" max="8" width="794">
<location seat="1" x="640" y="64"> </location>
<location seat="2" x="650" y="230"> </location>
<location seat="3" x="650" y="385"> </location>
<location seat="4" x="588" y="425"> </location>
<location seat="5" x="92" y="425"> </location>
<location seat="6" x="0" y="373"> </location>
<location seat="7" x="0" y="223"> </location>
<location seat="8" x="25" y="50"> </location>
</layout>
<layout fav_seat="0" height="547" max="6" width="794">
<location seat="1" x="640" y="58"> </location>
<location seat="2" x="654" y="288"> </location>
<location seat="3" x="615" y="424"> </location>
<location seat="4" x="70" y="421"> </location>
<location seat="5" x="0" y="280"> </location>
<location seat="6" x="70" y="58"> </location>
</layout>
<layout fav_seat="0" height="547" max="2" width="794">
<location seat="1" x="651" y="288"> </location>
<location seat="2" x="10" y="288"> </location>
</layout>
<layout fav_seat="0" height="547" max="9" width="794">
<location seat="1" x="634" y="38"> </location>
<location seat="2" x="667" y="184"> </location>
<location seat="3" x="667" y="321"> </location>
<location seat="4" x="667" y="445"> </location>
<location seat="5" x="337" y="459"> </location>
<location seat="6" x="0" y="400"> </location>
<location seat="7" x="0" y="322"> </location>
<location seat="8" x="0" y="181"> </location>
<location seat="9" x="70" y="53"> </location>
</layout>
</site>
<site HH_path="C:/Program Files/iPoker/HandHistory/Hero/" converter="iPokerToFpdb" decoder="everleaf_decode_table" enabled="True" screen_name="Hero" site_name="iPoker" site_path="C:/Program Files/iPoker/" supported_games="holdem" table_finder="iPoker.exe">
<layout fav_seat="0" height="547" max="8" width="794">
<location seat="1" x="640" y="64"> </location>
<location seat="2" x="650" y="230"> </location>
<location seat="3" x="650" y="385"> </location>
<location seat="4" x="588" y="425"> </location>
<location seat="5" x="92" y="425"> </location>
<location seat="6" x="0" y="373"> </location>
<location seat="7" x="0" y="223"> </location>
<location seat="8" x="25" y="50"> </location>
</layout>
<layout fav_seat="0" height="547" max="6" width="794">
<location seat="1" x="640" y="58"> </location>
<location seat="2" x="654" y="288"> </location>
<location seat="3" x="615" y="424"> </location>
<location seat="4" x="70" y="421"> </location>
<location seat="5" x="0" y="280"> </location>
<location seat="6" x="70" y="58"> </location>
</layout>
<layout fav_seat="0" height="547" max="2" width="794">
<location seat="1" x="651" y="288"> </location>
<location seat="2" x="10" y="288"> </location>
</layout>
<layout fav_seat="0" height="547" max="9" width="794">
<location seat="1" x="634" y="38"> </location>
<location seat="2" x="667" y="184"> </location>
<location seat="3" x="667" y="321"> </location>
<location seat="4" x="667" y="445"> </location>
<location seat="5" x="337" y="459"> </location>
<location seat="6" x="0" y="400"> </location>
<location seat="7" x="0" y="322"> </location>
<location seat="8" x="0" y="181"> </location>
<location seat="9" x="70" y="53"> </location>
</layout>
</site>
<site HH_path="C:/Program Files/Winamax/HandHistory/Hero/" converter="WinamaxToFpdb" decoder="everleaf_decode_table" enabled="True" screen_name="Hero" site_name="Winamax" site_path="C:/Program Files/Winamax/" supported_games="holdem" table_finder="Winamax.exe">
<layout fav_seat="0" height="547" max="8" width="794">
<location seat="1" x="640" y="64"> </location>
<location seat="2" x="650" y="230"> </location>
<location seat="3" x="650" y="385"> </location>
<location seat="4" x="588" y="425"> </location>
<location seat="5" x="92" y="425"> </location>
<location seat="6" x="0" y="373"> </location>
<location seat="7" x="0" y="223"> </location>
<location seat="8" x="25" y="50"> </location>
</layout>
<layout fav_seat="0" height="547" max="6" width="794">
<location seat="1" x="640" y="58"> </location>
<location seat="2" x="654" y="288"> </location>
<location seat="3" x="615" y="424"> </location>
<location seat="4" x="70" y="421"> </location>
<location seat="5" x="0" y="280"> </location>
<location seat="6" x="70" y="58"> </location>
</layout>
<layout fav_seat="0" height="547" max="2" width="794">
<location seat="1" x="651" y="288"> </location>
<location seat="2" x="10" y="288"> </location>
</layout>
<layout fav_seat="0" height="547" max="9" width="794">
<location seat="1" x="634" y="38"> </location>
<location seat="2" x="667" y="184"> </location>
<location seat="3" x="667" y="321"> </location>
<location seat="4" x="667" y="445"> </location>
<location seat="5" x="337" y="459"> </location>
<location seat="6" x="0" y="400"> </location>
<location seat="7" x="0" y="322"> </location>
<location seat="8" x="0" y="181"> </location>
<location seat="9" x="70" y="53"> </location>
</layout>
</site>
</supported_sites>
<supported_games>

View File

@ -57,6 +57,7 @@ class Hand(object):
#log.debug( _("Hand.init(): handText is ") + str(handText) )
self.config = config
self.saveActions = self.config.get_import_parameters().get('saveActions')
self.cacheSessions = self.config.get_import_parameters().get("cacheSessions")
#log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log)
self.sitename = sitename
self.siteId = self.config.get_site_id(sitename)
@ -258,7 +259,7 @@ dealt whether they were seen in a 'dealt to' line
db.commit()
#end def prepInsert
def insert(self, db, printtest = False):
def insert(self, db, hp_data = None, ha_data = None, insert_data=False, printtest = False):
""" Function to insert Hand into database
Should not commit, and do minimal selects. Callers may want to cache commits
db: a connected Database object"""
@ -276,17 +277,26 @@ db: a connected Database object"""
hh['gametypeId'] = self.dbid_gt
# seats TINYINT NOT NULL,
hh['seats'] = len(self.dbid_pids)
hp = self.stats.getHandsPlayers()
if self.cacheSessions:
hh['sessionId'] = db.storeSessionsCache(self.dbid_pids, self.startTime, self.gametype, hp)
self.dbid_hands = db.storeHand(hh, printdata = printtest)
self.dbid_hpid = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids,
self.stats.getHandsPlayers(), printdata = printtest)
hp_inserts = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, hp,
insert=insert_data, hp_bulk = hp_data, printdata = printtest)
if self.saveActions:
db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.dbid_hpid,
self.stats.getHandsActions(), printdata = printtest)
ha_inserts = db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),
insert=insert_data, ha_bulk = ha_data, printdata = printtest)
else:
log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo'])
self.is_duplicate = True # i.e. don't update hudcache
raise FpdbHandDuplicate(hh['siteHandNo'])
return hp_inserts, ha_inserts
def updateHudCache(self, db):
db.storeHudCache(self.dbid_gt, self.dbid_pids, self.startTime, self.stats.getHandsPlayers())

View File

@ -346,6 +346,7 @@ class Sql:
siteHandNo BIGINT NOT NULL,
tourneyId INT UNSIGNED,
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
sessionId INT UNSIGNED,
startTime DATETIME NOT NULL,
importTime DATETIME NOT NULL,
seats TINYINT NOT NULL,
@ -383,6 +384,7 @@ class Sql:
siteHandNo BIGINT NOT NULL,
tourneyId INT,
gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
sessionId INT,
startTime timestamp without time zone NOT NULL,
importTime timestamp without time zone NOT NULL,
seats SMALLINT NOT NULL,
@ -419,6 +421,7 @@ class Sql:
siteHandNo INT NOT NULL,
tourneyId INT,
gametypeId INT NOT NULL,
sessionId INT,
startTime REAL NOT NULL,
importTime REAL NOT NULL,
seats INT NOT NULL,
@ -1028,7 +1031,8 @@ class Sql:
if db_server == 'mysql':
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
handsPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
street SMALLINT NOT NULL,
actionNo SMALLINT NOT NULL,
streetActionNo SMALLINT NOT NULL,
@ -1043,7 +1047,8 @@ class Sql:
elif db_server == 'postgresql':
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id BIGSERIAL, PRIMARY KEY (id),
handsPlayerId BIGINT, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
street SMALLINT,
actionNo SMALLINT,
streetActionNo SMALLINT,
@ -1057,7 +1062,8 @@ class Sql:
elif db_server == 'sqlite':
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id INTEGER PRIMARY KEY,
handsPlayerId BIGINT,
handId INT NOT NULL,
playerId INT NOT NULL,
street SMALLINT,
actionNo SMALLINT,
streetActionNo SMALLINT,
@ -1067,9 +1073,7 @@ class Sql:
amountCalled INT,
numDiscarded SMALLINT,
cardsDiscarded TEXT,
allIn BOOLEAN,
FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
FOREIGN KEY (actionId) REFERENCES Actions(id) ON DELETE CASCADE
allIn BOOLEAN
)"""
@ -1410,8 +1414,8 @@ class Sql:
sessionEnd DATETIME NOT NULL,
ringHDs INT NOT NULL,
tourHDs INT NOT NULL,
totalProfit INT NOT NULL,
bigBets FLOAT UNSIGNED NOT NULL)
ringProfitUSD INT NOT NULL,
ringProfitEUR INT NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgresql':
@ -1421,8 +1425,8 @@ class Sql:
sessionEnd REAL NOT NULL,
ringHDs INT NOT NULL,
tourHDs INT NOT NULL,
totalProfit INT NOT NULL,
bigBets FLOAT NOT NULL)
ringProfitUSD INT NOT NULL,
ringProfitEUR INT NOT NULL)
"""
elif db_server == 'sqlite':
self.query['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
@ -1431,8 +1435,8 @@ class Sql:
sessionEnd REAL NOT NULL,
ringHDs INT NOT NULL,
tourHDs INT NOT NULL,
totalProfit INT NOT NULL,
bigBets REAL UNSIGNED NOT NULL)
ringProfitUSD INT NOT NULL,
ringProfitEUR INT NOT NULL)
"""
if db_server == 'mysql':
@ -4281,12 +4285,13 @@ class Sql:
####################################
self.query['select_sessionscache'] = """
SELECT sessionStart,
SELECT id,
sessionStart,
sessionEnd,
ringHDs,
tourHDs,
totalProfit,
bigBets
ringProfitUSD,
ringProfitEUR
FROM SessionsCache
WHERE sessionEnd>=%s
AND sessionStart<=%s"""
@ -4296,8 +4301,8 @@ class Sql:
sessionEnd,
ringHDs,
tourHDs,
totalProfit,
bigBets
ringProfitUSD,
ringProfitEUR
FROM SessionsCache
WHERE sessionEnd>=%s
AND sessionStart<=%s"""
@ -4307,8 +4312,8 @@ class Sql:
sessionEnd,
ringHDs,
tourHDs,
totalProfit,
bigBets
ringProfitUSD,
ringProfitEUR
FROM SessionsCache
WHERE sessionStart>%s
AND sessionEnd>=%s
@ -4318,8 +4323,8 @@ class Sql:
UPDATE SessionsCache SET
ringHDs=ringHDs+%s,
tourHDs=tourHDs+%s,
totalProfit=totalProfit+%s,
bigBets=bigBets+%s
ringProfitUSD=ringProfitUSD+%s,
ringProfitEUR=ringProfitEUR+%s
WHERE sessionStart<=%s
AND sessionEnd>=%s"""
@ -4328,8 +4333,8 @@ class Sql:
sessionStart=%s,
ringHDs=ringHDs+%s,
tourHDs=tourHDs+%s,
totalProfit=totalProfit+%s,
bigBets=bigBets+%s
ringProfitUSD=ringProfitUSD+%s,
ringProfitEUR=ringProfitEUR+%s
WHERE sessionStart>%s
AND sessionEnd>=%s
AND sessionStart<=%s"""
@ -4339,8 +4344,8 @@ class Sql:
sessionEnd=%s,
ringHDs=ringHDs+%s,
tourHDs=tourHDs+%s,
totalProfit=totalProfit+%s,
bigBets=bigBets+%s
ringProfitUSD=ringProfitUSD+%s,
ringProfitEUR=ringProfitEUR+%s
WHERE sessionEnd<%s
AND sessionEnd>=%s
AND sessionStart<=%s"""
@ -4351,20 +4356,27 @@ class Sql:
sessionEnd,
ringHDs,
tourHDs,
totalProfit,
bigBets)
ringProfitUSD,
ringProfitEUR)
VALUES (%s, %s, %s, %s, %s, %s)"""
self.query['merge_sessionscache'] = """
SELECT min(sessionStart), max(sessionEnd), sum(ringHDs), sum(tourHDs), sum(totalProfit), sum(bigBets)
SELECT min(sessionStart), max(sessionEnd), sum(ringHDs), sum(tourHDs), sum(ringProfitUSD), sum(ringProfitEUR)
FROM SessionsCache
WHERE sessionEnd>=%s
AND sessionStart<=%s"""
WHERE (case when id=%s or id=%s then 1 else 0 end)=1"""
self.query['delete_sessions'] = """
DELETE FROM SessionsCache
WHERE sessionEnd>=%s
AND sessionStart<=%s"""
WHERE id=%s"""
self.query['update_hands_sessionid'] = """
UPDATE Hands SET
sessionId=%s
WHERE (case when sessionId=%s or sessionId=%s then 1 else 0 end)=1"""
####################################
# Database management queries
####################################
if db_server == 'mysql':
self.query['analyze'] = """
@ -4554,11 +4566,12 @@ class Sql:
self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
self.query['handsPlayersTTypeId_joiner_id'] = " OR id="
self.query['store_hand'] = """INSERT INTO Hands (
self.query['store_hand'] = """insert into Hands (
tablename,
gametypeid,
sitehandno,
tourneyId,
gametypeid,
sessionId,
startTime,
importtime,
seats,
@ -4586,13 +4599,13 @@ class Sql:
street4Pot,
showdownPot
)
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)"""
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)"""
self.query['store_hands_players'] = """INSERT INTO HandsPlayers (
self.query['store_hands_players'] = """insert into HandsPlayers (
handId,
playerId,
startCash,
@ -4696,7 +4709,7 @@ class Sql:
street3Raises,
street4Raises
)
VALUES (
values (
%s, %s, %s, %s, %s,
%s, %s, %s, %s, %s,
%s, %s, %s, %s, %s,
@ -4720,8 +4733,9 @@ class Sql:
%s, %s
)"""
self.query['store_hands_actions'] = """INSERT INTO HandsActions (
handsPlayerId,
self.query['store_hands_actions'] = """insert into HandsActions (
handId,
playerId,
street,
actionNo,
streetActionNo,
@ -4733,10 +4747,10 @@ class Sql:
cardsDiscarded,
allIn
)
VALUES (
values (
%s, %s, %s, %s, %s,
%s, %s, %s, %s, %s,
%s
%s, %s
)"""
################################

4
pyfpdb/TestHandsPlayers.py Executable file → Normal file
View File

@ -152,14 +152,14 @@ def compare_hands_file(filename, importer, errors):
pass
else:
# Stats don't match.
if datum == "gametypeId":
if datum == "gametypeId" or datum == 'sessionId':
# Not an error. gametypeIds are dependent on the order added to the db.
#print "DEBUG: Skipping mismatched gamtypeId"
pass
else:
errors.error_report(filename, hand, datum, ghash, testhash, None)
except KeyError, e:
errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p)
errors.error_report(filename, False, "KeyError: '%s'" % datum, False, False, None)
def compare(leaf, importer, errors, site):

View File

@ -83,7 +83,6 @@ class Importer:
self.pos_in_file = {} # dict to remember how far we have read in the file
#Set defaults
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
self.cacheSessions = self.config.get_import_parameters().get("cacheSessions")
# CONFIGURATION OPTIONS
self.settings.setdefault("handCount", 0)
@ -470,12 +469,20 @@ class Importer:
handlist = hhc.getProcessedHands()
self.pos_in_file[file] = hhc.getLastCharacterRead()
to_hud = []
hp_bulk = []
ha_bulk = []
i = 0
for hand in handlist:
i += 1
if hand is not None:
hand.prepInsert(self.database, printtest = self.settings['testData'])
try:
hand.insert(self.database, printtest = self.settings['testData'])
hp_inserts, ha_inserts = hand.insert(self.database, hp_data = hp_bulk,
ha_data = ha_bulk, insert_data = len(handlist)==i,
printtest = self.settings['testData'])
hp_bulk += hp_inserts
ha_bulk += ha_inserts
except Exceptions.FpdbHandDuplicate:
duplicates += 1
else:
@ -491,13 +498,6 @@ class Importer:
if hand is not None and not hand.is_duplicate:
hand.updateHudCache(self.database)
self.database.commit()
# Call sessionsCache update
if self.cacheSessions:
for hand in handlist:
if hand is not None and not hand.is_duplicate:
hand.updateSessionsCache(self.database)
self.database.commit()
#pipe the Hands.id out to the HUD
if self.caller: