First working(?) version of siteneutral import

This commit is contained in:
Worros 2009-03-21 21:23:51 +09:00
parent 863e4f353b
commit ae4704b8dc
5 changed files with 30 additions and 21 deletions

View File

@ -41,8 +41,8 @@ class FpdbSQLQueries:
self.query['list_tables'] = """ """ self.query['list_tables'] = """ """
################################################################## ##################################################################
# Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax # Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax
################################################################## ##################################################################
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL') or (self.dbname == 'SQLite'): if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL') or (self.dbname == 'SQLite'):
self.query['drop_table'] = """DROP TABLE IF EXISTS """ self.query['drop_table'] = """DROP TABLE IF EXISTS """

View File

@ -58,13 +58,14 @@ class Importer:
self.cursor = None self.cursor = None
self.filelist = {} self.filelist = {}
self.dirlist = {} self.dirlist = {}
self.siteIds = {}
self.addToDirList = {} self.addToDirList = {}
self.removeFromFileList = {} # to remove deleted files self.removeFromFileList = {} # to remove deleted files
self.monitor = False self.monitor = False
self.updated = {} #Time last import was run {file:mtime} self.updated = {} #Time last import was run {file:mtime}
self.lines = None self.lines = None
self.faobs = None #File as one big string self.faobs = None # File as one big string
self.pos_in_file = {} # dict to remember how far we have read in the file self.pos_in_file = {} # dict to remember how far we have read in the file
#Set defaults #Set defaults
self.callHud = self.config.get_import_parameters().get("callFpdbHud") self.callHud = self.config.get_import_parameters().get("callFpdbHud")
if 'minPrint' not in self.settings: if 'minPrint' not in self.settings:
@ -111,6 +112,18 @@ class Importer:
def addImportFile(self, filename, site = "default", filter = "passthrough"): def addImportFile(self, filename, site = "default", filter = "passthrough"):
#TODO: test it is a valid file -> put that in config!! #TODO: test it is a valid file -> put that in config!!
self.filelist[filename] = [site] + [filter] self.filelist[filename] = [site] + [filter]
if site not in self.siteIds:
# Get id from Sites table in DB
self.fdb.cursor.execute(self.fdb.sql.query['getSiteId'], (site,))
result = self.fdb.cursor.fetchall()
if len(result) == 1:
self.siteIds[site] = result[0][0]
else:
if len(result) == 0:
print "[ERROR] Database ID for %s not found" % site
else:
print "[ERROR] More than 1 Database ID found for %s - Multiple currencies not implemented yet" % site
# Called from GuiBulkImport to add a file or directory. # Called from GuiBulkImport to add a file or directory.
def addBulkImportImportFileOrDir(self, inputPath,filter = "passthrough"): def addBulkImportImportFileOrDir(self, inputPath,filter = "passthrough"):
@ -289,9 +302,8 @@ class Importer:
print "TODO: implement importing tournament summaries" print "TODO: implement importing tournament summaries"
#self.faobs = readfile(inputFile) #self.faobs = readfile(inputFile)
#self.parseTourneyHistory() #self.parseTourneyHistory()
return 0 return (0,0,0,1,0)
site=fpdb_simple.recogniseSite(firstline)
category=fpdb_simple.recogniseCategory(firstline) category=fpdb_simple.recogniseCategory(firstline)
startpos=0 startpos=0
@ -322,7 +334,7 @@ class Importer:
try: try:
handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
,self.fdb.cursor, site, category, hand, self.config) ,self.fdb.cursor, self.siteIds[site], category, hand, self.config)
self.fdb.db.commit() self.fdb.db.commit()
stored+=1 stored+=1

View File

@ -21,7 +21,7 @@ import fpdb_simple
import fpdb_save_to_db import fpdb_save_to_db
#parses a holdem hand #parses a holdem hand
def mainParser(backend, db, cursor, category, hand, config): def mainParser(backend, db, cursor, siteID, category, hand, config):
category = fpdb_simple.recogniseCategory(hand[0]) category = fpdb_simple.recogniseCategory(hand[0])
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud" base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
@ -35,8 +35,6 @@ def mainParser(backend, db, cursor, category, hand, config):
#part 1: read hand no and check for duplicate #part 1: read hand no and check for duplicate
siteHandNo = fpdb_simple.parseSiteHandNo(hand[0]) siteHandNo = fpdb_simple.parseSiteHandNo(hand[0])
handStartTime = fpdb_simple.parseHandStartTime(hand[0]) handStartTime = fpdb_simple.parseHandStartTime(hand[0])
siteID = fpdb_simple.recogniseSiteID()
#print "parse logic, siteID:",siteID,"site:",site
isTourney = fpdb_simple.isTourney(hand[0]) isTourney = fpdb_simple.isTourney(hand[0])
smallBlindLine = 0 smallBlindLine = 0

View File

@ -28,10 +28,11 @@ SQLITE = 4
fastStoreHudCache = True # set this to True to test the new storeHudCache routine fastStoreHudCache = True # set this to True to test the new storeHudCache routine
saveActions = False # set this to False to avoid storing action data saveActions = True # set this to False to avoid storing action data
# Pros: speeds up imports # Pros: speeds up imports
# Cons: no action data is saved, so you need to keep the hand histories # Cons: no action data is saved, so you need to keep the hand histories
# variance not available on stats page # variance not available on stats page
# : No graphs
#stores a stud/razz hand into the database #stores a stud/razz hand into the database
def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time
@ -41,7 +42,7 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp
import_options = config.get_import_parameters() import_options = config.get_import_parameters()
saveActions = True if import_options['saveActions'] == 'True' else False saveActions = False if import_options['saveActions'] == 'False' else True
fastStoreHudCache = True if import_options['fastStoreHudCache'] == 'True' else False fastStoreHudCache = True if import_options['fastStoreHudCache'] == 'True' else False
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
@ -69,9 +70,11 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no,
"""stores a holdem/omaha hand into the database""" """stores a holdem/omaha hand into the database"""
import_options = config.get_import_parameters() import_options = config.get_import_parameters()
saveActions = True if import_options['saveActions'] == 'True' else False saveActions = False if import_options['saveActions'] == 'False' else True
fastStoreHudCache = True if import_options['fastStoreHudCache'] == 'True' else False fastStoreHudCache = True if import_options['fastStoreHudCache'] == 'True' else False
#print "DEBUG: saveActions: %s fastStoreHudCache: %s" %(saveActions, fastStoreHudCache)
t0 = time() t0 = time()
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
t1 = time() t1 = time()

View File

@ -691,14 +691,13 @@ def filterCrap(hand, isTourney):
hand[i] = False hand[i] = False
elif (hand[i]=="Betting is capped"): elif (hand[i]=="Betting is capped"):
hand[i] = False hand[i] = False
#site specific variable position filter
elif (hand[i].find(" said, \"")!=-1): elif (hand[i].find(" said, \"")!=-1):
hand[i] = False hand[i] = False
if isTourney: if isTourney:
if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))): if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))):
hand[i] = False hand[i] = False
elif: elif (hand[i].endswith(": sits out")):
if (hand[i].endswith(": sits out")):
hand[i] = False hand[i] = False
elif (hand[i].endswith(" is sitting out")): elif (hand[i].endswith(" is sitting out")):
hand[i] = False hand[i] = False
@ -1375,9 +1374,6 @@ def recognisePlayerNo(line, names, atype):
raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype) raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype)
#end def recognisePlayerNo #end def recognisePlayerNo
def recogniseSiteID():
return 2
#end def recogniseSiteID
#removes trailing \n from the given array #removes trailing \n from the given array
def removeTrailingEOL(arr): def removeTrailingEOL(arr):