* Modified storeHandsPlayers() so it returns a dictionary of handId & playerId to handPlayerIds

* Filled storeHandsActions() with the required information
* Updated Hand.insert so that it calls storeHandsActions() and added the variable dbid_hpid to receive the new dictionary
This commit is contained in:
Chaz 2010-09-28 17:09:24 -04:00
parent 1b0db117ce
commit a76e34598d
2 changed files with 32 additions and 27 deletions

View File

@ -1676,6 +1676,7 @@ class Database:
pp.pprint(pdata)
inserts = []
hpid = {}
for p in pdata:
inserts.append( (hid,
pids[p],
@ -1780,39 +1781,41 @@ class Database:
#print "DEBUG: inserts: %s" %inserts
#print "DEBUG: q: %s" % q
c = self.get_cursor()
c.executemany(q, inserts)
for r in inserts:
c.execute(q, r)
hpid[(r[0], r[1])] = self.get_last_insert_id(c)
return hpid
def storeHandsActions(self, hid, pids, adata, printdata = False):
def storeHandsActions(self, hid, pids, hpid, adata, printdata = False):
#print "DEBUG: %s %s %s" %(hid, pids, adata)
if printdata:
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(adata)
#inserts = []
#for p in pdata:
# inserts.append( (hid,
# pids[p],
# adata[p]['startCash'],
# adata[p]['seatNo'],
# adata[p]['sitout'],
# adata[p]['card1'],
#handsPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
#street SMALLINT NOT NULL,
#actionNo SMALLINT NOT NULL,
#action CHAR(5) NOT NULL,
#allIn BOOLEAN NOT NULL,
#amount INT NOT NULL,
inserts = []
for a in adata:
inserts.append( (hpid[(hid, pids[adata[a]['player']])],
#self.getHandsPlayerId(self.hid, pids[adata[a]['player']]),
adata[a]['street'],
adata[a]['actionNo'],
adata[a]['streetActionNo'],
adata[a]['actionId'],
adata[a]['amount'],
adata[a]['raiseTo'],
adata[a]['amountCalled'],
adata[a]['numDiscarded'],
adata[a]['cardsDiscarded'],
adata[a]['allIn']
) )
q = self.sql.query['store_hands_actions']
#q = q.replace('%s', self.sql.query['placeholder'])
q = q.replace('%s', self.sql.query['placeholder'])
#print "DEBUG: inserts: %s" %inserts
#print "DEBUG: q: %s" % q
#c = self.get_cursor()
#c.executemany(q, inserts)
c = self.get_cursor()
c.executemany(q, inserts)
def storeHudCache(self, gid, pids, starttime, pdata):
"""Update cached statistics. If update fails because no record exists, do an insert."""

View File

@ -67,6 +67,7 @@ class Hand(object):
self.cancelled = False
self.dbid_hands = 0
self.dbid_pids = None
self.dbid_hpid = None
self.dbid_gt = 0
self.tablename = ""
self.hero = ""
@ -264,10 +265,11 @@ db: a connected Database object"""
hh['seats'] = len(self.dbid_pids)
self.dbid_hands = db.storeHand(hh)
db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, self.stats.getHandsPlayers(), printdata = printtest)
# TODO HandsActions - all actions for all players for all streets - self.actions
# HudCache data can be generated from HandsActions (HandsPlayers?)
#db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(), printdata = printtest)
self.dbid_hpid = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids,
self.stats.getHandsPlayers(), printdata = printtest)
db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.dbid_hpid,
self.stats.getHandsActions(), printdata = printtest)
else:
log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo'])
self.is_duplicate = True # i.e. don't update hudcache