Skip to content

Commit 5466863

Browse files
committed
Clean ups and more tests. Reparation fails: leave holes. Trimming fails: doesn't work on repaired frames with headers.
1 parent 042f4b8 commit 5466863

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

PostProcessing/PostProcessVideos.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import pandas as pd
66
import re
77

8-
from dataframes import compute_time_range, trim_into_interval, repair_dropped_frames
8+
from dataframes import compute_time_range, trim_into_interval
9+
from dataframes import repair_dropped_frames, compute_time_step
10+
11+
from video import extract_frames
912

1013

1114
THRESHOLD_NS = 10 * 1000 * 1000
@@ -56,6 +59,7 @@ def scan_session_dir(input_dir: Path) -> Tuple[List[str], List[pd.DataFrame], Li
5659

5760
return clientIDs, df_list, mp4_list
5861

62+
5963
#
6064
#
6165
#
@@ -76,10 +80,11 @@ def main(input_dir: Path, output_dir: Path):
7680
print(f"For client ID {cID}: {len(df)} frames for file {mp4}")
7781

7882
#
79-
# Repair CSVs (TODO - Mina)
83+
# Repair CSVs
8084
repaired_df_list: List[pd.DataFrame] = []
8185
for cID, df in zip(clientIDs, df_list):
82-
repaired_df = repair_dropped_frames(df)
86+
time_step = compute_time_step(df)
87+
repaired_df = repair_dropped_frames(df=df, time_step=time_step)
8388
repaired_df_list.append(repaired_df)
8489

8590
assert len(clientIDs) == len(df_list) == len(mp4_list) == len(repaired_df_list)
@@ -90,7 +95,7 @@ def main(input_dir: Path, output_dir: Path):
9095
min_common, max_common = compute_time_range(repaired_df_list)
9196

9297
#
93-
# Trim CSVs (TODO)
98+
# Trim CSVs
9499
# Trim the data frames to the time range
95100
trimmed_dataframes = trim_into_interval(repaired_df_list, min_common, max_common, THRESHOLD_NS)
96101

@@ -109,7 +114,7 @@ def main(input_dir: Path, output_dir: Path):
109114
#
110115
# Extract the frames from the original videos
111116
# and rename the file names to the timestamps (DONE)
112-
# extract(input_dir, output_dir)
117+
# extract_frames(input_dir, output_dir)
113118

114119
#
115120
# Reconstruct videos (TODO)

PostProcessing/dataframes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def repair_dropped_frames(df: pd.DataFrame, time_step: float) -> pd.DataFrame:
3030

3131
# Forces the type of the timestamps to int64
3232
df[first_col_name] = pd.to_datetime(df[first_col_name]).astype(np.int64)
33-
# Retrieves the timestamps into a Serie
33+
# Retrieves the timestamps into a Series
3434
timestamps = df[first_col_name]
3535
# Will accumulate the repaired rows
3636
repaired_rows = []
@@ -114,11 +114,12 @@ def trim_into_interval(dfs, min_common, max_common, threshold):
114114
for df in dfs:
115115
start: pd.DataFrame = df[df.iloc[:, 0].between(min_common-threshold, min_common+threshold, inclusive='both')]
116116
end: pd.DataFrame = df[df.iloc[:, 0].between(max_common-threshold, max_common+threshold, inclusive='both')]
117-
if not start.empty and not end.empty :
117+
if not start.empty and not end.empty:
118118
df_start = start.stack().iloc[0]
119119
df_end = end.stack().iloc[-1]
120120
trimmed_df = df[df.iloc[:, 0].between(df_start, df_end, inclusive='both')]
121121
trimmed_dataframes.append(trimmed_df)
122122
else:
123-
print("No values found within the specified range.")
123+
raise Exception("No values found within the specified range.")
124+
124125
return trimmed_dataframes

PostProcessing/test_functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def test_df_reparation(client_data):
8484
assert df[first_col_name].iloc[-1] == repaired_df[repaired_first_col_name].iloc[-1],\
8585
"The last element changed after reparation"
8686

87+
tstamps = repaired_df["timestamp"]
88+
diffs = tstamps.diff().dropna()
89+
assert (diffs <= time_step).all(), "some timestamps difference is longer than expected"
90+
91+
pass
92+
8793

8894
def test_df_trimming(session_data):
8995
_, dataframes, _ = session_data

0 commit comments

Comments
 (0)