From 129d09796e2dd6679f203b657c515b719781645d Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 2 Aug 2009 10:19:45 +0800 Subject: [PATCH 1/3] Fix HUD_config.xml.example to have correct stat names --- pyfpdb/HUD_config.xml.example | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pyfpdb/HUD_config.xml.example b/pyfpdb/HUD_config.xml.example index 3cd592cc..658c0527 100644 --- a/pyfpdb/HUD_config.xml.example +++ b/pyfpdb/HUD_config.xml.example @@ -210,7 +210,7 @@ - + @@ -219,7 +219,7 @@ - + @@ -228,7 +228,7 @@ - + @@ -237,7 +237,7 @@ - + @@ -246,7 +246,7 @@ - + @@ -255,7 +255,7 @@ - + @@ -274,18 +274,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + From 40a0fe428b2c4a040a71bb107ccd30c58c48385b Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 2 Aug 2009 11:03:35 +0800 Subject: [PATCH 2/3] Variable name change - hhc is better imho --- pyfpdb/fpdb_import.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index c1d835b8..b0e17f78 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -392,10 +392,10 @@ class Importer: mod = __import__(filter) obj = getattr(mod, filter_name, None) if callable(obj): - conv = obj(in_path = file, out_path = out_path, index = 0) # Index into file 0 until changeover - if(conv.getStatus() and self.NEWIMPORT == False): + hhc = obj(in_path = file, out_path = out_path, index = 0) # Index into file 0 until changeover + if(hhc.getStatus() and self.NEWIMPORT == False): (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(db, out_path, site, q) - elif (conv.getStatus() and self.NEWIMPORT == True): + elif (hhc.getStatus() and self.NEWIMPORT == True): #This code doesn't do anything yet handlist = hhc.getProcessedHands() self.pos_in_file[file] = hhc.getLastCharacterRead() From ff2cca361cb3ca83b057ba4cc7c04733abe3390c Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 2 Aug 2009 12:19:33 +0800 Subject: [PATCH 3/3] New insert player function for HHC import Added getSqlPlayerIDs to Database.py - returns a hash {playername:sqlid} Function uses a caching hash in Database.py to reduce the number of round trips to the database needed just to fetch the player ids for later inserts. Need to do a performance comparison on a larger import. --- pyfpdb/Database.py | 41 +++++++++++++++++++++++++++++++++++++++++ pyfpdb/Hand.py | 2 ++ pyfpdb/fpdb_import.py | 4 ++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index f9ebea39..9d835844 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -182,6 +182,9 @@ class Database: else: self.sql = sql + self.pcache = None # PlayerId cache + self.cachemiss = 0 # Delete me later - using to count player cache misses + # config while trying out new hudcache mechanism self.use_date_in_hudcache = True @@ -981,6 +984,30 @@ class Database: print "Error during fdb.lock_for_insert:", str(sys.exc_value) #end def lock_for_insert + def getSqlPlayerIDs(self, pnames, siteid): + result = {} + if(self.pcache == None): + self.pcache = LambdaDict(lambda key:self.insertPlayer(key, siteid)) + + for player in pnames: + result[player] = self.pcache[player] + + return result + + def insertPlayer(self, name, site_id): + self.cachemiss += 1 + result = None + c = self.get_cursor() + c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) + tmp=c.fetchall() + if (len(tmp)==0): #new player + c.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (name, site_id)) + c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) + tmp=c.fetchall() + #print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp + print "DEBUG: cache misses: %s" %self.cachemiss + return tmp[0][0] + def store_the_hand(self, h): """Take a HandToWrite object and store it in the db""" @@ -1797,3 +1824,17 @@ if __name__=="__main__": print "press enter to continue" sys.stdin.readline() + + +#Code borrowed from http://push.cx/2008/caching-dictionaries-in-python-vs-ruby +class LambdaDict(dict): + def __init__(self, l): + super(LambdaDict, self).__init__() + self.l = l + + def __getitem__(self, key): + if key in self: + return self.get(key) + else: + self.__setitem__(key, self.l(key)) + return self.get(key) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 0dbb9674..4d571b76 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -40,10 +40,12 @@ class Hand(object): LCS = {'H':'h', 'D':'d', 'C':'c', 'S':'s'} SYMBOL = {'USD': '$', 'EUR': u'$', 'T$': '', 'play': ''} MS = {'horse' : 'HORSE', '8game' : '8-Game', 'hose' : 'HOSE', 'ha': 'HA'} + SITEIDS = {'Fulltilt':1, 'PokerStars':2, 'Everleaf':3, 'Win2day':4, 'OnGame':5, 'UltimateBet':6, 'Betfair':7} def __init__(self, sitename, gametype, handText, builtFrom = "HHC"): self.sitename = sitename + self.siteId = self.SITEIDS[sitename] self.stats = DerivedStats.DerivedStats(self) self.gametype = gametype self.starttime = 0 diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index b0e17f78..094b6d18 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -401,8 +401,8 @@ class Importer: self.pos_in_file[file] = hhc.getLastCharacterRead() for hand in handlist: - hand.prepInsert() - hand.insert() + #hand.prepInsert() + hand.insert(self.database) else: # conversion didn't work # TODO: appropriate response?