Skip to content

Commit

Permalink
Rewrite data processing to retain Time column
Browse files Browse the repository at this point in the history
This is needed for the gap calculation
  • Loading branch information
Casper-Guo committed Aug 3, 2024
1 parent 16fa621 commit 9fcf133
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 7 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ def df_convert_timedelta(df: pd.DataFrame) -> pd.DataFrame:
The pd.Timedelta type is not JSON serializable.
Columns with this data type need to be dropped or converted.
"""
# The Time column is dropped directly since its information is retained by LapTime
df = df.drop(columns=["Time"])
# PitOUtTime and PitInTime contains information that we might need later
df[["PitInTime", "PitOutTime"]] = df[["PitInTime", "PitOutTime"]].fillna(
pd.Timedelta(0, unit="ms")
)
df["PitInTime"] = df["PitInTime"].dt.total_seconds()
df["PitOutTime"] = df["PitOutTime"].dt.total_seconds()
timedelta_columns = ["Time", "PitInTime", "PitOutTime"]
# usually the Time column has no NaT values
# it is included here for consistency
df[timedelta_columns] = df[timedelta_columns].fillna(pd.Timedelta(0, unit="ms"))

for column in timedelta_columns:
df[column] = df[column].dt.total_seconds()
return df


Expand Down
5 changes: 4 additions & 1 deletion f1_visualization/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ def add_lap_rep_deltas(df_laps: pd.DataFrame) -> pd.DataFrame:
(df_laps["LapTime"] - df_laps["LapTime_Rep"]) / df_laps["LapTime_Rep"] * 100
).round(decimals=3)

return df_laps.drop(columns=["LapTime_Rep"])
# all data engineering functions fully modify the dataframe in addition to returning them
# this is so this function can be called similarly to others in transform
df_laps = df_laps.drop(columns=["LapTime_Rep"])
return df_laps # noqa: RET504


def find_diff(season: int, dfs: dict[str, pd.DataFrame], session_type: str) -> pd.DataFrame:
Expand Down

0 comments on commit 9fcf133

Please sign in to comment.