Added a rebuild_sessionscache method for creating the SC table from hands in the database

This commit is contained in:
Chaz Littlejohn 2011-03-23 05:44:03 +00:00
parent 8c4d5d42b4
commit 3e9dacf900
2 changed files with 120 additions and 6 deletions

View File

@ -1637,10 +1637,86 @@ class Database:
print err print err
#end def rebuild_hudcache #end def rebuild_hudcache
def rebuild_sessionscache(self, h_start=None, v_start=None): def rebuild_sessionscache(self):
"""clears sessionscache and rebuilds from the individual handsplayers records""" """clears sessionscache and rebuilds from the individual records"""
#Will get to this soon heros = []
pass for site in self.config.get_supported_sites():
result = self.get_site_id(site)
if result:
site_id = result[0][0]
hero = self.config.supported_sites[site].screen_name
p_id = self.get_player_id(self.config, site, hero)
if p_id:
heros.append(int(p_id))
rebuildSessionsCache = self.sql.query['rebuildSessionsCache']
rebuildSessionsCacheSum = self.sql.query['rebuildSessionsCacheSum']
if len(heros) == 0:
where = '0'
where_summary = '0'
elif len(heros) > 0:
where = str(heros[0])
where_summary = str(heros[0])
if len(heros) > 1:
for i in heros:
if i != heros[0]:
where = where + ' OR HandsPlayers.playerId = %s' % str(i)
where_summary = where_summary + ' OR TourneysPlayers.playerId = %s' % str(i)
rebuildSessionsCache = rebuildSessionsCache.replace('<where_clause>', where)
rebuildSessionsCacheSum = rebuildSessionsCacheSum.replace('<where_clause>', where_summary)
c = self.get_cursor()
c.execute(self.sql.query['clearSessionsCache'])
self.commit()
sc, gsc = {'bk': []}, {'bk': []}
c.execute(rebuildSessionsCache)
tmp = c.fetchone()
while True:
pids, game, pdata = {}, {}, {}
pdata['pname'] = {}
id = tmp[0]
startTime = tmp[1]
pids['pname'] = tmp[2]
gid = tmp[3]
game['type'] = tmp[4]
pdata['pname']['totalProfit'] = tmp[5]
pdata['pname']['tourneyTypeId'] = tmp[6]
tmp = c.fetchone()
sc = self.prepSessionsCache (id, pids, startTime, sc , heros, tmp == None)
gsc = self.storeSessionsCache(id, pids, startTime, game, gid, pdata, sc, gsc, None, heros, tmp == None)
if tmp == None:
for i, id in sc.iteritems():
if i!='bk':
sid = id['id']
gid = gsc[i]['id']
c.execute("UPDATE Hands SET sessionId = %s, gameSessionId = %s WHERE id = %s", (sid, gid, i))
break
self.commit()
sc, gsc = {'bk': []}, {'bk': []}
c.execute(rebuildSessionsCacheSum)
tmp = c.fetchone()
while True:
pids, game, info = {}, {}, {}
id = tmp[0]
startTime = tmp[1]
pids['pname'] = tmp[2]
game['type'] = 'summary'
info['tourneyTypeId'] = tmp[3]
info['winnings'] = {}
info['winnings']['pname'] = tmp[4]
info['winningsCurrency'] = {}
info['winningsCurrency']['pname'] = tmp[5]
info['buyinCurrency'] = tmp[6]
info['buyin'] = tmp[7]
info['fee'] = tmp[8]
tmp = c.fetchone()
sc = self.prepSessionsCache (id, pids, startTime, sc , heros, tmp == None)
gsc = self.storeSessionsCache(id, pids, startTime, game, None, info, sc, gsc, None, heros, tmp == None)
if tmp == None:
break
def get_hero_hudcache_start(self): def get_hero_hudcache_start(self):
"""fetches earliest stylekey from hudcache for one of hero's player ids""" """fetches earliest stylekey from hudcache for one of hero's player ids"""
@ -2279,9 +2355,9 @@ class Database:
hand['type'] = 'tour' hand['type'] = 'tour'
hand['tourneys'] = 1 hand['tourneys'] = 1
hand['tourneyTypeId'] = pdata['tourneyTypeId'] hand['tourneyTypeId'] = pdata['tourneyTypeId']
hand['totalProfit'] = pdata['winnings'][p]
if pdata['buyinCurrency'] == pdata['winningsCurrency'][p]: if pdata['buyinCurrency'] == pdata['winningsCurrency'][p]:
hand['totalProfit'] - (pdata['buyin'] + pdata['fee']) hand['totalProfit'] = pdata['winnings'][p] - (pdata['buyin'] + pdata['fee'])
else: hand['totalProfit'] = pdata['winnings'][p]
elif (game['type']=='ring'): elif (game['type']=='ring'):
hand['type'] = game['type'] hand['type'] = game['type']
hand['hands'] = 1 hand['hands'] = 1

View File

@ -4404,6 +4404,44 @@ class Sql:
#################################### ####################################
# Queries to rebuild/modify sessionscache # Queries to rebuild/modify sessionscache
#################################### ####################################
self.query['clearSessionsCache'] = """DELETE FROM SessionsCache"""
self.query['rebuildSessionsCache'] = """
SELECT Hands.id as id,
Hands.startTime as startTime,
HandsPlayers.playerId as playerId,
Hands.gametypeId as gametypeId,
Gametypes.type as game,
HandsPlayers.totalProfit as totalProfit,
Tourneys.tourneyTypeId as tourneyTypeId
FROM Gametypes, HandsPlayers, Hands
LEFT JOIN Tourneys ON Hands.tourneyId = Tourneys.tourneyTypeId
WHERE HandsPlayers.handId = Hands.id
AND Hands.gametypeId = Gametypes.id
AND (case when HandsPlayers.playerId = <where_clause> then 1 else 0 end) = 1
ORDER BY Hands.startTime ASC"""
self.query['rebuildSessionsCacheSum'] = """
SELECT Tourneys.id as id,
Tourneys.startTime as startTime,
TourneysPlayers.playerId,
TourneyTypes.id as tourneyTypeId,
TourneysPlayers.winnings as winnings,
TourneysPlayers.winningsCurrency as winningsCurrency,
TourneyTypes.currency as buyinCurrency,
TourneyTypes.buyIn as buyIn,
TourneyTypes.fee as fee,
case when TourneyTypes.rebuy then TourneyTypes.rebuyCost else 0 end as rebuyCost,
case when TourneyTypes.rebuy then TourneyTypes.rebuyFee else 0 end as rebuyFee,
case when TourneyTypes.addOn then TourneyTypes.addOnCost else 0 end as addOnCost,
case when TourneyTypes.addOn then TourneyTypes.addOnFee else 0 end as addOnFee,
case when TourneyTypes.knockout then TourneyTypes.koBounty else 0 end as koBounty
FROM Tourneys, TourneyTypes, TourneysPlayers
WHERE Tourneys.tourneyTypeId = TourneyTypes.id
AND Tourneys.id = TourneysPlayers.tourneyId
AND (case when TourneysPlayers.playerId = <where_clause> then 1 else 0 end) = 1
ORDER BY Tourneys.startTime ASC"""
self.query['select_prepSC'] = """ self.query['select_prepSC'] = """
SELECT sessionId as id, SELECT sessionId as id,