diff --git a/src/pages/dashboard.py b/src/pages/dashboard.py index 32adddbfaa8f94540f5389e41b31dd2bf728b77f..99fb6a6d0d168b7633a16274989f437b57a6e20c 100644 --- a/src/pages/dashboard.py +++ b/src/pages/dashboard.py @@ -278,10 +278,12 @@ def generate_ml_fcast_output_body(language_id, jobnr): ] @callback( - Output('image-container-ml-output', 'children'), + [Output('image-container-ml-output', 'children'), + Output("plot-info", "data", allow_duplicate=True)], Input('station-dropdown-ml-output', 'value'), [State("user-info", "data"), - State("job-info", "data")] + State("job-info", "data")], + prevent_initial_call=True ) def update_mlair_image(selected_station, users_dict, job_dict): jobid = json.loads(job_dict)["jobnr"] @@ -290,13 +292,28 @@ def update_mlair_image(selected_station, users_dict, job_dict): language_id = json.loads(users_dict)["language_id"] except: language_id = 0 + job_props = get_db_job_entry(jobid) + station_code, station_label = selected_station.split(',') + station_code = station_code.strip() + plotinfo_dict = {} + plotinfo_dict["station"] = station_code + ispec = job_props['species'] + species = guitr.species_options[0][ispec] + ml_species = guiconst.ml_names[species] + plotinfo_dict["species"] = ml_species + plotinfo_dict["start_date"] = job_props['start_date'][0:10] + forecast_length = job_props['forecast_length'] + fc_length_str = "{}{}{}".format(forecast_length, guitr.day_label[language_id], guitr.day_plural_label[language_id] if forecast_length > 1 else "") + plotinfo_dict["fc_length"] = fc_length_str + plotinfo_json = json.dumps(plotinfo_dict) + image_path = plot_ml_time_series(selected_station, language_id, ispec=job_props['species'], start_date=job_props['start_date'], forecast_length=job_props['forecast_length']) image = html.Img(src=image_path, className='image-fit-container') - return image + return image, plotinfo_json else: return None @@ -1228,15 +1245,13 @@ def mlair_output_download(download_button, job_dict): prevent_initial_call=True ) def mlair_plots_download(download_button, job_dict, plot_dict): -# jobid = json.loads(job_dict)["jobnr"] -# species = json.loads(job_dict)["variable"] -# start_date = json.loads(job_dict)["start_date"] -# station = json.loads(plot_dict)["station"] + species = json.loads(plot_dict)["species"] + station = json.loads(plot_dict)["station"] + start_date = json.loads(plot_dict)["start_date"] + fc_length = json.loads(plot_dict)["fc_length"] # file name according to users selection -# output_file_name = f"mlair_{ml_species}_{station_code}_{start_date}_{fc_length_str}.png" - # just to test - output_file_name = "mlair_O3_DENW067_2018-07-18_4Tage.png" + output_file_name = f"mlair_{species}_{station}_{start_date}_{fc_length}.png" infile = str(ASSETS_PATH.joinpath('mlair', output_file_name)) return dcc.send_file( infile