mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-11 12:30:25 +08:00
fix by review
This commit is contained in:
@@ -28,8 +28,8 @@ from ._cached_extra_study_property import get_cached_extra_study_property
|
||||
from ._custom_plot_data import get_plotly_graph_objects
|
||||
from ._importance import get_param_importance_from_trials_cache
|
||||
from ._pareto_front import get_pareto_front_trials
|
||||
from ._preferential_history import HistoryIdError
|
||||
from ._preferential_history import NewHistory
|
||||
from ._preferential_history import PreferenceHistoryNotFound
|
||||
from ._preferential_history import remove_history
|
||||
from ._preferential_history import report_history
|
||||
from ._preferential_history import restore_history
|
||||
@@ -314,7 +314,7 @@ def create_app(
|
||||
def remove_preference(study_id: int, history_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
remove_history(study_id, storage, history_id)
|
||||
except HistoryIdError:
|
||||
except PreferenceHistoryNotFound:
|
||||
response.status = 404
|
||||
return {"reason": f"history_id={history_id} is not found"}
|
||||
|
||||
@@ -326,7 +326,7 @@ def create_app(
|
||||
def restore_preference(study_id: int, history_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
restore_history(study_id, storage, history_id)
|
||||
except HistoryIdError:
|
||||
except PreferenceHistoryNotFound:
|
||||
response.status = 404
|
||||
return {"reason": f"history_id={history_id} is not found"}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ if TYPE_CHECKING:
|
||||
)
|
||||
|
||||
|
||||
class HistoryIdError(Exception):
|
||||
class PreferenceHistoryNotFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ def report_history(
|
||||
else:
|
||||
assert False, f"Unknown data: {input_data}"
|
||||
|
||||
id = report_preferences(
|
||||
preference_id = report_preferences(
|
||||
study_id=study_id,
|
||||
storage=storage,
|
||||
preferences=preferences,
|
||||
@@ -75,27 +75,27 @@ def report_history(
|
||||
if input_data.mode == "ChooseWorst":
|
||||
history: ChooseWorstHistory = {
|
||||
"mode": "ChooseWorst",
|
||||
"id": id,
|
||||
"id": preference_id,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"candidates": input_data.candidates,
|
||||
"clicked": input_data.clicked,
|
||||
"preferences": preferences,
|
||||
}
|
||||
|
||||
key = _SYSTEM_ATTR_PREFIX_HISTORY + id
|
||||
key = _SYSTEM_ATTR_PREFIX_HISTORY + preference_id
|
||||
storage.set_study_system_attr(
|
||||
study_id=study_id,
|
||||
key=key,
|
||||
value=json.dumps(history),
|
||||
)
|
||||
return id
|
||||
return preference_id
|
||||
|
||||
|
||||
def remove_history(study_id: int, storage: BaseStorage, history_id: str) -> None:
|
||||
system_attrs = storage.get_study_system_attrs(study_id)
|
||||
history_key = _SYSTEM_ATTR_PREFIX_HISTORY + history_id
|
||||
if history_key not in system_attrs:
|
||||
raise HistoryIdError
|
||||
raise PreferenceHistoryNotFound
|
||||
storage.set_study_system_attr(study_id, _SYSTEM_ATTR_PREFIX_PREFERENCE + history_id, [])
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ def restore_history(study_id: int, storage: BaseStorage, history_id: str) -> Non
|
||||
system_attrs = storage.get_study_system_attrs(study_id)
|
||||
history_key = _SYSTEM_ATTR_PREFIX_HISTORY + history_id
|
||||
if history_key not in system_attrs:
|
||||
raise HistoryIdError
|
||||
raise PreferenceHistoryNotFound
|
||||
history: History = json.loads(system_attrs.get(history_key, ""))
|
||||
storage.set_study_system_attr(
|
||||
study_id, _SYSTEM_ATTR_PREFIX_PREFERENCE + history_id, history["preferences"]
|
||||
|
||||
Reference in New Issue
Block a user