示例#1
0
    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()
示例#2
0
    def test_write_to_network_and_file_and_read_from_both(self):
        if os.path.exists('sample.db'):
            os.unlink('sample.db')

        print("Writing to server")
        database_manager = ExperimentDatabaseManager(
            mysql_credentials=sql_credentials.credentials,
            file='sample.db',
            cache_size=40)
        database_manager.delete_experiment('database_plots_test_case_1')
        database_manager.set_experiment('database_plots_test_case_1')

        self.write_to_database(database_manager)
        database_manager.close()

        download_experiment_to_file(
            experiment_name='database_plots_test_case_1',
            file_path='output/downloaded_database.db')

        print("Reading back from downloaded file")
        database_reading_manager = ExperimentDatabaseReadingManager(
            file='output/downloaded_database.db')
        self.read_from_database(database_reading_manager)

        print("Reading back from cache file")
        database_reading_manager = ExperimentDatabaseReadingManager(
            file='sample.db')
        self.read_from_database(database_reading_manager)

        database_manager = ExperimentDatabaseManager(
            mysql_credentials=sql_credentials.credentials, cache_size=40)
        database_manager.delete_experiment('database_plots_test_case_1')
        database_manager.close()
示例#3
0
    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()
示例#4
0
    def test_read_write(self):
        print("Writing")
        self.write_to_database()

        print("Reading back")
        self.read_from_database()

        database_manager = ExperimentDatabaseManager(mysql_credentials=sql_credentials.credentials, cache_size=40)
        database_manager.delete_experiment('database_plots_test_case_1')
        database_manager.close()
示例#5
0
    def write_to_database(self):
        database_manager = ExperimentDatabaseManager(mysql_credentials=sql_credentials.credentials, cache_size=40)
        database_manager.delete_experiment('database_plots_test_case_1')
        database_manager.set_experiment('database_plots_test_case_1')

        efficiency_plot = General2dBinningPlot(bins=np.array([0, 1, 2, 3, 4]), histogram_log=False,
                                               histogram_fraction=False)
        x_values = np.array([0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3])
        y_values = np.array([0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3])
        #
        # print(type(x_values))
        efficiency_plot.add_raw_values(x_values=x_values, y_values=y_values,
                                       tags={'beta_threshold': 0.1, 'dist_threshold': 0.9})
        efficiency_plot.draw()
        efficiency_plot.write_to_database(database_manager,table_name='database_plots_test_case_1')

        plt.savefig('output/test-original-plot.png')
        database_manager.close()
示例#6
0
    def test_read_write_file(self):
        if os.path.exists('sample.db'):
            os.unlink('sample.db')
        database_manager = ExperimentDatabaseManager(file='sample.db',
                                                     cache_size=40)
        database_manager.delete_experiment('database_plots_test_case_1')
        database_manager.set_experiment('database_plots_test_case_1')

        print("Writing to file")
        self.write_to_database(database_manager)
        database_manager.close()

        print("Reading back from file")
        database_reading_manager = ExperimentDatabaseReadingManager(
            file='sample.db')
        self.read_from_database(database_reading_manager)

        if os.path.exists('sample.db'):
            os.unlink('sample.db')
示例#7
0
    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()
示例#8
0
    def test_read_write(self):
        print("Writing to server")
        database_manager = ExperimentDatabaseManager(
            mysql_credentials=sql_credentials.credentials, cache_size=40)
        print("Deleting experiment")
        database_manager.delete_experiment('database_plots_test_case_1')
        print("Setting experiment")
        database_manager.set_experiment('database_plots_test_case_1')

        self.write_to_database(database_manager)
        print("Here, closing")
        database_manager.close()

        print("Reading back from server")
        database_reading_manager = ExperimentDatabaseReadingManager(
            sql_credentials.credentials)
        self.read_from_database(database_reading_manager)

        database_manager = ExperimentDatabaseManager(
            mysql_credentials=sql_credentials.credentials, cache_size=40)
        database_manager.delete_experiment('database_plots_test_case_1')
        database_manager.close()
示例#9
0
    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()