|
2 | 2 |
|
3 | 3 | import os
|
4 | 4 | from pathlib import Path
|
5 |
| - |
6 | 5 | from typing import List, Tuple
|
7 | 6 |
|
8 |
| - |
9 |
| -from dataframes import repair_dropped_frames, compute_time_range, trim_into_interval |
10 |
| -from PostProcessVideos import scan_session_dir |
11 |
| - |
12 |
| - |
13 | 7 | import pandas as pd
|
14 | 8 |
|
15 |
| -import pandas.testing as pd_testing |
| 9 | +from dataframes import compute_time_step |
| 10 | +from dataframes import repair_dropped_frames, compute_time_range |
| 11 | + |
| 12 | +from PostProcessVideos import scan_session_dir |
16 | 13 |
|
17 |
| -import numpy as np |
18 | 14 |
|
19 | 15 | RECSYNCH_SESSION_DIR_VAR = "RECSYNCH_SESSION_DIR"
|
20 | 16 |
|
@@ -56,61 +52,35 @@ def session_data_list() -> List[Tuple[str, pd.DataFrame, str]]:
|
56 | 52 | clienIDs, dataframes, video_paths = scan_session_dir(Path(RECSYNCH_SESSION_DIR))
|
57 | 53 |
|
58 | 54 | for clientID, df, video_path in zip(clienIDs, dataframes, video_paths):
|
59 |
| - yield (clientID, df, video_path) |
60 |
| - |
61 |
| - |
62 |
| -def client_IDs() -> List[Path]: |
63 |
| - |
64 |
| - out = [] |
65 |
| - |
66 |
| - for p in Path(RECSYNCH_SESSION_DIR).iterdir(): |
67 |
| - print("-->", p.stem) |
68 |
| - out.append(p) |
69 |
| - |
70 |
| - return out |
71 |
| - |
| 55 | + yield clientID, df, video_path |
72 | 56 |
|
73 |
| -def CSVs() -> List[str]: |
74 | 57 |
|
75 |
| - out = [] |
76 |
| - |
77 |
| - clients = client_IDs() |
78 |
| - for c in clients: |
79 |
| - client_dir = Path(RECSYNCH_SESSION_DIR) / c |
80 |
| - for csv_file in client_dir.glob("*.csv"): |
81 |
| - print("==>", csv_file) |
82 |
| - rel_filepath = str(csv_file.relative_to(RECSYNCH_SESSION_DIR)) |
83 |
| - print("++>", rel_filepath) |
84 |
| - out.append(rel_filepath) |
85 |
| - |
86 |
| - return out |
87 |
| - |
88 |
| - |
89 |
| -@pytest.mark.parametrize("csv_file", CSVs()) |
90 |
| -def test_df_reparation(csv_file): |
91 |
| - |
92 |
| - # Load the test dataframes |
93 |
| - csv_path = Path(RECSYNCH_SESSION_DIR) / csv_file |
94 |
| - df = pd.read_csv(csv_path) |
| 58 | +@pytest.mark.parametrize("client_data", session_data_list()) |
| 59 | +def test_df_reparation(client_data): |
95 | 60 |
|
| 61 | + _, df, _ = client_data |
96 | 62 | assert len(df) >= 2
|
97 | 63 |
|
98 |
| - repaired_df = repair_dropped_frames(df) |
| 64 | + first_col_name = df.columns[0] |
99 | 65 |
|
100 |
| - assert len(repaired_df) >= len(df) |
| 66 | + time_step = compute_time_step(df) |
| 67 | + assert time_step > 0 |
101 | 68 |
|
102 |
| -@pytest.mark.parametrize("client_data", session_data_list()) |
103 |
| -def test_df_reparation(client_data): |
| 69 | + repaired_df = repair_dropped_frames(df, time_step) |
104 | 70 |
|
105 |
| - _, df, _ = client_data |
| 71 | + assert len(repaired_df) > 2 |
106 | 72 |
|
107 |
| - assert len(df) >= 2 |
| 73 | + assert len(repaired_df) >= len(df), "Dataframe size was reduced after reparation." |
108 | 74 |
|
109 |
| - repaired_df = repair_dropped_frames(df) |
| 75 | + repaired_first_col_name = repaired_df.columns[0] |
| 76 | + repaired_second_col_name = repaired_df.columns[1] |
| 77 | + assert repaired_first_col_name == "timestamp" |
| 78 | + assert repaired_second_col_name == "generated" |
110 | 79 |
|
111 |
| - assert len(repaired_df) >= len(df) |
112 |
| - assert df[0].iloc[0] == repaired_df[0].iloc[0] |
113 |
| - assert df[0].iloc[-1] == repaired_df[0].iloc[-1] |
| 80 | + assert df[first_col_name].iloc[0] == repaired_df[repaired_first_col_name].iloc[0],\ |
| 81 | + "The first element changed after reparation" |
| 82 | + assert df[first_col_name].iloc[-1] == repaired_df[repaired_first_col_name].iloc[-1],\ |
| 83 | + "The last element changed after reparation" |
114 | 84 |
|
115 | 85 |
|
116 | 86 | def test_df_trimming(session_data):
|
|
0 commit comments