First working(?) version of siteneutral import
This commit is contained in:
		
							parent
							
								
									863e4f353b
								
							
						
					
					
						commit
						ae4704b8dc
					
				|  | @ -41,8 +41,8 @@ class FpdbSQLQueries: | |||
|             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'): | ||||
|             self.query['drop_table'] = """DROP TABLE IF EXISTS """ | ||||
|  |  | |||
|  | @ -58,13 +58,14 @@ class Importer: | |||
|         self.cursor     = None | ||||
|         self.filelist   = {} | ||||
|         self.dirlist    = {} | ||||
|         self.siteIds    = {} | ||||
|         self.addToDirList = {} | ||||
|         self.removeFromFileList = {} # to remove deleted files | ||||
|         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.faobs      = None       #File as one big string | ||||
|         self.pos_in_file = {} # dict to remember how far we have read in the file | ||||
|         self.faobs      = None       # File as one big string | ||||
|         self.pos_in_file = {}        # dict to remember how far we have read in the file | ||||
|         #Set defaults | ||||
|         self.callHud    = self.config.get_import_parameters().get("callFpdbHud") | ||||
|         if 'minPrint' not in self.settings: | ||||
|  | @ -111,6 +112,18 @@ class Importer: | |||
|     def addImportFile(self, filename, site = "default", filter = "passthrough"): | ||||
|         #TODO: test it is a valid file -> put that in config!! | ||||
|         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. | ||||
|     def addBulkImportImportFileOrDir(self, inputPath,filter = "passthrough"): | ||||
|  | @ -289,9 +302,8 @@ class Importer: | |||
|             print "TODO: implement importing tournament summaries" | ||||
|             #self.faobs = readfile(inputFile) | ||||
|             #self.parseTourneyHistory() | ||||
|             return 0 | ||||
|             return (0,0,0,1,0) | ||||
| 
 | ||||
|         site=fpdb_simple.recogniseSite(firstline) | ||||
|         category=fpdb_simple.recogniseCategory(firstline) | ||||
| 
 | ||||
|         startpos=0 | ||||
|  | @ -322,7 +334,7 @@ class Importer: | |||
| 
 | ||||
|                     try: | ||||
|                         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() | ||||
| 
 | ||||
|                         stored+=1 | ||||
|  |  | |||
|  | @ -21,7 +21,7 @@ import fpdb_simple | |||
| import fpdb_save_to_db | ||||
| 
 | ||||
| #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]) | ||||
| 
 | ||||
|     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 | ||||
|     siteHandNo      = fpdb_simple.parseSiteHandNo(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]) | ||||
|     smallBlindLine  = 0 | ||||
|  |  | |||
|  | @ -28,10 +28,11 @@ SQLITE          = 4 | |||
| 
 | ||||
| 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 | ||||
|                     # Cons: no action data is saved, so you need to keep the hand histories | ||||
|                     #       variance not available on stats page | ||||
|                     #     : No graphs | ||||
|   | ||||
| #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 | ||||
|  | @ -41,7 +42,7 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp | |||
| 
 | ||||
|     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 | ||||
| 
 | ||||
|     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""" | ||||
| 
 | ||||
|     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 | ||||
| 
 | ||||
|     #print "DEBUG: saveActions: %s fastStoreHudCache: %s" %(saveActions, fastStoreHudCache) | ||||
| 
 | ||||
|     t0 = time() | ||||
|     fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits) | ||||
|     t1 = time() | ||||
|  |  | |||
|  | @ -691,14 +691,13 @@ def filterCrap(hand, isTourney): | |||
|             hand[i] = False | ||||
|         elif (hand[i]=="Betting is capped"): | ||||
|             hand[i] = False | ||||
|         #site specific variable position filter | ||||
|         elif (hand[i].find(" said, \"")!=-1): | ||||
|             hand[i] = False | ||||
| 
 | ||||
|         if isTourney: | ||||
|             if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))): | ||||
|                 hand[i] = False | ||||
|         elif: | ||||
|             if (hand[i].endswith(": sits out")): | ||||
|             elif (hand[i].endswith(": sits out")): | ||||
|                 hand[i] = False | ||||
|             elif (hand[i].endswith(" is sitting out")): | ||||
|                 hand[i] = False | ||||
|  | @ -1375,9 +1374,6 @@ def recognisePlayerNo(line, names, atype): | |||
|     raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype) | ||||
| #end def recognisePlayerNo | ||||
|   | ||||
| def recogniseSiteID(): | ||||
|     return 2 | ||||
| #end def recogniseSiteID | ||||
|   | ||||
| #removes trailing \n from the given array | ||||
| def removeTrailingEOL(arr): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user