Simplify type definition in the standalone app

This commit is contained in:
c-bata
2024-03-03 01:13:49 +09:00
parent 52d64f0980
commit 06d1527a36
4 changed files with 14 additions and 32 deletions
+2 -4
View File
@@ -86,8 +86,7 @@ export const TrialTable: FC<{
null,
sortable: true,
filterable: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
less: (firstEl, secondEl, _): number => {
less: (firstEl, secondEl): number => {
const firstVal = firstEl.params.find(
(p) => p.name === s.name
)?.param_internal_value
@@ -117,8 +116,7 @@ export const TrialTable: FC<{
?.value || null,
sortable: attr_spec.sortable,
filterable: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
less: (firstEl, secondEl, _): number => {
less: (firstEl, secondEl): number => {
const firstVal = firstEl.user_attrs.find(
(attr) => attr.key === attr_spec.key
)?.value
+2 -9
View File
@@ -99,15 +99,8 @@ const parseDistribution = (distribution: string): Distribution => {
}
} else {
return {
// TODO(gen740): support other types
type: "CategoricalDistribution",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
choices: distributionJson["attributes"]["choices"].map((choice: any) => {
return {
pytype: "str",
value: choice.toString(),
}
}),
choices: distributionJson["attributes"]["choices"],
}
}
}
@@ -201,7 +194,7 @@ class JournalStorage {
} else if (distribution.type === "IntDistribution") {
return value.toString()
} else {
return distribution.choices[value].value
return distribution.choices[value]
}
})(),
distribution: distribution,
+5 -13
View File
@@ -206,8 +206,8 @@ const getTrialValues = (
db: SQLite3DB,
trialId: number,
schemaVersion: string
): TrialValueNumber[] => {
const values: TrialValueNumber[] = []
): number[] => {
const values: number[] = []
if (isGreaterSchemaVersion(schemaVersion, "v3.0.0.c")) {
db.exec({
sql:
@@ -267,13 +267,13 @@ const getTrialParams = (db: SQLite3DB, trialId: number): TrialParam[] => {
const paramInternalValueToExternalValue = (
distribution: Distribution,
internalValue: number
): string => {
): CategoricalChoiceType => {
if (distribution.type === "FloatDistribution") {
return internalValue.toString()
} else if (distribution.type === "IntDistribution") {
return internalValue.toString()
} else {
return distribution.choices[internalValue].value
return distribution.choices[internalValue]
}
}
@@ -336,17 +336,9 @@ const parseDistributionJSON = (t: string): Distribution => {
log: true,
}
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const choices = parsed.attributes.choices.map((value: any) => {
// TODO(c-bata): Support other types
return {
pytype: "str",
value: value.toString(),
}
})
return {
type: "CategoricalDistribution",
choices: choices,
choices: parsed.attributes.choices,
}
}
}
+5 -6
View File
@@ -1,7 +1,5 @@
declare const IS_VSCODE: boolean
type TrialValueNumber = number
type TrialIntermediateValueNumber = number
type TrialState = "Running" | "Complete" | "Pruned" | "Fail" | "Waiting"
type TrialStateFinished = "Complete" | "Fail" | "Pruned"
type StudyDirection = "maximize" | "minimize" | "not_set"
@@ -22,14 +20,15 @@ type IntDistribution = {
log: boolean
}
type CategoricalChoiceType = null | boolean | number | string
type CategoricalDistribution = {
type: "CategoricalDistribution"
choices: { pytype: string; value: string }[]
choices: CategoricalChoiceType[]
}
type TrialIntermediateValue = {
step: number
value: TrialIntermediateValueNumber
value: number
}
type Distribution =
@@ -63,7 +62,7 @@ type Trial = {
number: number
study_id: number
state: TrialState
values?: TrialValueNumber[]
values?: number[]
params: TrialParam[]
intermediate_values: TrialIntermediateValue[]
user_attrs: Attribute[]
@@ -74,7 +73,7 @@ type Trial = {
type TrialParam = {
name: string
param_internal_value: number
param_external_value: string
param_external_value: CategoricalChoiceType
param_external_type: string
distribution: Distribution
}