|
| 1 | +""" |
| 2 | +Prettify the execution information of the graph. |
| 3 | +""" |
| 4 | + |
| 5 | +import pandas as pd |
| 6 | + |
| 7 | + |
| 8 | +def prettify_exec_info(complete_result: dict) -> pd.DataFrame: |
| 9 | + """ |
| 10 | + Transform the execution information of the graph into a DataFrame for better visualization. |
| 11 | +
|
| 12 | + Args: |
| 13 | + - complete_result (dict): The complete execution information of the graph. |
| 14 | +
|
| 15 | + Returns: |
| 16 | + - pd.DataFrame: The execution information of the graph in a DataFrame. |
| 17 | + """ |
| 18 | + |
| 19 | + nodes_info = complete_result['nodes_info'] |
| 20 | + total_info = { |
| 21 | + 'total_exec_time': complete_result['total_exec_time'], |
| 22 | + 'total_model_info': complete_result['total_model_info'] |
| 23 | + } |
| 24 | + |
| 25 | + # Convert node-specific information to DataFrame |
| 26 | + flat_data = [] |
| 27 | + for node_name, node_info in nodes_info.items(): |
| 28 | + flat_data.append({ |
| 29 | + 'Node': node_name, |
| 30 | + 'Execution Time': node_info['exec_time'], |
| 31 | + # Unpack the model_info dict into the row |
| 32 | + **node_info['model_info'] |
| 33 | + }) |
| 34 | + |
| 35 | + df_nodes = pd.DataFrame(flat_data) |
| 36 | + |
| 37 | + # Add a row for the total execution time and total model info |
| 38 | + total_row = { |
| 39 | + 'Node': 'Total', |
| 40 | + 'Execution Time': total_info['total_exec_time'], |
| 41 | + # Unpack the total_model_info dict into the row |
| 42 | + **total_info['total_model_info'] |
| 43 | + } |
| 44 | + df_total = pd.DataFrame([total_row]) |
| 45 | + |
| 46 | + # Combine the nodes DataFrame with the total info DataFrame |
| 47 | + df_combined_with_total = pd.concat([df_nodes, df_total], ignore_index=True) |
| 48 | + return df_combined_with_total |
0 commit comments