diff --git a/src/pages/dashboard.py b/src/pages/dashboard.py index 93bc4fa789a114c674eae72bc55589a7678fd382..d2c6036e01763fb238ff48e53f6e0128b396f589 100644 --- a/src/pages/dashboard.py +++ b/src/pages/dashboard.py @@ -27,6 +27,7 @@ from mlair.time_series import plot as plot_ml_time_series import pages.dashboard_translations as guitr import pages.dashboard_constants as guiconst + # the following should be done with static files! APP_HOME = Path.cwd() IMAGE_PATH = APP_HOME.joinpath("static", "images") @@ -475,19 +476,28 @@ def generate_eurad_scen_body(language_id): return [ dbc.Row([ dbc.Col(dbc.Label(f"{guitr.date_label[language_id]}"), width=3), - dbc.Col(dcc.DatePickerSingle(date=dt.date.today(), + dbc.Col(dcc.DatePickerSingle(id="eurad_scen_start_date", + date=dt.date(2018, 7, 22), display_format=guitr.date_format[language_id], - first_day_of_week=guitr.first_day_of_week[language_id])), + first_day_of_week=guitr.first_day_of_week[language_id], + min_date_allowed=dt.date(2018, 7, 22), + max_date_allowed=dt.date(2018, 7, 31), + initial_visible_month=dt.date(2018, 7, 1))), dbc.Col(dbc.Label(f"{guitr.forecast_length_label[language_id]}:")), - dbc.Col(dcc.Dropdown(value=guitr.forecast_length_options[language_id][0], options=guitr.forecast_length_options[language_id])) + dbc.Col(dcc.Dropdown(value=guitr.forecast_length_options[language_id][0], options=guitr.forecast_length_options[language_id], + id="eurad_scen_forecast_length")) ], class_name="row mt-3"), dbc.Row([ dbc.Col(dbc.Label(f"{guitr.region_label[language_id]}"), width=3), - dbc.Col(dcc.RadioItems(['NRW', 'Berlin-Brandenburg'], 'NRW')), + dbc.Col(dcc.RadioItems(options={ + 0: 'Nordrhein-Westfalen', + 1: 'Berlin-Brandenburg'}, + value=0, id="eurad_scen_region_choice")), ], class_name="row mt-3"), dbc.Row([ dbc.Col(dbc.Label(f"{guitr.emis_scen_label[language_id]}"), width=3), - dbc.Col(dcc.Dropdown(value=emis_info[language_id][" Name"][0], options=emis_info[language_id][" Name"])), + dbc.Col(dcc.Dropdown(options=[{'label': emis_info[language_id][" Name"][i], 'value': i} for i in range(len(emis_info[language_id][" Name"]))], + value=0, id="eurad_scen_emi")), dbc.Col(dbc.Button(f"{guitr.help_emissions_label[language_id]}", id="help_emis_open", class_name="fzj_style_btn"), width=3), dbc.Modal([ dbc.ModalHeader(f"{guitr.help_emissions_label[language_id]}"), @@ -1038,6 +1048,61 @@ def ml_fcast_job_run(run_button, region, startdate, forecast_length, species, me generate_eurad_scen_output_modal(container_id="eurad_scen_output_modal_container", language_id=language_id)] +@callback( + [Output("eurad_scen_modal", "is_open", allow_duplicate=True), + Output("my_jobs_tab", "children", allow_duplicate=True)], + Input("eurad_scen_run", "n_clicks"), + [State("eurad_scen_region_choice", "value"), + State('eurad_scen_start_date', 'date'), + State('eurad_scen_forecast_length', 'value'), + State('eurad_scen_emi', 'value'), + State("user-info", "data")], + prevent_initial_call=True +) +def eurad_scen_job_run(run_button, region, startdate, forecast_length, emi_scen, user_dict): + # add job to user's job list + user_id = json.loads(user_dict)["user_id"] + language_id = json.loads(user_dict)["language_id"] + new_job_dict = {} + jobnr = get_random_string(12) + new_job_dict['id'] = jobnr + # application is EURAD-IM -- should be taken from the controlled vocabulary! + new_job_dict['application'] = 0 + new_job_dict['region'] = region + new_job_dict['start_date'] = startdate + ' 00:00' + new_job_dict['forecast_length'] = int(forecast_length.split()[0]) + new_job_dict['emis_scen'] = emi_scen + # take the coding for the status from the controlled vocabulary! + # set it to "waiting" since it will just be submitted + new_job_dict['status'] = 2 + # EURAD-IM does not have any species to be chosen + new_job_dict['species'] = None + # EURAD-IM does not have any metrics to be chosen + new_job_dict['metric'] = None + + # submit job + base_url = f"{UNICORE_BASE}JURECA/rest/core" + credentials = uc_credentials.UsernamePassword(UNICORE_USER, UNICORE_PASSWORD) + client = uc_client.Client(credentials, base_url) + job_description = {'Executable': "/p/project/cjicg21/schroeder5/Destine_AQ/start_destine_demonstrator.sh", "Job type": "ON_LOGIN_NODE", 'Arguments':[jobnr, emi_scen], } + job = client.new_job(job_description) + + # let's wait while the job is still running + # otherwise, the job status will not be able to be determined + job.poll() + + # now create job in db (otherwise the status cannot be determined!) + create_db_job_entry(user_id, new_job_dict) + + # return updated values + retval = ctx.triggered_id == "eurad_scen_open" + return retval,\ + [generate_jobs_table(user_id=user_id, language_id=language_id), + generate_eurad_im_output_modal(language_id=language_id), + generate_ml_fcast_output_modal(language_id=language_id), + generate_eurad_scen_output_modal(container_id="eurad_scen_output_modal_container", language_id=language_id)] + + @callback( Output("eurad_im_download_result", "data"), Input("eurad_im_output_download", "n_clicks"),