コード例 #1
0
def test_get_clean_cycles():
    """Tests that cycles are cleaned and saved in database"""
    test_db = 'my_great_db.db'
    test_filename = 'my_great_data.xlsx'
    test_decoded_df = pd.DataFrame({
        'Cycle_Index': [1, 1, 2, 2, 2],
        'Data_Point': [0, 1, 2, 3, 4],
        'Voltage(V)': [4, 8, 16, 8, 4],
        'Current(A)': [2, 4, 6, 8, 12],
        'Discharge_Capacity(Ah)': [10, 0, 30, 0, 10],
        'Charge_Capacity(Ah)': [0, 20, 0, 10, 0],
        'Step_Index': [1, 0, 1, 0, 1]
    })
    test_datatype = 'ARBIN'
    # initialize database:
    init_master_table(test_db)
    core_test_filename = get_filename_pref(test_filename)
    parse_update_master(core_test_filename, test_db, test_datatype,
                        test_decoded_df)
    # set up by adding raw data frame to database
    cycle_dict = load_sep_cycles(core_test_filename, test_db, test_datatype)
    result = get_clean_cycles(cycle_dict,
                              core_test_filename,
                              test_db,
                              test_datatype,
                              windowlength=9,
                              polyorder=3)
    assert core_test_filename + '-CleanCycle1' in get_table_names(test_db)
    assert type(result) == dict
    assert list(result.keys()) == [
        core_test_filename + '-CleanCycle1',
        core_test_filename + '-CleanCycle2'
    ]
    os.remove(test_db)
コード例 #2
0
def test_get_table_names():
    """Tests that the correct table names are returned"""
    # first make sure all data is processed
    process_data(test_filename, test_db, decoded_dataframe, test_datatype)
    new_peak_thresh = 0.7
    core_filename = get_filename_pref(test_filename)
    df_clean = get_file_from_database(core_filename + 'CleanSet', test_db)
    feedback = generate_model(df_clean, core_filename, new_peak_thresh,
                              test_db)
    assert core_filename + 'ModParams' in get_table_names(test_db)
    param_dicts_to_df(core_filename + 'ModParams', test_db)

    names_list = get_table_names(test_db)
    expected_list = [
        'master_table', 'test_data-CleanCycle1', 'test_data-Cycle1',
        'test_data-ModPoints', 'test_data-descriptors', 'test_dataCleanSet',
        'test_dataModParams', 'test_dataRaw', 'test_dataUnalteredRaw'
    ]
    assert set(names_list) == set(expected_list)
    os.remove(test_db)
    return
コード例 #3
0
def test_process_data():
    """Tests the process data function adds the correct
    datatables to the database."""
    ans = process_data(test_filename, test_db, decoded_dataframe,
                       test_datatype)
    # shouldn't return anything:
    assert ans == None
    names_list = get_table_names(test_db)
    assert 'master_table' in names_list
    list_new_tables = ['Raw', '-CleanCycle1', '-Cycle1', 'CleanSet']
    for i in list_new_tables:
        assert get_filename_pref(test_filename) + i in names_list
    os.remove(test_db)
    return
コード例 #4
0
def test_param_dicts_to_df():
    """Tests the parameter dictionaries generated by the model
    functions are parsed nicely and added to the database in the 
    modparams table"""

    process_data(test_filename, test_db, decoded_dataframe, test_datatype)
    core_test_filename = get_filename_pref(test_filename)
    new_peak_thresh = 0.7
    df_clean = get_file_from_database(core_test_filename + 'CleanSet', test_db)
    feedback = generate_model(
        df_clean, core_test_filename, new_peak_thresh, test_db)
    assert core_test_filename + 'ModParams' in get_table_names(test_db)
    param_dicts_to_df(core_test_filename + 'ModParams', test_db)
    assert core_test_filename + '-descriptors' in get_table_names(test_db)
    desc_df = get_file_from_database(
        core_test_filename + '-descriptors', test_db)
    expected_cols = ['d_gauss_sigma', 'd_gauss_center', 'd_gauss_amplitude',
                     'd_gauss_fwhm', 'd_gauss_height', 'd_cycle_number',
                                     'c_gauss_sigma', 'c_gauss_center', 'c_gauss_amplitude',
                                     'c_gauss_fwhm', 'c_gauss_height', 'c_cycle_number']
    for col in expected_cols:
        assert col in desc_df.columns
    os.remove(test_db)
    return
コード例 #5
0
def test_generate_model_for_maccor():
    """Tests that three new tables are generated in the database 
    in the process of generating the model. Acutal model generation
    functions are tested further outside of this wrapper."""
    peak_thresh = 0.7

    process_data(test_filename_mac, test_db, decoded_dataframe_mac,
                 test_datatype_mac)
    filename_pref = get_filename_pref(test_filename_mac)
    df_clean, df_raw = pop_with_db(test_filename_mac, test_db)

    feedback = generate_model(df_clean, filename_pref,
                              peak_thresh, test_db)
    assert type(feedback) == str
    names_list = get_table_names(test_db)

    list_new_tables = ['-ModPoints', 'ModParams', '-descriptors']
    for i in list_new_tables:
        assert filename_pref + i in names_list
    os.remove(test_db)
    return