Changing layout with sliders for sim parameters
Browse files84 unmodified lines8586878889909192931 unmodified line95969798991001011021031041051061071081091101111121131147 unmodified lines12212312412512612712812913013113226 unmodified lines15916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319414 unmodified lines2092102112122132142152 unmodified lines2182192202212222232242252264 unmodified lines23123223323423523623723845 unmodified lines28428528628784 unmodified lineshtml.Div([html.Div([html.Div("Select the desired input conditions, then click 'Simulate!':", id='text1'),html.Label("Contingency Time: "),dcc.Input( id='cont-time', type='text', placeholder='Time at which the lost link event occurs (set to "ALONGTIMEAWAY" (no quotes) if no lost link event needs to occur)', style={'width': '80%'}),html.Br(),html.Label("backgroundDivert: "),dcc.RadioItems(id='backgroundDivert',1 unmodified line{'label': 'Divert', 'value': 'True'},{'label': 'Continue', 'value': 'False'}],value=True,labelStyle={'display': 'inline-block'}),html.Br(),html.Label("IFthreshold: "),dcc.Input( id='IFthreshold', type='text', placeholder='A `double` which represents the interaction factor at which Blaze will make a decision.', style={'width': '80%'}),html.Br(),html.Label("TAthreshold: "),dcc.Input( id='TAthreshold', type='text', placeholder='An `integer` which represents how much time needs to be left before Blaze makes a decision.', style={'width': '80%'}),html.Br(),html.Label("updateTime: "),dcc.Input( id='updateTime', type='text', placeholder='An `integer` which represents the frequency at which the `DecisionAction` `Responding` is updated.', style={'width': '80%'}),html.Br(),html.Button('Simulate!', id='button', n_clicks=0),], style={'width': '50%', 'border': '1px solid gray'}),html.Div([7 unmodified lines),html.Button('Submit', id='submit-button', n_clicks=0),# Create a dropdown menu with the subfolders as optionshtml.Div("Once all subfolders are loaded (representing the different conditions you ran in WMC), you can select which one to plot:", id='text2'),dcc.Dropdown(id='subfolder-dropdown',value=None #subfolders[0] # Default value)], style={'width': '50%', 'border': '1px solid gray'}),], style={'display': 'flex'}),26 unmodified lines])@app.callback(dash.dependencies.Output('button', 'n_clicks'), # Add this output to reset button clicks[dash.dependencies.Input('cont-time', 'value')],[dash.dependencies.Input('backgroundDivert', 'value')],[dash.dependencies.Input('IFthreshold', 'value')],[dash.dependencies.Input('TAthreshold', 'value')],[dash.dependencies.Input('updateTime', 'value')],[dash.dependencies.Input('button', 'n_clicks')],)def run_wmc(selected_time, backgroundDivert, IFthreshold, TAthreshold, update_time, nc_clicks):if nc_clicks > 0:# try:print("Running WMC with input arguments",selected_time,"...")process = subprocess.Popen(['wmc/WNUAM', 'Example', selected_time, backgroundDivert, IFthreshold, TAthreshold, update_time]) # return f"WMC was run!"# process = subprocess.Popen(['./UAM', 'Example', '240', 'True']) # return f"WMC was run!"try:process.wait(timeout=50) # Wait for the process to completeexcept subprocess.TimeoutExpired:process.terminate() # Terminate the process after timeout# Continue with the rest of the codeprint("Completed running WMC...")return 0# except:# return f"error!"# Load data when the app starts and store it in the hidden div@app.callback(dash.dependencies.Output('subfolder-dropdown', 'options'),dash.dependencies.Output('variable-dropdown', 'options'),dash.dependencies.Output('submit-button', 'n_clicks'), # Add this output to reset submit button clicks[dash.dependencies.Input('submit-button', 'n_clicks')],[dash.dependencies.Input('path-input', 'value')],14 unmodified lineslabels = list(data[list(data.keys())[0]]['aircraft_data'][list(data[list(data.keys())[0]]['aircraft_data'].keys())[0]].columns.tolist()) # Extracting column names for the first aircraft-specific dataframereturn subfolder_labels, labels, 0else:return [], [], 0# Define the callback to update the graphs based on the slider value@app.callback(2 unmodified linesdash.dependencies.Output('altitude-series', 'figure'),# dash.dependencies.Output('timeline', 'figure'),# dash.dependencies.Input('path-input', 'value'),[dash.dependencies.Input('subfolder-dropdown', 'value'),dash.dependencies.Input('time-slider', 'value'),dash.dependencies.Input('variable-dropdown','value')])# def update_graph(selected_subfolder, selected_time):# # Load the CSV files into pandas DataFrames from the selected subfolder4 unmodified lines# exclude = ['Detect_crash','Detect_conflict','Flight_Dynamics','Reroute_flight','Show_radar','Direct_to_waypoint','Change_heading']# events = parse_action_trace(f'data/{selected_subfolder}/actionTrace.csv', exclude)def update_graph(selected_subfolder, selected_time, selected_variable):if selected_subfolder not in data_store:return go.Figure(), go.Figure(), go.Figure(layout=dict(autosize=True, width=None, height=300))#, go.Figure()45 unmodified lines# webbrowser.open_new("http://127.0.0.1:8050/")# app.run_server(debug=True)app.run_server(debug=False, host='0.0.0.0', port=7860)84 unmodified lines8586878889909192931 unmodified line95969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421437 unmodified lines15115215315415515615715815916016126 unmodified lines18818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222314 unmodified lines2382392402412422432442452462 unmodified lines2492502512522532542552562572582592602614 unmodified lines26626726826927027127227327427545 unmodified lines32132232332484 unmodified lineshtml.Div([html.Div([html.Div("Select the desired input conditions, then click 'Simulate!':", id='text1'),# html.Label("Contingency Time: "),# dcc.Input( id='cont-time', type='text', placeholder='Time at which the lost link event occurs (set to "ALONGTIMEAWAY" (no quotes) if no lost link event needs to occur)', style={'width': '80%'}),# html.Br(),html.Label("backgroundDivert: "),dcc.RadioItems(id='backgroundDivert',1 unmodified line{'label': 'Divert', 'value': 'True'},{'label': 'Continue', 'value': 'False'}],value='True',labelStyle={'display': 'inline-block'}),html.Br(),html.Label("Required certainty: A value that represents how high certainty needs to be before Blaze will make a decision."),html.Br(),dcc.Slider(id='IFthreshold',min=65,max=85,value=75,marks={str(time): str(time) for time in range(65, 85+1, 10)},step=None, # Add this line to make the slider stick to the marksupdatemode='drag'),# style={'width': '100%'}, # Set the width of the div containing the slider to 80% of the container# dcc.Input( id='IFthreshold', type='text', placeholder='A `double` which represents the interaction factor at which Blaze will make a decision.', style={'width': '80%'}),# html.Br(),html.Label("Time buffer: The time left before a decision must be made."),dcc.Slider(id='TAthreshold',min=10,max=40,value=20,marks={str(time): str(time) for time in range(10, 40+1, 10)},step=None, # Add this line to make the slider stick to the marksupdatemode='drag'),# dcc.Input( id='TAthreshold', type='text', placeholder='An `integer` which represents how much time needs to be left before Blaze makes a decision.', style={'width': '80%'}),# html.Br(),html.Label("Wait interval: How long to wait before the next update is made."),dcc.Slider(id='updateTime',min=20,max=40,value=30,marks={str(time): str(time) for time in range(20, 40+1, 10)},step=None, # Add this line to make the slider stick to the marksupdatemode='drag'),# dcc.Input( id='updateTime', type='text', placeholder='An `integer` which represents the frequency at which the `DecisionAction` `Responding` is updated.', style={'width': '80%'}),# html.Br(),# html.Button('Simulate!', id='button', n_clicks=0),], style={'width': '50%', 'border': '1px solid gray'}),html.Div([7 unmodified lines),html.Button('Submit', id='submit-button', n_clicks=0),# Create a dropdown menu with the subfolders as options# html.Div("Once all subfolders are loaded (representing the different conditions you ran in WMC), you can select which one to plot:", id='text2'),# dcc.Dropdown(# id='subfolder-dropdown',# value=None #subfolders[0] # Default value# )], style={'width': '50%', 'border': '1px solid gray'}),], style={'display': 'flex'}),26 unmodified lines])# @app.callback(# dash.dependencies.Output('button', 'n_clicks'), # Add this output to reset button clicks# [dash.dependencies.Input('cont-time', 'value')],# [dash.dependencies.Input('backgroundDivert', 'value')],# [dash.dependencies.Input('IFthreshold', 'value')],# [dash.dependencies.Input('TAthreshold', 'value')],# [dash.dependencies.Input('updateTime', 'value')],# [dash.dependencies.Input('button', 'n_clicks')],# )# def run_wmc(selected_time, backgroundDivert, IFthreshold, TAthreshold, update_time, nc_clicks):# if nc_clicks > 0:# # try:# print("Running WMC with input arguments",selected_time,"...")# process = subprocess.Popen(['wmc/WNUAM', 'Example', selected_time, backgroundDivert, IFthreshold, TAthreshold, update_time]) # return f"WMC was run!"# # process = subprocess.Popen(['./UAM', 'Example', '240', 'True']) # return f"WMC was run!"# try:# process.wait(timeout=50) # Wait for the process to complete# except subprocess.TimeoutExpired:# process.terminate() # Terminate the process after timeout# # Continue with the rest of the code# print("Completed running WMC...")# return 0# except:# return f"error!"# Load data when the app starts and store it in the hidden div@app.callback(# dash.dependencies.Output('subfolder-dropdown', 'options'),# dash.dependencies.Output('variable-dropdown', 'options'),dash.dependencies.Output('submit-button', 'n_clicks'), # Add this output to reset submit button clicks[dash.dependencies.Input('submit-button', 'n_clicks')],[dash.dependencies.Input('path-input', 'value')],14 unmodified lineslabels = list(data[list(data.keys())[0]]['aircraft_data'][list(data[list(data.keys())[0]]['aircraft_data'].keys())[0]].columns.tolist()) # Extracting column names for the first aircraft-specific dataframereturn subfolder_labels, labels, 0else:# return [], [], 0return 0# Define the callback to update the graphs based on the slider value@app.callback(2 unmodified linesdash.dependencies.Output('altitude-series', 'figure'),# dash.dependencies.Output('timeline', 'figure'),# dash.dependencies.Input('path-input', 'value'),# [dash.dependencies.Input('subfolder-dropdown', 'value'),[dash.dependencies.Input('time-slider', 'value'),dash.dependencies.Input('variable-dropdown','value'),dash.dependencies.Input('backgroundDivert','value'),dash.dependencies.Input('IFthreshold','value'),dash.dependencies.Input('TAthreshold','value'),dash.dependencies.Input('updateTime','value')])# def update_graph(selected_subfolder, selected_time):# # Load the CSV files into pandas DataFrames from the selected subfolder4 unmodified lines# exclude = ['Detect_crash','Detect_conflict','Flight_Dynamics','Reroute_flight','Show_radar','Direct_to_waypoint','Change_heading']# events = parse_action_trace(f'data/{selected_subfolder}/actionTrace.csv', exclude)def update_graph(selected_time, selected_variable, backgroundDivert, RequiredCertainty, TimeBuffer, WaitInterval): #selected_subfolder,selected_subfolder = "exampleTime=200"+backgroundDivert+"_"+str(RequiredCertainty)+"_"+str(TimeBuffer)+"_"+str(WaitInterval)if selected_subfolder not in data_store:return go.Figure(), go.Figure(), go.Figure(layout=dict(autosize=True, width=None, height=300))#, go.Figure()45 unmodified lines# webbrowser.open_new("http://127.0.0.1:8050/")# app.run_server(debug=True)app.run_server(debug=True, host='0.0.0.0', port=7860)
app.py+85-48