|
5 | 5 |
|
6 | 6 | from typing import List
|
7 | 7 |
|
8 |
| -from dataframes import repair_dropped_frames |
| 8 | +from dataframes import repair_dropped_frames, compute_time_range, trim_into_interval |
9 | 9 |
|
10 | 10 | import pandas as pd
|
11 | 11 |
|
| 12 | +import pandas.testing as pd_testing |
| 13 | + |
| 14 | +import numpy as np |
| 15 | + |
12 | 16 | RECSYNCH_SESSION_DIR_VAR = "RECSYNCH_SESSION_DIR"
|
13 | 17 |
|
14 | 18 | print(f"Getting data dir from {RECSYNCH_SESSION_DIR_VAR} environment variable...")
|
|
21 | 25 | # raise Exception(f"Environment variable {RECSYNCH_SESSION_DIR_VAR} not defined")
|
22 | 26 |
|
23 | 27 |
|
24 |
| -def client_IDs() -> List[str]: |
| 28 | +# def client_IDs() -> List[str]: |
| 29 | + |
| 30 | +# out = [] |
| 31 | + |
| 32 | +# for p in Path(RECSYNCH_SESSION_DIR).iterdir(): |
| 33 | +# print("-->", p.stem) |
| 34 | +# out.append(p) |
| 35 | + |
| 36 | +# return out |
| 37 | + |
| 38 | + |
| 39 | +# def CSVs() -> List[str]: |
25 | 40 |
|
26 |
| - out = [] |
| 41 | +# out = [] |
27 | 42 |
|
28 |
| - for p in Path(RECSYNCH_SESSION_DIR).iterdir(): |
29 |
| - print("-->", p.stem) |
30 |
| - out.append(p) |
| 43 | +# clients = client_IDs() |
| 44 | +# for c in clients: |
| 45 | +# client_dir = Path(RECSYNCH_SESSION_DIR) / c |
| 46 | +# for csv_file in client_dir.glob("*.csv"): |
| 47 | +# print("==>", csv_file) |
| 48 | +# rel_filepath = str(csv_file.relative_to(RECSYNCH_SESSION_DIR)) |
| 49 | +# print("++>", rel_filepath) |
| 50 | +# out.append(rel_filepath) |
31 | 51 |
|
32 |
| - return out |
| 52 | +# return out |
33 | 53 |
|
34 | 54 |
|
35 |
| -def CSVs() -> List[str]: |
| 55 | +# @pytest.mark.parametrize("csv_file", CSVs()) |
| 56 | +# def test_df_reparation(csv_file): |
36 | 57 |
|
37 |
| - out = [] |
| 58 | +# # Load the test dataframes |
| 59 | +# csv_path = Path(RECSYNCH_SESSION_DIR) / csv_file |
| 60 | +# df = pd.read_csv(csv_path) |
38 | 61 |
|
39 |
| - clients = client_IDs() |
40 |
| - for c in clients: |
41 |
| - client_dir = Path(RECSYNCH_SESSION_DIR) / c |
42 |
| - for csv_file in client_dir.glob("*.csv"): |
43 |
| - print("==>", csv_file) |
44 |
| - rel_filepath = str(csv_file.relative_to(RECSYNCH_SESSION_DIR)) |
45 |
| - print("++>", rel_filepath) |
46 |
| - out.append(rel_filepath) |
| 62 | +# assert len(df) >= 2 |
47 | 63 |
|
48 |
| - return out |
| 64 | +# repaired_df = repair_dropped_frames(df) |
49 | 65 |
|
| 66 | +# assert len(repaired_df) >= len(df) |
50 | 67 |
|
51 |
| -@pytest.mark.parametrize("csv_file", CSVs()) |
52 |
| -def test_df_reparation(csv_file): |
53 | 68 |
|
54 |
| - # Load the test dataframes |
55 |
| - csv_path = Path(RECSYNCH_SESSION_DIR) / csv_file |
56 |
| - df = pd.read_csv(csv_path) |
| 69 | +def test_df_trim(): |
| 70 | + # Create three sample dataframes with single column and no headers |
| 71 | + df1 = pd.DataFrame([9, 10, 11, 16]) |
| 72 | + df2 = pd.DataFrame([7, 8, 12, 13]) |
| 73 | + df3 = pd.DataFrame([12, 15, 16, 19]) |
57 | 74 |
|
58 |
| - assert len(df) >= 2 |
| 75 | + # Add the dataframes to a list |
| 76 | + df_list = [df1, df2, df3] |
59 | 77 |
|
60 |
| - repaired_df = repair_dropped_frames(df) |
| 78 | + # Compute time range and trim the dataframe |
| 79 | + min_val, max_val = compute_time_range(df_list) |
| 80 | + trimmed_df_list = trim_into_interval(df_list, min_val, max_val, 3) |
61 | 81 |
|
62 |
| - assert len(repaired_df) >= len(df) |
| 82 | + # Create expected list of dataframes to compare with trimmed_df_list |
| 83 | + compare_list = [ |
| 84 | + pd.DataFrame([9, 10, 11, 16]), |
| 85 | + pd.DataFrame([12, 13]), |
| 86 | + pd.DataFrame([12, 15, 16]) |
| 87 | + ] |
| 88 | + |
| 89 | + # print(trimmed_df_list.to_string(index=False)) |
| 90 | + # print(compare_list.to_string(index=False)) |
| 91 | + # try: |
| 92 | + # for df1, df2 in zip(trimmed_df_list, compare_list): |
| 93 | + # df1_reset = df1.reset_index(drop=True) |
| 94 | + # df2_reset = df2.reset_index(drop=True) |
| 95 | + # pd_testing.assert_frame_equal(df1_reset, df2_reset) |
| 96 | + # print("All dataframes match") |
| 97 | + # except AssertionError as e: |
| 98 | + # print("Dataframes do not match:") |
| 99 | + # print(e) |
| 100 | + # Assert if all dataframes in df_list match the corresponding dataframes in compare_list |
| 101 | + assert trimmed_df_list == compare_list |
0 commit comments