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

View File

@ -115,6 +115,7 @@ class DerivedStats():
self.hands['tableName'] = hand.tablename self.hands['tableName'] = hand.tablename
self.hands['siteHandNo'] = hand.handid self.hands['siteHandNo'] = hand.handid
self.hands['gametypeId'] = None # Leave None, handled later after checking db 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['startTime'] = hand.startTime # format this!
self.hands['importTime'] = None self.hands['importTime'] = None
self.hands['seats'] = self.countPlayers(hand) self.hands['seats'] = self.countPlayers(hand)

View File

@ -211,7 +211,7 @@ Left-Drag to Move"
</layout> </layout>
</site> </site>
<site enabled="False" <site enabled="True"
site_name="Everleaf" site_name="Everleaf"
table_finder="Everleaf.exe" table_finder="Everleaf.exe"
screen_name="Hero" screen_name="Hero"
@ -255,7 +255,7 @@ Left-Drag to Move"
</layout> </layout>
</site> </site>
<site enabled="False" <site enabled="True"
site_name="Win2day" site_name="Win2day"
table_finder="Win2day.exe" table_finder="Win2day.exe"
screen_name="Hero" screen_name="Hero"
@ -300,7 +300,7 @@ Left-Drag to Move"
</site> </site>
<site enabled="False" <site enabled="True"
site_name="Absolute" site_name="Absolute"
table_finder="AbsolutePoker.exe" table_finder="AbsolutePoker.exe"
screen_name="Hero" screen_name="Hero"
@ -345,7 +345,7 @@ Left-Drag to Move"
</site> </site>
<site enabled="False" <site enabled="True"
site_name="PartyPoker" site_name="PartyPoker"
table_finder="PartyGaming.exe" table_finder="PartyGaming.exe"
screen_name="Hero" screen_name="Hero"
@ -390,7 +390,7 @@ Left-Drag to Move"
</site> </site>
<site enabled="False" <site enabled="True"
site_name="Betfair" site_name="Betfair"
table_finder="Betfair Poker.exe" table_finder="Betfair Poker.exe"
screen_name="Hero" screen_name="Hero"
@ -433,6 +433,188 @@ Left-Drag to Move"
<location seat="9" x="70" y="53"> </location> <location seat="9" x="70" y="53"> </location>
</layout> </layout>
</site> </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_sites>
<supported_games> <supported_games>

View File

@ -57,6 +57,7 @@ class Hand(object):
#log.debug( _("Hand.init(): handText is ") + str(handText) ) #log.debug( _("Hand.init(): handText is ") + str(handText) )
self.config = config self.config = config
self.saveActions = self.config.get_import_parameters().get('saveActions') 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) #log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log)
self.sitename = sitename self.sitename = sitename
self.siteId = self.config.get_site_id(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() db.commit()
#end def prepInsert #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 """ Function to insert Hand into database
Should not commit, and do minimal selects. Callers may want to cache commits Should not commit, and do minimal selects. Callers may want to cache commits
db: a connected Database object""" db: a connected Database object"""
@ -277,17 +278,26 @@ db: a connected Database object"""
# seats TINYINT NOT NULL, # seats TINYINT NOT NULL,
hh['seats'] = len(self.dbid_pids) 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_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: if self.saveActions:
db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.dbid_hpid, ha_inserts = db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),
self.stats.getHandsActions(), printdata = printtest) insert=insert_data, ha_bulk = ha_data, printdata = printtest)
else: else:
log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo']) log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo'])
self.is_duplicate = True # i.e. don't update hudcache self.is_duplicate = True # i.e. don't update hudcache
raise FpdbHandDuplicate(hh['siteHandNo']) raise FpdbHandDuplicate(hh['siteHandNo'])
return hp_inserts, ha_inserts
def updateHudCache(self, db): def updateHudCache(self, db):
db.storeHudCache(self.dbid_gt, self.dbid_pids, self.startTime, self.stats.getHandsPlayers()) 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, siteHandNo BIGINT NOT NULL,
tourneyId INT UNSIGNED, tourneyId INT UNSIGNED,
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
sessionId INT UNSIGNED,
startTime DATETIME NOT NULL, startTime DATETIME NOT NULL,
importTime DATETIME NOT NULL, importTime DATETIME NOT NULL,
seats TINYINT NOT NULL, seats TINYINT NOT NULL,
@ -383,6 +384,7 @@ class Sql:
siteHandNo BIGINT NOT NULL, siteHandNo BIGINT NOT NULL,
tourneyId INT, tourneyId INT,
gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
sessionId INT,
startTime timestamp without time zone NOT NULL, startTime timestamp without time zone NOT NULL,
importTime timestamp without time zone NOT NULL, importTime timestamp without time zone NOT NULL,
seats SMALLINT NOT NULL, seats SMALLINT NOT NULL,
@ -419,6 +421,7 @@ class Sql:
siteHandNo INT NOT NULL, siteHandNo INT NOT NULL,
tourneyId INT, tourneyId INT,
gametypeId INT NOT NULL, gametypeId INT NOT NULL,
sessionId INT,
startTime REAL NOT NULL, startTime REAL NOT NULL,
importTime REAL NOT NULL, importTime REAL NOT NULL,
seats INT NOT NULL, seats INT NOT NULL,
@ -1028,7 +1031,8 @@ class Sql:
if db_server == 'mysql': if db_server == 'mysql':
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), 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, street SMALLINT NOT NULL,
actionNo SMALLINT NOT NULL, actionNo SMALLINT NOT NULL,
streetActionNo SMALLINT NOT NULL, streetActionNo SMALLINT NOT NULL,
@ -1043,7 +1047,8 @@ class Sql:
elif db_server == 'postgresql': elif db_server == 'postgresql':
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id BIGSERIAL, PRIMARY KEY (id), 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, street SMALLINT,
actionNo SMALLINT, actionNo SMALLINT,
streetActionNo SMALLINT, streetActionNo SMALLINT,
@ -1057,7 +1062,8 @@ class Sql:
elif db_server == 'sqlite': elif db_server == 'sqlite':
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
handsPlayerId BIGINT, handId INT NOT NULL,
playerId INT NOT NULL,
street SMALLINT, street SMALLINT,
actionNo SMALLINT, actionNo SMALLINT,
streetActionNo SMALLINT, streetActionNo SMALLINT,
@ -1067,9 +1073,7 @@ class Sql:
amountCalled INT, amountCalled INT,
numDiscarded SMALLINT, numDiscarded SMALLINT,
cardsDiscarded TEXT, cardsDiscarded TEXT,
allIn BOOLEAN, allIn BOOLEAN
FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
FOREIGN KEY (actionId) REFERENCES Actions(id) ON DELETE CASCADE
)""" )"""
@ -1410,8 +1414,8 @@ class Sql:
sessionEnd DATETIME NOT NULL, sessionEnd DATETIME NOT NULL,
ringHDs INT NOT NULL, ringHDs INT NOT NULL,
tourHDs INT NOT NULL, tourHDs INT NOT NULL,
totalProfit INT NOT NULL, ringProfitUSD INT NOT NULL,
bigBets FLOAT UNSIGNED NOT NULL) ringProfitEUR INT NOT NULL)
ENGINE=INNODB""" ENGINE=INNODB"""
elif db_server == 'postgresql': elif db_server == 'postgresql':
@ -1421,8 +1425,8 @@ class Sql:
sessionEnd REAL NOT NULL, sessionEnd REAL NOT NULL,
ringHDs INT NOT NULL, ringHDs INT NOT NULL,
tourHDs INT NOT NULL, tourHDs INT NOT NULL,
totalProfit INT NOT NULL, ringProfitUSD INT NOT NULL,
bigBets FLOAT NOT NULL) ringProfitEUR INT NOT NULL)
""" """
elif db_server == 'sqlite': elif db_server == 'sqlite':
self.query['createSessionsCacheTable'] = """CREATE TABLE SessionsCache ( self.query['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
@ -1431,8 +1435,8 @@ class Sql:
sessionEnd REAL NOT NULL, sessionEnd REAL NOT NULL,
ringHDs INT NOT NULL, ringHDs INT NOT NULL,
tourHDs INT NOT NULL, tourHDs INT NOT NULL,
totalProfit INT NOT NULL, ringProfitUSD INT NOT NULL,
bigBets REAL UNSIGNED NOT NULL) ringProfitEUR INT NOT NULL)
""" """
if db_server == 'mysql': if db_server == 'mysql':
@ -4281,12 +4285,13 @@ class Sql:
#################################### ####################################
self.query['select_sessionscache'] = """ self.query['select_sessionscache'] = """
SELECT sessionStart, SELECT id,
sessionStart,
sessionEnd, sessionEnd,
ringHDs, ringHDs,
tourHDs, tourHDs,
totalProfit, ringProfitUSD,
bigBets ringProfitEUR
FROM SessionsCache FROM SessionsCache
WHERE sessionEnd>=%s WHERE sessionEnd>=%s
AND sessionStart<=%s""" AND sessionStart<=%s"""
@ -4296,8 +4301,8 @@ class Sql:
sessionEnd, sessionEnd,
ringHDs, ringHDs,
tourHDs, tourHDs,
totalProfit, ringProfitUSD,
bigBets ringProfitEUR
FROM SessionsCache FROM SessionsCache
WHERE sessionEnd>=%s WHERE sessionEnd>=%s
AND sessionStart<=%s""" AND sessionStart<=%s"""
@ -4307,8 +4312,8 @@ class Sql:
sessionEnd, sessionEnd,
ringHDs, ringHDs,
tourHDs, tourHDs,
totalProfit, ringProfitUSD,
bigBets ringProfitEUR
FROM SessionsCache FROM SessionsCache
WHERE sessionStart>%s WHERE sessionStart>%s
AND sessionEnd>=%s AND sessionEnd>=%s
@ -4318,8 +4323,8 @@ class Sql:
UPDATE SessionsCache SET UPDATE SessionsCache SET
ringHDs=ringHDs+%s, ringHDs=ringHDs+%s,
tourHDs=tourHDs+%s, tourHDs=tourHDs+%s,
totalProfit=totalProfit+%s, ringProfitUSD=ringProfitUSD+%s,
bigBets=bigBets+%s ringProfitEUR=ringProfitEUR+%s
WHERE sessionStart<=%s WHERE sessionStart<=%s
AND sessionEnd>=%s""" AND sessionEnd>=%s"""
@ -4328,8 +4333,8 @@ class Sql:
sessionStart=%s, sessionStart=%s,
ringHDs=ringHDs+%s, ringHDs=ringHDs+%s,
tourHDs=tourHDs+%s, tourHDs=tourHDs+%s,
totalProfit=totalProfit+%s, ringProfitUSD=ringProfitUSD+%s,
bigBets=bigBets+%s ringProfitEUR=ringProfitEUR+%s
WHERE sessionStart>%s WHERE sessionStart>%s
AND sessionEnd>=%s AND sessionEnd>=%s
AND sessionStart<=%s""" AND sessionStart<=%s"""
@ -4339,8 +4344,8 @@ class Sql:
sessionEnd=%s, sessionEnd=%s,
ringHDs=ringHDs+%s, ringHDs=ringHDs+%s,
tourHDs=tourHDs+%s, tourHDs=tourHDs+%s,
totalProfit=totalProfit+%s, ringProfitUSD=ringProfitUSD+%s,
bigBets=bigBets+%s ringProfitEUR=ringProfitEUR+%s
WHERE sessionEnd<%s WHERE sessionEnd<%s
AND sessionEnd>=%s AND sessionEnd>=%s
AND sessionStart<=%s""" AND sessionStart<=%s"""
@ -4351,20 +4356,27 @@ class Sql:
sessionEnd, sessionEnd,
ringHDs, ringHDs,
tourHDs, tourHDs,
totalProfit, ringProfitUSD,
bigBets) ringProfitEUR)
VALUES (%s, %s, %s, %s, %s, %s)""" VALUES (%s, %s, %s, %s, %s, %s)"""
self.query['merge_sessionscache'] = """ 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 FROM SessionsCache
WHERE sessionEnd>=%s WHERE (case when id=%s or id=%s then 1 else 0 end)=1"""
AND sessionStart<=%s"""
self.query['delete_sessions'] = """ self.query['delete_sessions'] = """
DELETE FROM SessionsCache DELETE FROM SessionsCache
WHERE sessionEnd>=%s WHERE id=%s"""
AND sessionStart<=%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': if db_server == 'mysql':
self.query['analyze'] = """ self.query['analyze'] = """
@ -4554,11 +4566,12 @@ class Sql:
self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0=" self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
self.query['handsPlayersTTypeId_joiner_id'] = " OR id=" self.query['handsPlayersTTypeId_joiner_id'] = " OR id="
self.query['store_hand'] = """INSERT INTO Hands ( self.query['store_hand'] = """insert into Hands (
tablename, tablename,
gametypeid,
sitehandno, sitehandno,
tourneyId, tourneyId,
gametypeid,
sessionId,
startTime, startTime,
importtime, importtime,
seats, seats,
@ -4586,13 +4599,13 @@ class Sql:
street4Pot, street4Pot,
showdownPot showdownPot
) )
VALUES 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)"""
self.query['store_hands_players'] = """INSERT INTO HandsPlayers ( self.query['store_hands_players'] = """insert into HandsPlayers (
handId, handId,
playerId, playerId,
startCash, startCash,
@ -4696,7 +4709,7 @@ class Sql:
street3Raises, street3Raises,
street4Raises street4Raises
) )
VALUES ( 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,
@ -4720,8 +4733,9 @@ class Sql:
%s, %s %s, %s
)""" )"""
self.query['store_hands_actions'] = """INSERT INTO HandsActions ( self.query['store_hands_actions'] = """insert into HandsActions (
handsPlayerId, handId,
playerId,
street, street,
actionNo, actionNo,
streetActionNo, streetActionNo,
@ -4733,10 +4747,10 @@ class Sql:
cardsDiscarded, cardsDiscarded,
allIn allIn
) )
VALUES ( values (
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%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 pass
else: else:
# Stats don't match. # 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. # Not an error. gametypeIds are dependent on the order added to the db.
#print "DEBUG: Skipping mismatched gamtypeId" #print "DEBUG: Skipping mismatched gamtypeId"
pass pass
else: else:
errors.error_report(filename, hand, datum, ghash, testhash, None) errors.error_report(filename, hand, datum, ghash, testhash, None)
except KeyError, e: 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): 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 self.pos_in_file = {} # dict to remember how far we have read in the file
#Set defaults #Set defaults
self.callHud = self.config.get_import_parameters().get("callFpdbHud") self.callHud = self.config.get_import_parameters().get("callFpdbHud")
self.cacheSessions = self.config.get_import_parameters().get("cacheSessions")
# CONFIGURATION OPTIONS # CONFIGURATION OPTIONS
self.settings.setdefault("handCount", 0) self.settings.setdefault("handCount", 0)
@ -470,12 +469,20 @@ class Importer:
handlist = hhc.getProcessedHands() handlist = hhc.getProcessedHands()
self.pos_in_file[file] = hhc.getLastCharacterRead() self.pos_in_file[file] = hhc.getLastCharacterRead()
to_hud = [] to_hud = []
hp_bulk = []
ha_bulk = []
i = 0
for hand in handlist: for hand in handlist:
i += 1
if hand is not None: if hand is not None:
hand.prepInsert(self.database, printtest = self.settings['testData']) hand.prepInsert(self.database, printtest = self.settings['testData'])
try: 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: except Exceptions.FpdbHandDuplicate:
duplicates += 1 duplicates += 1
else: else:
@ -492,13 +499,6 @@ class Importer:
hand.updateHudCache(self.database) hand.updateHudCache(self.database)
self.database.commit() 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 #pipe the Hands.id out to the HUD
if self.caller: if self.caller:
for hid in to_hud: for hid in to_hud: