2from dash
import dcc, html
3from dash.dependencies
import Input, Output, State
4import plotly.express
as px
12 os.path.abspath(os.path.join(os.path.dirname(__file__),
"..",
"cloud_storage"))
14from bucket_operations
import list_blobs, download_csv_from_bucket_to_folder
17app = dash.Dash(__name__)
18app.config.suppress_callback_exceptions =
True
21csv_files = list_blobs(
"as_evaluation")
24available_dashboards = [
25 "Evaluator_perception",
26 "Evaluator_state_estimation",
29 "Perception_exec_time",
30 "State_estimation_exec_time",
32 "Planning_cone_coloring",
40 dcc.Store(id=
"stored-csv-data", storage_type=
"memory"),
41 html.H1(
"Select Dashboard"),
43 id=
"dashboard-dropdown",
45 {
"label": dashboard,
"value": dashboard}
46 for dashboard
in available_dashboards
49 placeholder=
"Select a dashboard",
51 html.Div(id=
"dashboard-content"),
58 dashboard_conditions = {
59 "Evaluator_perception":
"evaluator/perception",
60 "Evaluator_state_estimation":
"evaluator/se",
61 "Evaluator_planning":
"evaluator/planning",
62 "Evaluator_control":
"evaluator/control",
63 "Perception_exec_time":
"perception/perception/",
64 "State_estimation_exec_time":
"state_est",
65 "Planning_exec_time":
"planning_exec_time",
66 "Planning_cone_coloring":
"planning_cone_coloring",
67 "Power_log":
"power_log",
71 condition = dashboard_conditions.get(dashboard,
"")
74 csv_files = [file
for file
in list_blobs(
"as_evaluation")
if condition
in file]
78 html.H2(f
"{dashboard} CSV files"),
80 id=f
"csv-dropdown-{dashboard}",
81 options=[{
"label": f,
"value": f}
for f
in csv_files],
84 placeholder=
"Select CSV files",
89 id=f
"graph1-{dashboard}",
90 style={
"width":
"70%",
"height":
"500px"},
96 id=f
"graph1-{dashboard}-metrics-dropdown",
98 style={
"minWidth":
"200px"},
101 html.Label(
"X-Axis"),
103 id=f
"x-axis-dropdown-{dashboard}-1",
104 style={
"minWidth":
"200px"},
107 id=f
"graph1-metrics-{dashboard}",
108 style={
"minWidth":
"200px",
"width":
"25%"},
111 style={
"display":
"flex"},
116 id=f
"graph2-{dashboard}",
117 style={
"width":
"70%",
"height":
"500px"},
121 html.Label(
"Y-Axis"),
123 id=f
"graph2-{dashboard}-metrics-dropdown",
125 style={
"minWidth":
"200px"},
128 html.Label(
"X-Axis"),
130 id=f
"x-axis-dropdown-{dashboard}-2",
131 style={
"minWidth":
"200px"},
134 id=f
"graph2-metrics-{dashboard}",
135 style={
"minWidth":
"200px",
"width":
"25%"},
138 style={
"display":
"flex"},
143 id=f
"graph3-{dashboard}",
144 style={
"width":
"70%",
"height":
"500px"},
148 html.Label(
"Y-Axis"),
150 id=f
"graph3-{dashboard}-metrics-dropdown",
152 style={
"minWidth":
"200px"},
155 html.Label(
"X-Axis"),
157 id=f
"x-axis-dropdown-{dashboard}-3",
158 style={
"minWidth":
"200px"},
161 id=f
"graph3-metrics-{dashboard}",
162 style={
"minWidth":
"200px",
"width":
"25%"},
165 style={
"display":
"flex"},
170 id=f
"graph4-{dashboard}",
171 style={
"width":
"70%",
"height":
"500px"},
175 html.Label(
"Y-Axis"),
177 id=f
"graph4-{dashboard}-metrics-dropdown",
179 style={
"minWidth":
"200px"},
182 html.Label(
"X-Axis"),
184 id=f
"x-axis-dropdown-{dashboard}-3",
185 style={
"minWidth":
"200px"},
188 id=f
"graph4-metrics-{dashboard}",
189 style={
"minWidth":
"200px",
"width":
"25%"},
192 style={
"display":
"flex"},
197 id=f
"graph5-{dashboard}",
198 style={
"width":
"70%",
"height":
"500px"},
202 html.Label(
"Y-Axis"),
204 id=f
"graph5-{dashboard}-metrics-dropdown",
206 style={
"minWidth":
"200px"},
209 html.Label(
"X-Axis"),
211 id=f
"x-axis-dropdown-{dashboard}-3",
212 style={
"minWidth":
"200px"},
215 id=f
"graph5-metrics-{dashboard}",
216 style={
"minWidth":
"200px",
"width":
"25%"},
219 style={
"display":
"flex"},
227 Output(
"dashboard-content",
"children"), Input(
"dashboard-dropdown",
"value")
231 Update the layout based on the selected dashboard.
234 selected_dashboard: The selected dashboard.
236 if selected_dashboard:
243 Download and combine the selected CSV files.
246 selected_csvs: The selected CSV files.
247 temp_folder: The temporary folder to store the CSV files.
249 combined_df = pd.DataFrame()
250 for csv
in selected_csvs:
251 download_csv_from_bucket_to_folder(
"as_evaluation", csv, temp_folder, csv)
252 temp_df = pd.read_csv(os.path.join(temp_folder, csv))
253 temp_df[
"Source"] = csv
254 combined_df = pd.concat([combined_df, temp_df], ignore_index=
True)
261 Output(f
"graph{graph_number}-{dashboard}-metrics-dropdown",
"options"),
262 Output(f
"x-axis-dropdown-{dashboard}-{graph_number}",
"options"),
265 Input(f
"csv-dropdown-{dashboard}",
"value"),
266 Input(f
"stored-csv-data",
"data"),
268 State(f
"csv-dropdown-{dashboard}",
"value"),
270 def update_metric_dropdowns(selected_csvs, stored_data, current_selected_csvs):
272 Update the metric dropdowns based on the selected CSV files.
275 selected_csvs: The selected CSV files.
276 stored_data: The stored CSV data.
277 current_selected_csvs: The currently selected CSV files.
279 if not selected_csvs:
282 temp_folder =
"src/cloud_storage/temp"
283 if stored_data
is None or set(current_selected_csvs) != set(selected_csvs):
286 combined_df = pd.read_json(stored_data, orient=
"split")
288 columns = list(combined_df.columns)
289 options = [{
"label": col,
"value": col}
for col
in columns]
291 return options, options
296 Output(graph_id,
"figure"),
298 Input(f
"csv-dropdown-{dashboard}",
"value"),
299 Input(f
"graph{graph_number}-{dashboard}-metrics-dropdown",
"value"),
300 Input(f
"x-axis-dropdown-{dashboard}-{graph_number}",
"value"),
301 Input(f
"stored-csv-data",
"data"),
303 State(f
"csv-dropdown-{dashboard}",
"value"),
306 selected_csvs, metrics, x_axis, stored_data, current_selected_csvs
309 Update the graph based on the selected CSV files and metrics.
311 selected_csvs: The selected CSV files.
312 metrics: The selected metrics.
313 x_axis: The selected x-axis.
314 stored_data: The stored CSV data.
315 current_selected_csvs: The currently selected CSV files.
317 if not selected_csvs
or not metrics:
320 temp_folder =
"src/cloud_storage/temp"
321 if stored_data
is None or set(current_selected_csvs) != set(selected_csvs):
324 combined_df = pd.read_json(stored_data, orient=
"split")
326 if x_axis
not in combined_df.columns:
328 if "time" not in combined_df.columns:
329 combined_df[
"time"] = range(len(combined_df))
331 df_melted = combined_df.melt(id_vars=[x_axis,
"Source"], value_vars=metrics)
332 df_melted[
"Source_Metric"] = df_melted[
"Source"] +
" - " + df_melted[
"variable"]
333 df_melted = df_melted[df_melted[
"variable"].isin(metrics)]
335 if graph_type ==
"line":
340 color=
"Source_Metric",
341 labels={
"value":
"Metrics", x_axis: x_axis},
344 elif graph_type ==
"scatter":
349 color=
"Source_Metric",
350 labels={
"value":
"Metrics", x_axis: x_axis},
351 title=
"Scatter Plot",
353 elif graph_type ==
"bar":
358 color=
"Source_Metric",
360 labels={
"value":
"Metrics", x_axis: x_axis},
363 elif graph_type ==
"heatmap":
365 df_melted.pivot_table(index=x_axis, columns=
"variable", values=
"value"),
366 labels={
"value":
"Metric Value", x_axis: x_axis},
373for dashboard
in available_dashboards:
388 temp_folder =
"src/cloud_storage/temp"
389 if os.path.exists(temp_folder):
390 shutil.rmtree(temp_folder)
393atexit.register(cleanup_temp_folder)
396if __name__ ==
"__main__":
397 app.run_server(debug=
True)
update_dashboard(selected_dashboard)
Update the layout based on the selected dashboard.
create_update_metric_dropdowns_callback(dashboard, graph_number)
download_and_combine_csvs(selected_csvs, temp_folder)
Download and combine the selected CSV files.
get_dashboard_layout(dashboard)
create_update_graph_callback(graph_id, dashboard, graph_number, graph_type="line")