diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 841d96d4..15c59c16 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 @@ -969,6 +972,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""" @@ -1785,3 +1812,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/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 @@ - - - - - - - - - - - - + + + + + + + + + + + + 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 c1d835b8..094b6d18 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -392,17 +392,17 @@ 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() for hand in handlist: - hand.prepInsert() - hand.insert() + #hand.prepInsert() + hand.insert(self.database) else: # conversion didn't work # TODO: appropriate response?