Skip to content

Commit

Permalink
[ET] Add csv_path to inspector_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgep31415 committed Nov 22, 2024
1 parent fc42a4e commit fce5c49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions devtools/inspector/_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,33 @@ def print_data_tabular(

display_or_print_df(filtered_column_df, file)


def save_data_to_csv(
self,
file: IO[str],
) -> None:
"""
Stores the underlying EventBlocks in a csv format with tab separator, to facilitate copy-paste into spreadsheets.
Args:
file: Which IO stream to print to. Do not use stdout, as tab separator is not preserved.
Returns:
None
"""
combined_df = self.to_dataframe()

# Filter out some columns and rows for better readability when printing
filtered_column_df = combined_df.drop(columns=EXCLUDED_COLUMNS_WHEN_PRINTING)
for filter_name in EXCLUDED_EVENTS_WHEN_PRINTING:
filtered_column_df = filtered_column_df[
~filtered_column_df["event_name"].str.contains(filter_name)
]
filtered_column_df.reset_index(drop=True, inplace=True)

filtered_column_df.to_csv(file, sep="\t")


# TODO: write unit test
def find_total_for_module(self, module_name: str) -> float:
"""
Expand Down
7 changes: 7 additions & 0 deletions devtools/inspector/inspector_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def main() -> None:
required=False,
help="Provide an optional buffer file path.",
)
parser.add_argument(
"--csv_path",
required=False,
help="Provide an optional csv file path.",
)
parser.add_argument("--compare_results", action="store_true")

args = parser.parse_args()
Expand All @@ -55,6 +60,8 @@ def main() -> None:
target_time_scale=TimeScale(args.target_time_scale),
)
inspector.print_data_tabular()
if args.csv_path:
inspector.save_data_to_csv(args.csv_path)
if args.compare_results:
for event_block in inspector.event_blocks:
if event_block.name == "Execute":
Expand Down

0 comments on commit fce5c49

Please sign in to comment.