storeSessionsCache() now adds a sessionId to the Hands table

This commit is contained in:
chaz@pokeit.co 2011-01-01 03:35:14 -05:00
parent 838c626bba
commit 990e226254
7 changed files with 279 additions and 78 deletions

View File

@ -73,7 +73,7 @@ except ImportError:
use_numpy = False use_numpy = False
DB_VERSION = 148 DB_VERSION = 149
# Variance created as sqlite has a bunch of undefined aggregate functions. # Variance created as sqlite has a bunch of undefined aggregate functions.
@ -1718,9 +1718,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'],
@ -2035,10 +2036,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'])
@ -2061,6 +2061,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
@ -2090,30 +2093,35 @@ 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 = []
session_records = []
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 for r in cursor:
if r: session_records.append(r[0])
num = len(session_records)
if (num == 1): if (num == 1):
id = session_records[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 = cursor.fetchone()
if (mid == 0): if mid:
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 = cursor.fetchone()
if (start == 0): if start:
#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)
else: else:
@ -2123,38 +2131,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

@ -102,6 +102,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

@ -2,7 +2,7 @@
<FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd"> <FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd">
<import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="True" sessionTimeout="30"></import> <import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="False" sessionTimeout="30"></import>
<!-- These values determine what stats are displayed in the HUD <!-- These values determine what stats are displayed in the HUD
@ -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)
@ -265,8 +266,14 @@ 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)
db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, self.stats.getHandsPlayers(),
db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, hp,
printdata = printtest) printdata = printtest)
if self.saveActions: if self.saveActions:
db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(), db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),

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,
@ -1368,8 +1371,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':
@ -1379,8 +1382,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 (
@ -1389,8 +1392,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':
@ -4058,12 +4061,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"""
@ -4073,8 +4077,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"""
@ -4084,8 +4088,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
@ -4095,8 +4099,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"""
@ -4105,8 +4109,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"""
@ -4116,8 +4120,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"""
@ -4128,20 +4132,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'] = """
@ -4326,9 +4337,10 @@ class Sql:
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,
@ -4357,9 +4369,9 @@ class Sql:
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 (

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

@ -115,14 +115,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("minPrint", 30) self.settings.setdefault("minPrint", 30)
@ -496,13 +495,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: