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

330 wrong values are transferred to data points #331

Merged
merged 5 commits into from
Oct 4, 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
5 changes: 5 additions & 0 deletions .changeset/honest-monkeys-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@boostv/process-optimizer-frontend-core': patch
---

Fix wrong variables being copied to data points
12 changes: 3 additions & 9 deletions packages/core/src/context/experiment/experiment-reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { settings, versionInfo } from '@core/common'
import { assertUnreachable } from '@core/common/util'
import {
selectActiveDataPoints,
selectActiveVariablesFromExperiment,
selectNextValues,
} from './experiment-selectors'
import { createFetchExperimentResultRequest } from '@core/context/experiment/api'
Expand Down Expand Up @@ -185,14 +186,7 @@ export const experimentReducer = produce(
break
case 'copySuggestedToDataPoints': {
const nextValues = selectNextValues(state)
const variables = state.valueVariables
.map(v => ({ name: v.name, type: 'numeric' }))
.concat(
state.categoricalVariables.map(c => ({
name: c.name,
type: 'categorical',
}))
)
const variables = selectActiveVariablesFromExperiment(state)
const newEntries: DataEntry[] = nextValues
.filter((_, i) => action.payload.includes(i))
.map((n, k) => ({
Expand All @@ -214,7 +208,7 @@ export const experimentReducer = produce(
value: Number(v),
type: 'numeric',
}
case 'categorical':
case 'options':
return {
name: variable.name,
value: String(v),
Expand Down
45 changes: 45 additions & 0 deletions packages/core/src/context/experiment/experiment-selectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { initialState, State } from '@core/context/experiment/store'
import {
selectActiveVariablesFromExperiment,
selectCalculatedSuggestionCount,
selectId,
selectIsConstraintActive,
Expand Down Expand Up @@ -175,4 +176,48 @@ describe('Experiment selectors', () => {
}
)
})

describe('selectActiveVariablesFromExperiment', () => {
it('should filter out disabled variables', () => {
const experiment: ExperimentType = {
...initialState.experiment,
valueVariables: [
{
name: 'Water',
description: '',
type: 'continuous',
min: 0,
max: 100,
enabled: true,
},
{
name: 'Cheese',
description: '',
type: 'discrete',
min: 0,
max: 100,
enabled: false,
},
],
categoricalVariables: [
{
name: 'Icing',
description: '',
options: ['Vanilla', 'Chocolate'],
enabled: true,
},
{
name: 'Colour',
description: '',
options: ['Blue', 'Red'],
enabled: false,
},
],
}
const activeVariables = selectActiveVariablesFromExperiment(experiment)
expect(activeVariables.length).toBe(2)
expect(activeVariables[0]?.name).toBe('Water')
expect(activeVariables[1]?.name).toBe('Icing')
})
})
})
23 changes: 22 additions & 1 deletion packages/core/src/context/experiment/experiment-selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExperimentType } from 'common'
import { CombinedVariableType, ExperimentType } from 'common'
import { State } from './store'

export const selectExperiment = (state: State) => state.experiment
Expand Down Expand Up @@ -55,6 +55,27 @@ export const selectActiveVariableNames = (state: State): string[] => {
)
}

export const selectActiveVariablesFromExperiment = (
experiment: ExperimentType
) => {
const valueVars: CombinedVariableType[] = experiment.valueVariables
.filter(v => v.enabled)
.map(v => ({
name: v.name,
description: v.description,
type: 'numeric',
}))
const catVars: CombinedVariableType[] = experiment.categoricalVariables
.filter(v => v.enabled)
.map(v => ({
name: v.name,
description: v.description,
type: 'options',
options: v.options,
}))
return valueVars.concat(catVars)
}

export const selectSumConstraint = (state: State) =>
selectSumConstraintFromExperiment(selectExperiment(state))

Expand Down
45 changes: 45 additions & 0 deletions packages/core/src/context/experiment/reducers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,51 @@ describe('experiment reducer', () => {
{ type: 'categorical', name: 'Icing', value: 'Chocolate' },
])
})

it('should only copy enabled variables to data points', () => {
const action: ExperimentAction = {
type: 'copySuggestedToDataPoints',
payload: [0],
}
const state: State = {
...initState,
experiment: {
...initState.experiment,
valueVariables: [
{
type: 'continuous',
name: 'Water',
description: 'Wet',
min: 100,
max: 200,
enabled: false,
},
],
categoricalVariables: [
{
name: 'Icing',
description: '',
options: ['Vanilla', 'Chocolate'],
enabled: true,
},
],
dataPoints: [],
results: {
...initState.experiment.results,
next: [['Vanilla'], ['Chocolate']],
},
},
}
const newDataPoints = rootReducer(state, action).experiment.dataPoints
expect(newDataPoints.length).toBe(1)
expect(newDataPoints[0]?.data).toEqual([
{
type: 'categorical',
name: 'Icing',
value: 'Vanilla',
},
])
})
})

it('should add scores to new data point for multi-objective - two scores enabled', () => {
Expand Down