From cbd71a60953a7e5612d22d2f6f3e2920359b6d85 Mon Sep 17 00:00:00 2001 From: moririn2528 Date: Tue, 5 Sep 2023 13:17:41 +0900 Subject: [PATCH] fix by review --- optuna_dashboard/_preferential_history.py | 22 +++++++++++----------- optuna_dashboard/ts/apiClient.ts | 6 ++++-- optuna_dashboard/ts/types/index.d.ts | 3 ++- python_tests/test_preferential_history.py | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/optuna_dashboard/_preferential_history.py b/optuna_dashboard/_preferential_history.py index 7ff588f5..00375e56 100644 --- a/optuna_dashboard/_preferential_history.py +++ b/optuna_dashboard/_preferential_history.py @@ -34,8 +34,8 @@ if TYPE_CHECKING: @dataclass(frozen=True) class ChooseWorstHistory: mode: Literal["ChooseWorst"] - uuid: str - preference_uuid: str # making it possible to remove the preference + id: str + preference_id: str # making it possible to remove the preference timestamp: datetime candidates: list[int] # a list of trial number clicked: int # The worst trial number in the candidates. @@ -43,8 +43,8 @@ class ChooseWorstHistory: def to_dict(self) -> dict[str, Any]: return { "mode": self.mode, - "uuid": self.uuid, - "preference_uuid": self.preference_uuid, + "id": self.id, + "preference_id": self.preference_id, "timestamp": self.timestamp.isoformat(), "candidates": self.candidates, "clicked": self.clicked, @@ -69,24 +69,24 @@ def report_history( else: assert False, f"Unknown mode: {input_data['mode']}" - preference_uuid = report_preferences( + preference_id = report_preferences( study_id=study_id, storage=storage, preferences=preferences, ) - history_uuid = str(uuid.uuid4()) + history_id = str(uuid.uuid4()) if input_data["mode"] == "ChooseWorst": history = ChooseWorstHistory( mode="ChooseWorst", - uuid=history_uuid, - preference_uuid=preference_uuid, + id=history_id, + preference_id=preference_id, timestamp=datetime.now(), candidates=input_data["candidates"], clicked=input_data["clicked"], ) - key = _SYSTEM_ATTR_PREFIX_HISTORY + history_uuid + key = _SYSTEM_ATTR_PREFIX_HISTORY + history_id storage.set_study_system_attr( study_id=study_id, key=key, @@ -106,8 +106,8 @@ def serialize_preference_history( histories.append( ChooseWorstHistory( mode="ChooseWorst", - uuid=choice["uuid"], - preference_uuid=choice["preference_uuid"], + id=choice["id"], + preference_id=choice["preference_id"], timestamp=datetime.fromisoformat(choice["timestamp"]), candidates=choice["candidates"], clicked=choice["clicked"], diff --git a/optuna_dashboard/ts/apiClient.ts b/optuna_dashboard/ts/apiClient.ts index 2c202f68..e23fc2ff 100644 --- a/optuna_dashboard/ts/apiClient.ts +++ b/optuna_dashboard/ts/apiClient.ts @@ -56,7 +56,8 @@ const convertTrialResponse = (res: TrialResponse): Trial => { } interface PreferenceHistoryResponce { - uuid: string + id: string + preference_id: string candidates: number[] clicked: number mode: PreferenceFeedbackMode @@ -67,7 +68,8 @@ const convertPreferenceHistory = ( res: PreferenceHistoryResponce ): PreferenceHistory => { return { - uuid: res.uuid, + id: res.id, + preference_id: res.preference_id, candidates: res.candidates, clicked: res.clicked, feedback_mode: res.mode, diff --git a/optuna_dashboard/ts/types/index.d.ts b/optuna_dashboard/ts/types/index.d.ts index dbe35d75..646d64cf 100644 --- a/optuna_dashboard/ts/types/index.d.ts +++ b/optuna_dashboard/ts/types/index.d.ts @@ -210,7 +210,8 @@ type StudyParamImportance = { } type PreferenceHistory = { - uuid: string + id: string + preference_id: string candidates: number[] clicked: number feedback_mode: PreferenceFeedbackMode diff --git a/python_tests/test_preferential_history.py b/python_tests/test_preferential_history.py index 64591783..b23dee9e 100644 --- a/python_tests/test_preferential_history.py +++ b/python_tests/test_preferential_history.py @@ -45,7 +45,7 @@ def test_report_and_get_choices(storage_supplier: Callable[[], StorageSupplier]) assert len(history) == 2 assert history[0]["candidates"] == [0, 1, 2] assert history[0]["clicked"] == 1 - preferences = sys_attrs[_SYSTEM_ATTR_PREFIX_PREFERENCE + history[0]["preference_uuid"]] + preferences = sys_attrs[_SYSTEM_ATTR_PREFIX_PREFERENCE + history[0]["preference_id"]] assert len(preferences) == 2 for i, (best, worst) in enumerate([(0, 1), (2, 1)]): assert len(preferences[i]) == 2 @@ -53,7 +53,7 @@ def test_report_and_get_choices(storage_supplier: Callable[[], StorageSupplier]) assert preferences[i][1] == worst assert history[1]["candidates"] == [0, 2, 3, 4] assert history[1]["clicked"] == 0 - preferences = sys_attrs[_SYSTEM_ATTR_PREFIX_PREFERENCE + history[1]["preference_uuid"]] + preferences = sys_attrs[_SYSTEM_ATTR_PREFIX_PREFERENCE + history[1]["preference_id"]] assert len(preferences) == 3 for i, (best, worst) in enumerate([(2, 0), (3, 0), (4, 0)]): assert len(preferences[i]) == 2