def test_multiply(): df1 = load_series(generator="linear") df2 = load_series(generator="harmonic") df = process(function="multiply", df_first=df1, df_second=df2, first_col="u", second_col="u") assert df.columns == ["u"]
def test_data_create(): component_first_df = load_series(generator="harmonic", points=10000) component_second_df = load_series(generator="white_noise", points=10000) signal_df = component_first_df["u"] + component_second_df["u"] # saving file_path_3 = ( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/pure_data/gauss_additiv.txt") signal_df.to_csv(file_path_3, index=False, header=None) assert not signal_df.empty
def test_valid_dfa_handle(): df = load_series(path=abs_path + "/pure_data/close_mod.txt") df = process(function="profile", df=df) df = process(function="dfa_extended", df=df) dfa_handler(df) assert os.listdir(csv_dir) assert len(os.listdir(img_dir)) == 5
def test_dfa_many(): df = load_series(path=file_path) df = process(function="profile", df=df) df = process(function="dfa_extended", df=df) assert not df["dfa_lags"].empty assert not df["dfa_transform"].empty assert not df["dfa_ext_transform"].empty
def test_diff_solution_seq_handle_correctly(): diff_solution_df = load_series( generator="diff_sol", t=[1, 1, 1, 0.1, 0.1, 0.1], f=[f_x, f_y, f_z, f_u, f_v, f_w], ) diff_solution_df.columns = ["t", "x", "y", "z", "u", "v", "w"] # saving file_path_2 = ( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/pure_data/diff_sol.txt") diff_solution_df["u"].to_csv(file_path_2, index=False, header=None) assert not diff_solution_df.empty
def build_dfa_graphics(series_dir, path, scale) -> None: """ web-interface supporting method it contains all the step for DFA-transform building and saves processing result saves graphics of profile, time series alpha and betta coefficient dependence """ del_old_files("/static/images") del_old_files("/dataframes") # dfa building df = load_series(path=base_dir + "/" + series_dir + "/" + path) df = process(function="profile", df=df) df = process(function="dfa_extended", df=df) # routing files csv_path = base_dir + "/dataframes/dataframe.csv" orig_img_path = base_dir + "/static/images/orig.png" profile_img_path = base_dir + "/static/images/profile.png" dfa_img_path = base_dir + "/static/images/dfa.png" dfa_ext_img_path = base_dir + "/static/images/dfa_ext.png" dfa_many_img_path = base_dir + "/static/images/dfa_many.png" # saving results df.to_csv(csv_path, index=False) sns.lineplot(data=df["u"][scale[0]:scale[1]])\ .get_figure().savefig(orig_img_path) plt.clf() sns.lineplot(data=df["profile"]).get_figure().savefig(profile_img_path) plt.clf() sns.lineplot(x=df["dfa_lags"], y=df["dfa_ext_transform"]).get_figure().savefig( dfa_ext_img_path ) plt.clf() sns.lineplot(x=df["dfa_lags"], y=df["dfa_transform"]).get_figure().savefig( dfa_img_path ) sns.lineplot(x=df["dfa_lags"], y=df["dfa_ext_transform"]).get_figure().savefig( dfa_many_img_path ) plt.clf()
def build_cd_dfa_graphics(series_dir, path, scale): """ new algorithm - cd dfa build """ del_old_files("/static/images") del_old_files("/dataframes") # time series and cD coefficient obtaining df = load_series(path=base_dir + "/" + series_dir + "/" + path) order = "db8" cA, cD = pywt.dwt(df, order) cd_df = pd.DataFrame({"u": cD.transpose()[-1]}) # dfa building df = process(function="profile", df=df) df = process(function="dfa_extended", df=df) cd_df = process(function="profile", df=cd_df) cd_df = process(function="dfa_extended", df=cd_df) # routing files orig_img_path = base_dir + "/static/images/time_series.png" cd_img_path = base_dir + "/static/images/cD.png" cd_dfa_img_path = base_dir + "/static/images/DFA_cD.png" ts_path = base_dir + "/dataframes/time_series.csv" cd_path = base_dir + "/dataframes/cD.csv" # saving results df.to_csv(ts_path, index=False) cd_df.to_csv(cd_path, index=False) sns.lineplot(data=df["u"][scale[0]:scale[1]])\ .get_figure().savefig(orig_img_path) plt.clf() sns.lineplot(data=cd_df["u"]).get_figure().savefig(cd_img_path) plt.clf() sns.lineplot(x=cd_df["dfa_lags"], y=cd_df["dfa_transform"]).get_figure().savefig( cd_dfa_img_path ) plt.clf()
def test_existing_raw_file_aggregation(): assert not load_series(path=file_path).empty
def save_ts(upload_dir, file_name): # pre-index() process(function="filtering", df=load_series(path="pure_data/linear.txt"))\ .to_csv(f"{upload_dir}/{file_name}", header=None, index=False)
def test_dfa_points(): df = load_series(path=file_path) df = process(function="profile", df=df) df = process(function="dfa_extended", df=df) assert (len(df["dfa_lags"]) == len(df["dfa_transform"]) == len( df["dfa_ext_transform"]))
def test_akf(): lags_points = 10 df = load_series(generator="harmonic") df = process(function="akf", df=df, lags=lags_points) assert not df["akf"].empty
def test_approximation(): df = load_series(path=file_path) df = process(function="approx", df=df) assert not df["approx"].empty
def test_profile(): df = load_series(path=file_path) df = process(function="profile", df=df) assert not df["profile"].empty
def test_integrate(): df = load_series(path=file_path) df = process(function="integrate", df=df) assert not df["integrate"].empty