Added printtest back in and fixed a couple of SessionsCache bugs

This commit is contained in:
Chaz Littlejohn 2011-03-23 04:59:44 +00:00
parent 3ac088b748
commit 8c4d5d42b4
5 changed files with 45 additions and 18 deletions

View File

@ -1760,8 +1760,14 @@ class Database:
# NEWIMPORT CODE # NEWIMPORT CODE
########################### ###########################
def storeHand(self, hdata, hbulk, doinsert = False): def storeHand(self, hdata, hbulk, doinsert = False, printdata = False):
#stores into table hands: if printdata:
print _("######## Hands ##########")
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(hdata)
print _("###### End Hands ########")
# Tablename can have odd charachers # Tablename can have odd charachers
hdata['tableName'] = Charset.to_db_utf8(hdata['tableName']) hdata['tableName'] = Charset.to_db_utf8(hdata['tableName'])
@ -1813,8 +1819,12 @@ class Database:
self.commit() self.commit()
return hbulk return hbulk
def storeHandsPlayers(self, hid, pids, pdata, hpbulk, doinsert = False): def storeHandsPlayers(self, hid, pids, pdata, hpbulk, doinsert = False, printdata = False):
#print "DEBUG: %s %s %s" %(hid, pids, pdata) #print "DEBUG: %s %s %s" %(hid, pids, pdata)
if printdata:
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(pdata)
for p in pdata: for p in pdata:
hpbulk.append( ( hid, hpbulk.append( ( hid,
@ -1930,8 +1940,14 @@ class Database:
c.executemany(q, hpbulk) c.executemany(q, hpbulk)
return hpbulk return hpbulk
def storeHandsActions(self, hid, pids, adata, habulk, doinsert = False): def storeHandsActions(self, hid, pids, adata, habulk, doinsert = False, 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
#if printdata:
# import pprint
# pp = pprint.PrettyPrinter(indent=4)
# pp.pprint(adata)
for a in adata: for a in adata:
habulk.append( (hid, habulk.append( (hid,
@ -2262,8 +2278,10 @@ class Database:
if (game['type']=='summary'): if (game['type']=='summary'):
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] - (pdata.buyin + pdata.fee) hand['totalProfit'] = pdata['winnings'][p]
if pdata['buyinCurrency'] == pdata['winningsCurrency'][p]:
hand['totalProfit'] - (pdata['buyin'] + pdata['fee'])
elif (game['type']=='ring'): elif (game['type']=='ring'):
hand['type'] = game['type'] hand['type'] = game['type']
hand['hands'] = 1 hand['hands'] = 1

View File

@ -229,7 +229,7 @@ class SummaryImporter:
doinsert = len(summaryTexts)==j doinsert = len(summaryTexts)==j
try: try:
conv = obj(db=self.database, config=self.config, siteName=site, summaryText=summaryText, builtFrom = "IMAP") conv = obj(db=self.database, config=self.config, siteName=site, summaryText=summaryText, builtFrom = "IMAP")
sc, gsc = conv.updateSessionsCache(sc, gsc, self.tz, doinsert) sc, gsc = conv.updateSessionsCache(sc, gsc, None, doinsert)
except FpdbParseError, e: except FpdbParseError, e:
errors += 1 errors += 1
print _("Finished importing %s/%s tournament summaries") %(j, len(summaryTexts)) print _("Finished importing %s/%s tournament summaries") %(j, len(summaryTexts))

View File

@ -259,24 +259,24 @@ dealt whether they were seen in a 'dealt to' line
next = id +1 next = id +1
return next return next
def insertHands(self, db, hbulk, doinsert = False): def insertHands(self, db, hbulk, doinsert = 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"""
self.hands['gameTypeId'] = self.dbid_gt self.hands['gameTypeId'] = self.dbid_gt
self.hands['seats'] = len(self.dbid_pids) self.hands['seats'] = len(self.dbid_pids)
hbulk = db.storeHand(self.hands, hbulk, doinsert) hbulk = db.storeHand(self.hands, hbulk, doinsert, printtest)
return hbulk return hbulk
def insertHandsPlayers(self, db, hpbulk, doinsert = False): def insertHandsPlayers(self, db, hpbulk, doinsert = False, printtest = False):
""" Function to inserts HandsPlayers into database""" """ Function to inserts HandsPlayers into database"""
hpbulk = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, self.handsplayers, hpbulk, doinsert) hpbulk = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, self.handsplayers, hpbulk, doinsert, printtest)
return hpbulk return hpbulk
def insertHandsActions(self, db, habulk, doinsert = False): def insertHandsActions(self, db, habulk, doinsert = False, printtest = False):
""" Function to inserts HandsActions into database""" """ Function to inserts HandsActions into database"""
handsactions = self.stats.getHandsActions() handsactions = self.stats.getHandsActions()
habulk = db.storeHandsActions(self.dbid_hands, self.dbid_pids, handsactions, habulk, doinsert) habulk = db.storeHandsActions(self.dbid_hands, self.dbid_pids, handsactions, habulk, doinsert, printtest)
return habulk return habulk
def updateHudCache(self, db, hcbulk, doinsert = False): def updateHudCache(self, db, hcbulk, doinsert = False):

View File

@ -291,11 +291,20 @@ winnings (int) the money the player ended the tourney with (can be 0, or -1 i
def updateSessionsCache(self, sc, gsc, tz, doinsert): def updateSessionsCache(self, sc, gsc, tz, doinsert):
self.heros = self.db.getHeroIds(self.dbid_pids, self.siteName) self.heros = self.db.getHeroIds(self.dbid_pids, self.siteName)
sc = self.db.prepSessionsCache(self.tourNo, self.dbid_pids, self.startTime, sc , self.heros, doinsert) sc = self.db.prepSessionsCache(self.tourNo, self.dbid_pids, self.startTime, sc , self.heros, doinsert)
gsc = self.db.storeSessionsCache(self.tourNo, self.dbid_pids, self.startTime, {'type': 'summary'} gsc = self.db.storeSessionsCache(self.tourNo, self.dbid_pids, self.startTime, {'type': 'summary'}
, None, self, sc, gsc, tz, self.heros, doinsert) ,None, self.assembleInfo(), sc, gsc, tz, self.heros, doinsert)
return sc, gsc return sc, gsc
def assembleInfo(self):
info = {}
info['tourneyTypeId'] = self.tourneyTypeId
info['winnings'] = self.winnings
info['winningsCurrency'] = self.winningsCurrency
info['buyinCurrency'] = self.buyinCurrency
info['buyin'] = self.buyin
info['fee'] = self.fee
return info
def writeSummary(self, fh=sys.__stdout__): def writeSummary(self, fh=sys.__stdout__):
print >>fh, "Override me" print >>fh, "Override me"

View File

@ -476,7 +476,7 @@ class Importer:
try: try:
id = hand.getHandId(self.database, id) id = hand.getHandId(self.database, id)
sc, gsc = hand.updateSessionsCache(self.database, sc, gsc, None, doinsert) sc, gsc = hand.updateSessionsCache(self.database, sc, gsc, None, doinsert)
hbulk = hand.insertHands(self.database, hbulk, doinsert) hbulk = hand.insertHands(self.database, hbulk, doinsert, self.settings['testData'])
hcbulk = hand.updateHudCache(self.database, hcbulk, doinsert) hcbulk = hand.updateHudCache(self.database, hcbulk, doinsert)
ihands.append(hand) ihands.append(hand)
to_hud.append(id) to_hud.append(id)
@ -488,8 +488,8 @@ class Importer:
for i in range(len(ihands)): for i in range(len(ihands)):
doinsert = len(ihands)==i+1 doinsert = len(ihands)==i+1
hand = ihands[i] hand = ihands[i]
hpbulk = hand.insertHandsPlayers(self.database, hpbulk, doinsert) hpbulk = hand.insertHandsPlayers(self.database, hpbulk, doinsert, self.settings['testData'])
habulk = hand.insertHandsActions(self.database, habulk, doinsert) habulk = hand.insertHandsActions(self.database, habulk, doinsert, self.settings['testData'])
self.database.commit() self.database.commit()
#pipe the Hands.id out to the HUD #pipe the Hands.id out to the HUD