From a76e34598d22d7384215c0250532679b3580c956 Mon Sep 17 00:00:00 2001 From: Chaz Date: Tue, 28 Sep 2010 17:09:24 -0400 Subject: [PATCH] * 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 --- pyfpdb/Database.py | 49 ++++++++++++++++++++++++---------------------- pyfpdb/Hand.py | 10 ++++++---- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index a44f28f5..d3deb578 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -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.""" diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 9afd5ca5..86eaa34c 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -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