From 5550166f372a2f56cb7f0e0f638f5a79dcbd2556 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 8 Aug 2009 16:15:36 +0800 Subject: [PATCH 1/3] Start of storeHand from HHC code Currently cant actually insert as we need the fk gametypeid --- pyfpdb/Database.py | 94 +++++++++++++++++++++++----------------------- pyfpdb/Hand.py | 35 +++++++++-------- 2 files changed, 64 insertions(+), 65 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index e83daac0..d59c879c 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1043,7 +1043,7 @@ class Database: q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s" q = q.replace('%s', self.sql.query['placeholder']) - print "DEBUG: name: %s site: %s" %(name, site_id) + #print "DEBUG: name: %s site: %s" %(name, site_id) c.execute (q, (site_id, name)) @@ -1121,70 +1121,70 @@ class Database: def storeHand(self, p): #stores into table hands: - self.cursor.execute ("""INSERT INTO Hands ( + q = """INSERT INTO Hands ( tablename, - sitehandno, gametypeid, + sitehandno, handstart, importtime, - seats, maxseats, boardcard1, boardcard2, boardcard3, boardcard4, - boardcard5, --- texture, - playersVpi, - playersAtStreet1, - playersAtStreet2, - playersAtStreet3, - playersAtStreet4, - playersAtShowdown, - street0Raises, - street1Raises, - street2Raises, - street3Raises, - street4Raises, --- street1Pot, --- street2Pot, --- street3Pot, --- street4Pot, --- showdownPot + boardcard5 ) VALUES - (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, - %s, %s, %s, %s, %s, %s, %s)""", - ( - p['tablename'], - p['sitehandno'], + (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" +#--- texture, +#-- playersVpi, +#-- playersAtStreet1, +#-- playersAtStreet2, +#-- playersAtStreet3, +#-- playersAtStreet4, +#-- playersAtShowdown, +#-- street0Raises, +#-- street1Raises, +#-- street2Raises, +#-- street3Raises, +#-- street4Raises, +#-- street1Pot, +#-- street2Pot, +#-- street3Pot, +#-- street4Pot, +#-- showdownPot +#-- seats, + + q = q.replace('%s', self.sql.query['placeholder']) + self.cursor.execute(q, ( + p['tableName'], + p['siteHandNo'], p['gametypeid'], p['handStart'], - datetime.datetime.today(), - len(p['names']), + datetime.today(), #importtime +# len(p['names']), #seats p['maxSeats'], p['boardcard1'], p['boardcard2'], p['boardcard3'], p['boardcard4'], - p['boardcard5'], - hudCache['playersVpi'], - hudCache['playersAtStreet1'], - hudCache['playersAtStreet2'], - hudCache['playersAtStreet3'], - hudCache['playersAtStreet4'], - hudCache['playersAtShowdown'], - hudCache['street0Raises'], - hudCache['street1Raises'], - hudCache['street2Raises'], - hudCache['street3Raises'], - hudCache['street4Raises'], - hudCache['street1Pot'], - hudCache['street2Pot'], - hudCache['street3Pot'], - hudCache['street4Pot'], - hudCache['showdownPot'] - ) + p['boardcard5']) +# hudCache['playersVpi'], +# hudCache['playersAtStreet1'], +# hudCache['playersAtStreet2'], +# hudCache['playersAtStreet3'], +# hudCache['playersAtStreet4'], +# hudCache['playersAtShowdown'], +# hudCache['street0Raises'], +# hudCache['street1Raises'], +# hudCache['street2Raises'], +# hudCache['street3Raises'], +# hudCache['street4Raises'], +# hudCache['street1Pot'], +# hudCache['street2Pot'], +# hudCache['street3Pot'], +# hudCache['street4Pot'], +# hudCache['showdownPot'] ) #return getLastInsertId(backend, conn, cursor) # def storeHand diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 75aab808..f28e654d 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -187,29 +187,28 @@ db: a connected fpdb_db object""" sqlids = db.getSqlPlayerIDs([p[1] for p in self.players], self.siteId) # HudCache data to come from DerivedStats class # HandsActions - all actions for all players for all streets - self.actions - # BoardCards - Skip - no longer necessary # Hands - Summary information of hand indexed by handId - gameinfo - #hh['siteHandNo'] = self.handid - # gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - # - #hh['handStart'] = self.starttime - # seats TINYINT NOT NULL, - # - #hh['tableName'] = self.tablenam - #hh['maxSeats'] = self.maxseats + #This should be moved to prepInsert + hh = {} + hh['siteHandNo'] = self.handid + hh['handStart'] = self.starttime + # seats TINYINT NOT NULL, + hh['tableName'] = self.tablename + hh['maxSeats'] = self.maxseats # boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ # boardcard2 smallint, # boardcard3 smallint, # boardcard4 smallint, # boardcard5 smallint, - # Flop turn and river may all be empty - add (likely) too many elements and trim with range - # boardcards = board['FLOP'] + board['TURN'] + board['RIVER'] + [u'0x', u'0x', u'0x', u'0x', u'0x'] - # cards = [Card.cardFromValueSuit(v,s) for v,s in boardcards[0:4]] - # hh['boardcard1'] = cards[0] - # hh['boardcard2'] = cards[1] - # hh['boardcard3'] = cards[2] - # hh['boardcard4'] = cards[3] - # hh['boardcard5'] = cards[4] + # Flop turn and river may all be empty - add (likely) too many elements and trim with range + boardcards = self.board['FLOP'] + self.board['TURN'] + self.board['RIVER'] + [u'0x', u'0x', u'0x', u'0x', u'0x'] + cards = [Card.encodeCard(c) for c in boardcards[0:5]] + hh['boardcard1'] = cards[0] + hh['boardcard2'] = cards[1] + hh['boardcard3'] = cards[2] + hh['boardcard4'] = cards[3] + hh['boardcard5'] = cards[4] + print hh # texture smallint, # playersVpi SMALLINT NOT NULL, /* num of players vpi */ # Needs to be recorded @@ -244,7 +243,7 @@ db: a connected fpdb_db object""" # showdownPot INT, /* pot size at sd/street7 */ # comment TEXT, # commentTs DATETIME - # handid = db.storeHand(hh) + handid = db.storeHand(hh) # HandsPlayers - ? ... Do we fix winnings? # Tourneys ? # TourneysPlayers From a70bd9742d6f3af3d56d2b9e4f1c9e77e399e934 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 8 Aug 2009 16:43:52 +0800 Subject: [PATCH 2/3] Add Gametype insert Almost done, need to convert 0.25 to 25 for the database - Lookup? --- pyfpdb/Hand.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f28e654d..8c165bd9 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -185,6 +185,24 @@ db: a connected fpdb_db object""" # TODO: # Players - base playerid and siteid tuple sqlids = db.getSqlPlayerIDs([p[1] for p in self.players], self.siteId) + + #Gametypes + + print "DEBUG: self.gametype %s" % self.gametype + #Nice way to discover if the game is already listed in the db? + #Also this is using an old method from fpdb_simple - should probably conform to the rest of the inserts + + hilo = "h" + if self.gametype['category'] in ['studhilo', 'omahahilo']: + hilo = "s" + elif self.gametype['category'] in ['razz','27_3draw','badugi']: + hilo = "l" + #FIXME - the two zeros are small_bet and big_bet for limit + gtid = db.insertGameTypes( (self.siteId, self.gametype['type'], self.gametype['base'], + self.gametype['category'], self.gametype['limitType'], hilo, + self.gametype['sb'], self.gametype['bb'], 0, 0) ) + + # HudCache data to come from DerivedStats class # HandsActions - all actions for all players for all streets - self.actions # Hands - Summary information of hand indexed by handId - gameinfo @@ -208,6 +226,7 @@ db: a connected fpdb_db object""" hh['boardcard3'] = cards[2] hh['boardcard4'] = cards[3] hh['boardcard5'] = cards[4] + print hh # texture smallint, # playersVpi SMALLINT NOT NULL, /* num of players vpi */ From d6529ab42f4a1bc822d96a4ee88b424f0688d0dc Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 9 Aug 2009 01:59:44 +0800 Subject: [PATCH 3/3] Import Hand.insert() work storeHand updated, almost works, just violating some NOT NULL contraints --- pyfpdb/Database.py | 10 ++++++++-- pyfpdb/Hand.py | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index d59c879c..6fb96507 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -28,6 +28,7 @@ import sys import traceback from datetime import datetime, date, time, timedelta from time import time, strftime, sleep +from decimal import Decimal import string import re import logging @@ -1127,6 +1128,7 @@ class Database: sitehandno, handstart, importtime, + seats, maxseats, boardcard1, boardcard2, @@ -1135,7 +1137,8 @@ class Database: boardcard5 ) VALUES - (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" + (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s)""" #--- texture, #-- playersVpi, #-- playersAtStreet1, @@ -1156,14 +1159,17 @@ class Database: #-- seats, q = q.replace('%s', self.sql.query['placeholder']) + print "DEBUG: p: %s" %p + print "DEBUG: gtid: %s" % p['gameTypeId'] self.cursor.execute(q, ( p['tableName'], + p['gameTypeId'], p['siteHandNo'], - p['gametypeid'], p['handStart'], datetime.today(), #importtime # len(p['names']), #seats p['maxSeats'], + p['seats'], p['boardcard1'], p['boardcard2'], p['boardcard3'], diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 8c165bd9..c3bd93f0 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -197,10 +197,10 @@ db: a connected fpdb_db object""" hilo = "s" elif self.gametype['category'] in ['razz','27_3draw','badugi']: hilo = "l" - #FIXME - the two zeros are small_bet and big_bet for limit + gtid = db.insertGameTypes( (self.siteId, self.gametype['type'], self.gametype['base'], self.gametype['category'], self.gametype['limitType'], hilo, - self.gametype['sb'], self.gametype['bb'], 0, 0) ) + int(Decimal(self.gametype['sb'])*100), int(Decimal(self.gametype['bb'])*100), 0, 0) ) # HudCache data to come from DerivedStats class @@ -210,9 +210,11 @@ db: a connected fpdb_db object""" hh = {} hh['siteHandNo'] = self.handid hh['handStart'] = self.starttime + hh['gameTypeId'] = gtid[0] # seats TINYINT NOT NULL, hh['tableName'] = self.tablename hh['maxSeats'] = self.maxseats + hh['seats'] = len(sqlids) # boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ # boardcard2 smallint, # boardcard3 smallint,