* Added 'cacheSessions' flag

* Added a cacheSessions update call to import_file_dict() in fpdb_import.py
* Added updateSessionsCache() method to Hands
* Added storeSessionsCache() to Database --- WORK IN PROGRESS and set to pass
TO DOs
- add sessions queries to SQL
- complete storeSessionsCache() so it works like we've discussed (save for adding sessionId to HP)
- add SessionsCache keys
- add SessionsCache to the default table creation and deletion methods in Database.py
- update storeSessionsCache() and all the relevant db & sql code so it writes a sessionId to HP
This commit is contained in:
Chaz 2010-12-02 01:58:02 -05:00
parent a7f3b1326f
commit 925db93157
5 changed files with 59 additions and 2 deletions

View File

@ -1966,6 +1966,53 @@ class Database:
else: else:
#print "DEBUG: Successfully updated HudCacho using UPDATE" #print "DEBUG: Successfully updated HudCacho using UPDATE"
pass pass
def storeSessionsCache(self, pids, starttime, pdata):
"""Update cached sessions. If update fails because no record exists, do an insert."""
#In development
pass
#update_sessionscache = self.sql.query['update_sessionscache']
#update_sessionscache = update_sessionscache.replace('%s', self.sql.query['placeholder'])
#insert_sessionscache = self.sql.query['insert_sessionscache']
#insert_sessionscache = insert_sessionscache.replace('%s', self.sql.query['placeholder'])
#merge_sessionscache = self.sql.query['merge_sessionscache']
#merge_sessionscache = merge_sessionscache.replace('%s', self.sql.query['placeholder'])
#print "DEBUG: %s %s %s" %(hid, pids, pdata)
#inserts = []
#for p in pdata:
#line = [0]*5
#line[0] = 1 # HDs
#line[1] = pdata[p]['totalProfit']
#line[2] = pids[p] # playerId
#line[3] = sessionStart
#line[4] = sessionEnd
#inserts.append(line)
#cursor = self.get_cursor()
#for row in inserts:
# Try to do the update first:
#num = cursor.execute(update_sessionscache, row)
#print "DEBUG: values: %s" % row[-3:]
# Test statusmessage to see if update worked, do insert if not
# num is a cursor in sqlite
#if ((self.backend == self.PGSQL and cursor.statusmessage != "UPDATE 1")
#or (self.backend == self.MYSQL_INNODB and num == 0)
#or (self.backend == self.SQLITE and num.rowcount == 0)):
#move the last 6 items in WHERE clause of row from the end of the array
# to the beginning for the INSERT statement
#print "DEBUG: using INSERT: %s" % num
#row = row[-3:] + row[:-3]
#num = cursor.execute(insert_sessionscache, row)
#print "DEBUG: Successfully(?: %s) updated HudCacho using INSERT" % num
#else:
#print "DEBUG: Successfully updated HudCacho using UPDATE"
#pass
def isDuplicate(self, gametypeID, siteHandNo): def isDuplicate(self, gametypeID, siteHandNo):
dup = False dup = False

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"></import> <import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="False"></import>
<!-- These values determine what stats are displayed in the HUD <!-- These values determine what stats are displayed in the HUD

View File

@ -12,7 +12,7 @@
config_difficulty="expert" config_difficulty="expert"
/> />
<import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="True"></import> <import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="False"></import>
<gui_cash_stats> <gui_cash_stats>
<col col_name="game" disp_all="True" disp_posn="True" col_title="Game" xalignment="0.0" field_format="%s" field_type="str" /> <col col_name="game" disp_all="True" disp_posn="True" col_title="Game" xalignment="0.0" field_format="%s" field_type="str" />

View File

@ -278,6 +278,9 @@ db: a connected Database object"""
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())
def updateSessionsCache(self, db):
db.storeSessionsCache(self.dbid_pids, self.startTime, self.stats.getHandsPlayers())
def select(self, handId): def select(self, handId):
""" Function to create Hand object from database """ """ Function to create Hand object from database """

View File

@ -495,6 +495,13 @@ class Importer:
if hand is not None and not hand.is_duplicate: if hand is not None and not hand.is_duplicate:
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: