diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index fbb29655..d684e60a 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1760,8 +1760,14 @@ class Database: # NEWIMPORT CODE ########################### - def storeHand(self, hdata, hbulk, doinsert = False): - #stores into table hands: + def storeHand(self, hdata, hbulk, doinsert = False, printdata = False): + if printdata: + print _("######## Hands ##########") + import pprint + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(hdata) + print _("###### End Hands ########") + # Tablename can have odd charachers hdata['tableName'] = Charset.to_db_utf8(hdata['tableName']) @@ -1813,8 +1819,12 @@ class Database: self.commit() 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) + if printdata: + import pprint + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(pdata) for p in pdata: hpbulk.append( ( hid, @@ -1930,8 +1940,14 @@ class Database: c.executemany(q, 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) + + # 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: habulk.append( (hid, @@ -2262,8 +2278,10 @@ class Database: if (game['type']=='summary'): hand['type'] = 'tour' hand['tourneys'] = 1 - hand['tourneyTypeId'] = pdata.tourneyTypeId - hand['totalProfit'] = pdata.winnings[p] - (pdata.buyin + pdata.fee) + hand['tourneyTypeId'] = pdata['tourneyTypeId'] + hand['totalProfit'] = pdata['winnings'][p] + if pdata['buyinCurrency'] == pdata['winningsCurrency'][p]: + hand['totalProfit'] - (pdata['buyin'] + pdata['fee']) elif (game['type']=='ring'): hand['type'] = game['type'] hand['hands'] = 1 diff --git a/pyfpdb/GuiTourneyImport.py b/pyfpdb/GuiTourneyImport.py index c6f0bb48..0ed33b18 100755 --- a/pyfpdb/GuiTourneyImport.py +++ b/pyfpdb/GuiTourneyImport.py @@ -229,7 +229,7 @@ class SummaryImporter: doinsert = len(summaryTexts)==j try: 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: errors += 1 print _("Finished importing %s/%s tournament summaries") %(j, len(summaryTexts)) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f86e5df9..cb3bb405 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -259,24 +259,24 @@ dealt whether they were seen in a 'dealt to' line next = id +1 return next - def insertHands(self, db, hbulk, doinsert = False): + def insertHands(self, db, hbulk, doinsert = False, printtest = False): """ Function to insert Hand into database Should not commit, and do minimal selects. Callers may want to cache commits db: a connected Database object""" self.hands['gameTypeId'] = self.dbid_gt self.hands['seats'] = len(self.dbid_pids) - hbulk = db.storeHand(self.hands, hbulk, doinsert) + hbulk = db.storeHand(self.hands, hbulk, doinsert, printtest) return hbulk - def insertHandsPlayers(self, db, hpbulk, doinsert = False): + def insertHandsPlayers(self, db, hpbulk, doinsert = False, printtest = False): """ 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 - def insertHandsActions(self, db, habulk, doinsert = False): + def insertHandsActions(self, db, habulk, doinsert = False, printtest = False): """ Function to inserts HandsActions into database""" 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 def updateHudCache(self, db, hcbulk, doinsert = False): diff --git a/pyfpdb/TourneySummary.py b/pyfpdb/TourneySummary.py index 0483755f..2e655f6b 100644 --- a/pyfpdb/TourneySummary.py +++ b/pyfpdb/TourneySummary.py @@ -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): 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) - 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 + + 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__): print >>fh, "Override me" diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 93e57554..7aab478c 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -476,7 +476,7 @@ class Importer: try: id = hand.getHandId(self.database, id) 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) ihands.append(hand) to_hud.append(id) @@ -488,8 +488,8 @@ class Importer: for i in range(len(ihands)): doinsert = len(ihands)==i+1 hand = ihands[i] - hpbulk = hand.insertHandsPlayers(self.database, hpbulk, doinsert) - habulk = hand.insertHandsActions(self.database, habulk, doinsert) + hpbulk = hand.insertHandsPlayers(self.database, hpbulk, doinsert, self.settings['testData']) + habulk = hand.insertHandsActions(self.database, habulk, doinsert, self.settings['testData']) self.database.commit() #pipe the Hands.id out to the HUD