Skip to content

Commit 5d588eb

Browse files
committed
More comments.
1 parent 74f8e05 commit 5d588eb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

PostProcessing/dataframes.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,50 @@ def compute_time_step(video_timestamps: pd.DataFrame) -> float:
1818
"""
1919

2020
first_col_name = video_timestamps.columns[0]
21+
# Retrieves the most frequent time different between consecutive lines.
2122
time_step = (video_timestamps[first_col_name].diff()).dropna().value_counts().index[0]
2223

2324
return time_step
2425

2526

26-
def repair_dropped_frames(df: pd.DataFrame, time_step: float) -> pd.DataFrame:
27-
27+
def repair_dropped_frames(df: pd.DataFrame, time_step: float) -> pd.DataFrame:
28+
# The name of the first column (can be anythign as the original df doesn't have header
2829
first_col_name = df.columns[0]
2930

31+
# Forces the type of the timestamps to int64
3032
df[first_col_name] = pd.to_datetime(df[first_col_name]).astype(np.int64)
33+
# Retrieves the timestamps into a Serie
3134
timestamps = df[first_col_name]
35+
# Will accumulate the repaired rows
3236
repaired_rows = []
3337

3438
# Check for missing timestamps and generate them
3539
for i in range(len(timestamps) - 1):
3640
timestamp = timestamps.iloc[i]
3741
next_timestamp = timestamps.iloc[i + 1]
3842

43+
# The current timestamp is by definition original
3944
repaired_rows.append([timestamp, 'Original'])
4045

46+
# If the next timestamp exceeds the expected time step
4147
if next_timestamp - timestamp > time_step:
42-
missing_timestamps_count = int((next_timestamp - timestamp)/ time_step) - 1
48+
# Estimate the number of missing frames
49+
missing_timestamps_count = int((next_timestamp - timestamp) / time_step) - 1
50+
# Estimate a time interval between them (will be very similar to the input time_step
4351
interval = (next_timestamp - timestamp) / (missing_timestamps_count + 1)
44-
52+
# Generate the missing lines
4553
for j in range(1, missing_timestamps_count + 1):
4654
new_timestamp = (timestamp + j * interval).astype(np.int64)
4755
repaired_rows.append([new_timestamp, 'Generated'])
4856

4957
# Add the last row
5058
repaired_rows.append([timestamps.iloc[-1], 'Original'])
59+
# print(len(repaired_rows))
5160

52-
print(len(repaired_rows))
5361
# Create a new DataFrame with repaired rows
5462
columns = ['timestamp', 'generated']
5563
output_df = pd.DataFrame(repaired_rows, columns=columns)
64+
# Forces the output timestamp type to int 64
5665
output_df['timestamp'] = pd.to_datetime(output_df['timestamp']).astype(np.int64)
5766

5867
return output_df

0 commit comments

Comments
 (0)