Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename score to quality #334

Merged
merged 8 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eight-hounds-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@boostv/process-optimizer-frontend-core': minor
'@boostv/process-optimizer-frontend-ui': minor
---

Rename score to quality
4 changes: 3 additions & 1 deletion packages/core/src/common/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { z } from 'zod'
// Change the current version when doing structural
// changes to any types belonging to ExperimentType

export const currentVersion = '16'
export const currentVersion = '17'

export const scoreName = 'Quality (0-5)'

const infoSchema = z.object({
name: z.string(),
Expand Down
21 changes: 11 additions & 10 deletions packages/core/src/common/util/converters/converters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ExperimentType,
ScoreVariableType,
ValueVariableType,
scoreName,
} from '@core/common/types'
import { initialState } from '@core/context'
import {
Expand All @@ -24,14 +25,14 @@ describe('converters', () => {
{ type: 'numeric', name: 'Peber', value: 982 },
{ type: 'numeric', name: 'Hvedemel', value: 632 },
{ type: 'categorical', name: 'Kunde', value: 'Mus' },
{ type: 'score', name: 'score', value: 0.1 },
{ type: 'score', name: scoreName, value: 0.1 },
] satisfies DataPointType[],
[
{ type: 'numeric', name: 'Sukker', value: 15 },
{ type: 'numeric', name: 'Peber', value: 123 },
{ type: 'numeric', name: 'Hvedemel', value: 324 },
{ type: 'categorical', name: 'Kunde', value: 'Ræv' },
{ type: 'score', name: 'score', value: 0.2 },
{ type: 'score', name: scoreName, value: 0.2 },
] satisfies DataPointType[],
].map((data, idx) => ({
meta: { enabled: true, id: idx + 1, valid: true },
Expand All @@ -43,16 +44,16 @@ describe('converters', () => {
{ type: 'numeric', name: 'Peber', value: 982 },
{ type: 'numeric', name: 'Hvedemel', value: 632 },
{ type: 'categorical', name: 'Kunde', value: 'Mus' },
{ type: 'score', name: 'score', value: 0.1 },
{ type: 'score', name: 'score2', value: 0.3 },
{ type: 'score', name: scoreName, value: 0.1 },
{ type: 'score', name: scoreName + ' 2', value: 0.3 },
] satisfies DataPointType[],
[
{ type: 'numeric', name: 'Sukker', value: 15 },
{ type: 'numeric', name: 'Peber', value: 123 },
{ type: 'numeric', name: 'Hvedemel', value: 324 },
{ type: 'categorical', name: 'Kunde', value: 'Ræv' },
{ type: 'score', name: 'score', value: 0.2 },
{ type: 'score', name: 'score2', value: 0.4 },
{ type: 'score', name: scoreName, value: 0.2 },
{ type: 'score', name: scoreName + ' 2', value: 0.4 },
] satisfies DataPointType[],
].map((data, idx) => ({
meta: { enabled: true, id: idx + 1, valid: true },
Expand Down Expand Up @@ -246,8 +247,8 @@ describe('converters', () => {
sampleExperiment.categoricalVariables,
sampleExperiment.valueVariables,
[
{ name: 'score', description: '', enabled: true },
{ name: 'score2', description: '', enabled: true },
{ name: scoreName, description: '', enabled: true },
{ name: scoreName + ' 2', description: '', enabled: true },
],
sampleMultiObjectiveDataPoints
)
Expand All @@ -263,8 +264,8 @@ describe('converters', () => {
sampleExperiment.categoricalVariables,
sampleExperiment.valueVariables,
[
{ name: 'score', description: '', enabled: true },
{ name: 'score2', description: '', enabled: false },
{ name: scoreName, description: '', enabled: true },
{ name: scoreName + ' 2', description: '', enabled: false },
],
sampleMultiObjectiveDataPoints
)
Expand Down
102 changes: 102 additions & 0 deletions packages/core/src/common/util/migration/data-formats/17.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"id": "1234",
"changedSinceLastEvaluation": true,
"lastEvaluationHash": "never-calculated",
"info": {
"dataFormatVersion": "17",
"swVersion": "v1.2.0-16",
"name": "Cake",
"description": "Yummy",
"version": 0,
"extras": {}
},
"categoricalVariables": [
{
"name": "Icing",
"description": "Sugary",
"options": ["White", "Brown"],
"enabled": true
}
],
"valueVariables": [
{
"name": "name1",
"description": "desc1",
"min": 10,
"max": 100,
"type": "discrete",
"enabled": true
},
{
"name": "name2",
"description": "desc2",
"min": 10.2,
"max": 100.3,
"type": "continuous",
"enabled": true
}
],
"scoreVariables": [
{
"name": "Quality (0-5)",
"description": "Quality (0-5)",
"enabled": true
}
],
"constraints": [
{
"type": "sum",
"dimensions": [],
"value": 0
}
],
"optimizerConfig": {
"baseEstimator": "GP",
"acqFunc": "EI",
"initialPoints": 3,
"kappa": 1.96,
"xi": 0.01
},
"results": {
"id": "",
"next": [[]],
"plots": [],
"pickled": "",
"expectedMinimum": [],
"extras": {}
},
"dataPoints": [
{
"meta": {
"enabled": true,
"valid": true,
"id": 1
},
"data": [
{
"type": "categorical",
"name": "Icing",
"value": "Brown"
},
{
"type": "numeric",
"name": "name1",
"value": 10
},
{
"type": "numeric",
"name": "name2",
"value": 10.2
},
{
"type": "score",
"name": "Quality (0-5)",
"value": 0.5
}
]
}
],
"extras": {
"experimentSuggestionCount": 1
}
}
130 changes: 127 additions & 3 deletions packages/core/src/common/util/migration/migration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JSONSchemaFaker } from 'json-schema-faker'
import { migrate, _migrate, MIGRATIONS } from './migration'
import version17 from './data-formats/17.json'
import version16 from './data-formats/16.json'
import version3 from './data-formats/3.json'
import version2 from './data-formats/2.json'
Expand All @@ -11,8 +12,14 @@ import brokenV9Experiment from '@core/sample-data/version-9-with-strings-in-opti
import large from '@core/sample-data/large.json'
import { emptyExperiment } from '@core/context/experiment'
import { formatNext } from './migrations/migrateToV9'
import { experimentSchema } from '@core/common/types'
import {
ExperimentType,
ScoreVariableType,
experimentSchema,
scoreName,
} from '@core/common/types'
import { storeLatestSchema, loadTestData } from './test-utils'
import { migrateToV17 } from './migrations/migrateToV17'

describe('Migration of data format', () => {
storeLatestSchema()
Expand Down Expand Up @@ -139,14 +146,131 @@ describe('Migration of data format', () => {
})
})

describe('migrateToV17', () => {
const scoreVarsMultiObjective = [
{
name: 'score',
description: 'score',
enabled: true,
},
{
name: 'score2',
description: 'score',
enabled: true,
},
] satisfies ScoreVariableType[]

const scoreVarsMultiObjectiveDisabled = [
{
name: 'score',
description: 'score',
enabled: true,
},
{
name: 'score2',
description: 'score',
enabled: true,
},
] satisfies ScoreVariableType[]

it.each([
['multiobjective, all enabled', scoreVarsMultiObjective],
['multiobjective, one disabled', scoreVarsMultiObjectiveDisabled],
])('scoreVariables should be renamed, %s', (_, scoreVariables) => {
const experiment16 = {
...version16,
scoreVariables,
} as unknown as ExperimentType
expect(migrateToV17(experiment16).scoreVariables).toEqual([
{
name: scoreName,
description: scoreName,
enabled: scoreVariables[0]?.enabled,
},
{
name: scoreName + ' 2',
description: scoreName,
enabled: scoreVariables[1]?.enabled,
},
])
})

const dataPointsSingle = [...version16.dataPoints]
const dataPointsMulti = [...version16.dataPoints].map(dp => ({
...dp,
data: [...dp.data].concat([
{
type: 'score',
name: 'score2',
value: 2,
},
]),
}))

it.each([
['one score exists', dataPointsSingle, false],
['two scores exist', dataPointsMulti, true],
])(
'data points should be renamed, %s',
(_, dataPoints, isMultiObjective) => {
const experiment16 = {
...version16,
dataPoints,
} as unknown as ExperimentType
const actual = [
{
meta: {
enabled: true,
valid: true,
id: 1,
},
data: [
{
type: 'categorical',
name: 'Icing',
value: 'Brown',
},
{
type: 'numeric',
name: 'name1',
value: 10,
},
{
type: 'numeric',
name: 'name2',
value: 10.2,
},
{
type: 'score',
name: scoreName,
value: 0.5,
},
].concat(
isMultiObjective
? [
{
type: 'score',
name: scoreName + ' 2',
value: 2,
},
]
: []
),
},
]
expect(migrateToV17(experiment16).dataPoints).toEqual(actual)
}
)
})

describe('experiment properties', () => {
//TODO: More/better tests - maybe this can be mabe obsolete by schema testing
it('newest data format json should match default empty experiment', () => {
expect(Object.keys(emptyExperiment).length).toBe(
Object.keys(version16).length
Object.keys(version17).length
)
Object.keys(emptyExperiment).forEach(p =>
expect(version16).toHaveProperty(p)
expect(version17).toHaveProperty(p)
)
})
})
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/common/util/migration/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
migrateToV15,
migrateToV16,
} from './migrations'
import { migrateToV17 } from './migrations/migrateToV17'

export const migrate = (json: any): ExperimentType => {
const migrated = _migrate(
Expand Down Expand Up @@ -98,4 +99,5 @@ export const MIGRATIONS: Migration[] = [
{ version: '14', converter: migrateToV14 },
{ version: '15', converter: migrateToV15 },
{ version: '16', converter: migrateToV16 },
{ version: '17', converter: migrateToV17 },
]
19 changes: 12 additions & 7 deletions packages/core/src/common/util/migration/migrations/migrateToV16.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { ExperimentType } from '@core/common/types'
import { produce } from 'immer'

export const migrateToV16 = (json: ExperimentType): ExperimentType => {
return produce(json, draft => {
draft.info.dataFormatVersion = '16'
draft.info.version = 0
draft.info.extras = {}
})
/* eslint-disable @typescript-eslint/no-explicit-any */
export const migrateToV16 = (json: any): ExperimentType => {
return produce(
json,
(draft: {
info: { dataFormatVersion: string; version: number; extras: unknown }
}) => {
draft.info.dataFormatVersion = '16'
draft.info.version = 0
draft.info.extras = {}
}
) as unknown as ExperimentType
}
Loading
Loading