mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-09 11:28:14 +08:00
fix by review
This commit is contained in:
@@ -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"],
|
||||
|
||||
@@ -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,
|
||||
|
||||
Vendored
+2
-1
@@ -210,7 +210,8 @@ type StudyParamImportance = {
|
||||
}
|
||||
|
||||
type PreferenceHistory = {
|
||||
uuid: string
|
||||
id: string
|
||||
preference_id: string
|
||||
candidates: number[]
|
||||
clicked: number
|
||||
feedback_mode: PreferenceFeedbackMode
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user