def download_experiment_to_file(experiment_name, file_path): if os.path.exists(file_path): os.unlink(file_path) file_database = ExperimentDatabaseManager(file=file_path, cache_size=100000) file_database.set_experiment(experiment_name) reading_manager = ExperimentDatabaseReadingManager(mysql_credentials=credentials) query = '''SELECT (table_name) FROM information_schema.columns WHERE column_name = 'experiment_name' AND table_schema = '%s';''' % credentials['database'] data = reading_manager.get_data_from_query(query) tables = [x[0] for x in data] tables.remove('experiments') print("Gotten list of all tables:") print('\n'.join(tables)) for table in tables: print("Downloading data from ", table) table_data = reading_manager.get_data(table, experiment_name) if table_data is None: print("No data found in table for this experiment, skipping") continue print("Gotten keys", table_data.keys()) for key in table_data.keys(): print('\t%s is %s' % (key, str(type(table_data[key][0])))) table_data.pop('experiment_name') file_database.insert_experiment_data(table, table_data) print("Finishing up writing to file...") file_database.close()
def test_read_write_4(self): if os.path.exists('sample.db'): os.unlink('sample.db') database_manager = ExperimentDatabaseManager(file='sample.db', cache_size=40) database_manager.delete_experiment( 'writing_numerical_data_test_case_4') database_manager.set_experiment('writing_numerical_data_test_case_4') inserted_data = dict() inserted_data['var_1'] = 19 inserted_data['var_2'] = 109 inserted_data['var_3'] = np.nan database_manager.insert_experiment_data( 'writing_numerical_data_test_case_4', inserted_data) database_manager.flush() database_manager_2 = ExperimentDatabaseReadingManager(file='sample.db') read_back_data = database_manager_2.get_data( 'writing_numerical_data_test_case_4', 'writing_numerical_data_test_case_4') assert read_back_data['var_1'][0] == inserted_data[ 'var_1'] # Always returns list assert read_back_data['var_2'][0] == inserted_data[ 'var_2'] # Always returns list assert read_back_data['var_3'][0] == 0 # Always returns list # Doing it at the end to check if it flushing works properly database_manager.delete_experiment( 'writing_numerical_data_test_case_4') database_manager.close()
def test_read_write_4(self): database_manager = ExperimentDatabaseManager( mysql_credentials=sql_credentials.credentials, cache_size=40) database_manager.delete_experiment( 'writing_numerical_data_test_case_4') database_manager.set_experiment('writing_numerical_data_test_case_4') inserted_data = dict() inserted_data['var_1'] = 19 inserted_data['var_2'] = 109 inserted_data['var_3'] = np.nan database_manager.insert_experiment_data( 'writing_numerical_data_test_case_4', inserted_data) database_manager.flush() database_manager_2 = ExperimentDatabaseReadingManager( mysql_credentials=sql_credentials.credentials) read_back_data = database_manager_2.get_data( 'writing_numerical_data_test_case_4', 'writing_numerical_data_test_case_4') assert read_back_data['var_1'][0] == inserted_data[ 'var_1'] # Always returns list assert read_back_data['var_2'][0] == inserted_data[ 'var_2'] # Always returns list assert read_back_data['var_3'][0] == 0 # Always returns list # Doing it at the end to check if it flushing works properly database_manager.delete_experiment( 'writing_numerical_data_test_case_4') database_manager.close()
def test_read_write_3(self): if os.path.exists('sample.db'): os.unlink('sample.db') database_manager = ExperimentDatabaseManager(file='sample.db', cache_size=40) database_manager.delete_experiment( 'writing_numerical_data_test_case_3') database_manager.set_experiment('writing_numerical_data_test_case_3') inserted_data = dict() inserted_data['var_1'] = np.array([19, 20]) inserted_data['var_2'] = np.array([109, 110]) inserted_data['var_3'] = np.array([54.1, 43]) inserted_data['var_4'] = np.array(['hello', 'world']) database_manager.insert_experiment_data( 'writing_numerical_data_test_case_3', inserted_data) database_manager.flush() database_manager_2 = ExperimentDatabaseReadingManager(file='sample.db') read_back_data = database_manager_2.get_data( 'writing_numerical_data_test_case_3', 'writing_numerical_data_test_case_3') assert read_back_data['var_1'][0] == inserted_data['var_1'][0] assert read_back_data['var_1'][1] == inserted_data['var_1'][1] assert read_back_data['var_2'][0] == inserted_data['var_2'][0] assert read_back_data['var_2'][1] == inserted_data['var_2'][1] assert read_back_data['var_3'][0] == inserted_data['var_3'][0] assert read_back_data['var_3'][1] == inserted_data['var_3'][1] assert read_back_data['var_4'][0] == inserted_data['var_4'][0] assert read_back_data['var_4'][1] == inserted_data['var_4'][1] # Doing it at the end to check if it flushing works properly # database_manager.delete_experiment('writing_numerical_data_test_case_3') database_manager.close()
def test_read_write_2(self): database_manager = ExperimentDatabaseManager( mysql_credentials=sql_credentials.credentials, cache_size=40) database_manager.delete_experiment( 'writing_numerical_data_test_case_2') database_manager.set_experiment('writing_numerical_data_test_case_2') inserted_data = dict() inserted_data['var_1'] = [19, 20] inserted_data['var_2'] = [109, 110] inserted_data['var_3'] = [54.1, 43] database_manager.insert_experiment_data( 'writing_numerical_data_test_case_2', inserted_data) database_manager.flush() database_manager_2 = ExperimentDatabaseReadingManager( mysql_credentials=sql_credentials.credentials) read_back_data = database_manager_2.get_data( 'writing_numerical_data_test_case_2', 'writing_numerical_data_test_case_2') assert read_back_data['var_1'][0] == inserted_data['var_1'][0] assert read_back_data['var_1'][1] == inserted_data['var_1'][1] assert read_back_data['var_2'][0] == inserted_data['var_2'][0] assert read_back_data['var_2'][1] == inserted_data['var_2'][1] assert read_back_data['var_3'][0] == inserted_data['var_3'][0] assert read_back_data['var_3'][1] == inserted_data['var_3'][1] # Doing it at the end to check if it flushing works properly database_manager.delete_experiment( 'writing_numerical_data_test_case_2') database_manager.close()