From 15ca335b07442bc772cbdcc02cb8a989832bd095 Mon Sep 17 00:00:00 2001 From: Kenshin Abe Date: Fri, 2 Feb 2024 19:25:07 +0900 Subject: [PATCH] Implement compare-studies API --- optuna_dashboard/_app.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index dfa7338c..ac0e1cf0 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -288,6 +288,21 @@ def create_app( return {"reason": f"plot_type={plot_type} is not supported."} return fig.to_json() + @app.get("/api/compare-studies/plot/") + @json_api_view + def get_compare_studies_plot(plot_type: str) -> dict[str, Any]: + study_ids = map(int, request.query.getall("study_ids[]")) + studies = [ + optuna.load_study(study_name=storage.get_study_name_from_id(study_id), storage=storage) + for study_id in study_ids + ] + if plot_type == "edf": + fig = optuna.visualization.plot_edf(studies) + else: + response.status = 404 # Not found + return {"reason": f"plot_type={plot_type} is not supported."} + return fig.to_json() + @app.put("/api/studies//note") @json_api_view def save_study_note(study_id: int) -> dict[str, Any]: