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

Feature/discrete continuous simple #85

Merged
merged 7 commits into from
Jul 14, 2021
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
8 changes: 4 additions & 4 deletions components/categorical-variable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function CategoricalVariable(props: CategoricalVariableProps) {
<div className={classes.option}>
<Typography variant="body1">{option}</Typography>
<IconButton onClick={() => deleteOption(index)} size="small" aria-label="delete" color="primary">
<DeleteIcon />
<DeleteIcon fontSize="small" />
</IconButton>
</div>
</div>
Expand All @@ -65,10 +65,10 @@ export default function CategoricalVariable(props: CategoricalVariableProps) {
setOptions([...options, option])
}}/>

<Box mt={1}>
<Button disabled={isDisabled} variant="outlined" type="submit">Add</Button>
<Box mt={2}>
<Button disabled={isDisabled} size="small" variant="outlined" type="submit">Add variable</Button>
</Box>

</form>
</>
)
Expand Down
1 change: 1 addition & 0 deletions components/data-points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default function DataPoints(props: DataPointProps) {
</IconButton>
</>
}>
{buildCombinedVariables().length === 0 && "Data points will appear here"}
{buildCombinedVariables().length > 0 && isLoadingState &&
<CircularProgress size={24}/>
}
Expand Down
25 changes: 14 additions & 11 deletions components/experiment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ export default function Experiment(props: ExperimentProps) {
updateDescription={(description: string) => dispatch({ type: 'updateExperimentDescription', payload: description })} />
</Grid>

<Grid item xs={12}>
<NextExperiments
nextValues={nextValues}
headers={headers} />
</Grid>

<Grid item xs={12}>
<OptimizerModel
valueVariables={valueVariables}
Expand All @@ -182,11 +176,20 @@ export default function Experiment(props: ExperimentProps) {

<Grid container spacing={2}>
<Grid item xs={12} xl={6}>
<DataPoints
valueVariables={experiment.valueVariables}
categoricalVariables={experiment.categoricalVariables}
dataPoints={experiment.dataPoints}
onUpdateDataPoints={(dataPoints: DataPointType[][]) => dispatch({ type: 'updateDataPoints', payload: dataPoints })} />
<Grid container spacing={2}>
<Grid item xs={12}>
<NextExperiments
nextValues={nextValues}
headers={headers} />
</Grid>
<Grid item xs={12}>
<DataPoints
valueVariables={experiment.valueVariables}
categoricalVariables={experiment.categoricalVariables}
dataPoints={experiment.dataPoints}
onUpdateDataPoints={(dataPoints: DataPointType[][]) => dispatch({ type: 'updateDataPoints', payload: dataPoints })} />
</Grid>
</Grid>
</Grid>
<Grid item xs={12} xl={6}>
<Plots />
Expand Down
1 change: 0 additions & 1 deletion components/model-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function ModelEditor(props: ModelEditorProps) {
name="info.description"
label="Description"
value={info.description}
required
onChange={(e: ChangeEvent) => props.updateDescription((e.target as HTMLInputElement).value)}
/>
</form>
Expand Down
2 changes: 1 addition & 1 deletion components/optimizer-configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type OptimizerConfiguratorProps = {

export default function OptimizerConfigurator(props: OptimizerConfiguratorProps) {
const { config , onConfigUpdated} = props
const { register, handleSubmit, reset, watch, errors, getValues } = useForm<OptimizerConfig>()
const { register, getValues } = useForm<OptimizerConfig>()

const handleChange = () => {
onConfigUpdated(getValues() as OptimizerConfig)
Expand Down
191 changes: 99 additions & 92 deletions components/optimizer-model.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Box, Button, IconButton, Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@material-ui/core'
import { Box, IconButton, Table, TableBody, TableCell, TableHead, TableRow, Typography, Tooltip } from '@material-ui/core'
import { CategoricalVariableType, ValueVariableType } from '../types/common'
import DeleteIcon from '@material-ui/icons/Delete'
import { useState } from 'react'
import VariableEditor from './variable-editor'
import useStyles from '../styles/optimizer-model.style'
import { TitleCard } from './title-card'
import LensIcon from '@material-ui/icons/Lens'
import PanoramaFishEyeIcon from '@material-ui/icons/PanoramaFishEye'

type OptimizerModelProps = {
valueVariables: ValueVariableType[]
Expand All @@ -17,105 +19,110 @@ type OptimizerModelProps = {

export default function OptimizerModel(props: OptimizerModelProps) {
const { valueVariables, categoricalVariables, disabled, onDeleteValueVariable, onDeleteCategoricalVariable, addValueVariable, addCategoricalVariable } = props
const [isAddOpen, setAddOpen] = useState(false)
const classes = useStyles()

return (
<TitleCard title="Input model">
{valueVariables.length > 0 &&
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell align="left">Description</TableCell>
<TableCell align="right">minVal</TableCell>
<TableCell align="right">maxVal</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{valueVariables.map((valueVar, valueIndex) => (
<TableRow key={valueIndex}>
<TableCell component="th" scope="row">{valueVar.name}</TableCell>
<TableCell align="left">{valueVar.description}</TableCell>
<TableCell align="right">{valueVar.minVal}</TableCell>
<TableCell align="right">{valueVar.maxVal}</TableCell>
<TableCell align="right">
<IconButton
disabled={disabled}
size="small"
onClick={() => {onDeleteValueVariable(valueVar)}}>
<DeleteIcon color={disabled ? "inherit" : "primary"} fontSize="small"/>
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
}

{categoricalVariables.length > 0 &&
<Box mt={2} mb={2}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell align="left">Description</TableCell>
<TableCell align="left">Options</TableCell>
<TableCell align="left"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{categoricalVariables.map((catVar, catIndex) => (
<TableRow key={catIndex}>
<TableCell component="th" scope="row">{catVar.name}</TableCell>
<TableCell align="left">{catVar.description}</TableCell>
<TableCell align="left">
{catVar.options.map((option, optionIndex) => (
<div key={optionIndex}>
<Typography variant="body2">{option}</Typography>
</div>
))}
</TableCell>
<TableCell align="right">
<IconButton
disabled={disabled}
size="small"
onClick={() => {onDeleteCategoricalVariable(catVar)}}>
<DeleteIcon color={disabled ? "inherit" : "primary"} fontSize="small"/>
</IconButton>
</TableCell>
<TitleCard title="Input model" padding={0}>
{(valueVariables.length > 0 || categoricalVariables.length > 0) &&
<Box p={2}>
{valueVariables.length > 0 &&
<Table size="small">
<TableHead>
<TableRow>
<TableCell></TableCell>
<TableCell>Name</TableCell>
<TableCell align="left">Description</TableCell>
<TableCell align="right">minVal</TableCell>
<TableCell align="right">maxVal</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Box>
}
{!isAddOpen &&
<Box mt={2}>
<Button
disabled={disabled}
variant="outlined"
size="small"
onClick={() => setAddOpen(true)}>Add variable</Button>
</TableHead>
<TableBody>
{valueVariables.map((valueVar, valueIndex) => (
<TableRow key={valueIndex}>
<TableCell>{valueVar.discrete ?
<Tooltip title="Discrete">
<LensIcon className={classes.iconDiscrete}/>
</Tooltip> :
<Tooltip title="Continuous">
<PanoramaFishEyeIcon className={classes.iconDiscrete} />
</Tooltip>}
</TableCell>
<TableCell component="th" scope="row">{valueVar.name}</TableCell>
<TableCell align="left">{valueVar.description}</TableCell>
<TableCell align="right">{valueVar.minVal}</TableCell>
<TableCell align="right">{valueVar.maxVal}</TableCell>
<TableCell align="right">
<IconButton
disabled={disabled}
size="small"
onClick={() => {onDeleteValueVariable(valueVar)}}>
<DeleteIcon color={disabled ? "inherit" : "primary"} fontSize="small"/>
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
}

{categoricalVariables.length > 0 &&
<Box mt={2} mb={2}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell align="left">Description</TableCell>
<TableCell align="left">Options</TableCell>
<TableCell align="left"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{categoricalVariables.map((catVar, catIndex) => (
<TableRow key={catIndex}>
<TableCell component="th" scope="row">{catVar.name}</TableCell>
<TableCell align="left">{catVar.description}</TableCell>
<TableCell align="left">
{catVar.options.map((option, optionIndex) => (
<div key={optionIndex}>
<Typography variant="body2">{option}</Typography>
</div>
))}
</TableCell>
<TableCell align="right">
<IconButton
disabled={disabled}
size="small"
onClick={() => {onDeleteCategoricalVariable(catVar)}}>
<DeleteIcon color={disabled ? "inherit" : "primary"} fontSize="small"/>
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Box>
}
</Box>
}
{isAddOpen &&
<Box mt={2}>

<Box pb={2} className={classes.editBox}>
{!disabled &&
<VariableEditor
isAddVariableDisabled={disabled}
addCategoricalVariable={(categoricalVariable: CategoricalVariableType) => addCategoricalVariable(categoricalVariable)}
addValueVariable={(valueVariable: ValueVariableType) => addValueVariable(valueVariable)}
close={() => setAddOpen(false)} />
</Box>
}

{disabled &&
<Box mt={2}>
<Typography variant="body2" color="textSecondary">
Note: Model cannot be updated while there are data points
</Typography>
</Box>
}
/>
}

{disabled &&
<Box pt={2} pr={2} pl={2}>
<Typography variant="body2" color="textSecondary">
Model cannot be updated while there are data points.
</Typography>
</Box>
}
</Box>
</TitleCard>
)
}
10 changes: 6 additions & 4 deletions components/plots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export const Plots = () => {

return (
<>
{experiment.results.plots.length > 0 &&
<TitleCard title="Plots">
<TitleCard title="Plots">
{experiment.results.plots.length > 0 ?
<ul>
{experiment.results.plots && experiment.results.plots.map(plot => <li key={plot.id}><img src={`data:image/png;base64, ${plot.plot}`} alt={plot.id}></img></li>)}
</ul>
</TitleCard>
}
:
"Plots will appear here"
}
</TitleCard>
</>
)
}
5 changes: 3 additions & 2 deletions components/title-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import useStyles from "../styles/title-card.style"

type TitleCardProps = {
title: ReactNode
padding?: number
children: any
}

export const TitleCard = (props: TitleCardProps) => {
const { title, children } = props
const { title, padding, children } = props
const classes = useStyles()

return (
Expand All @@ -17,7 +18,7 @@ export const TitleCard = (props: TitleCardProps) => {
<Box className={classes.title}>
{title}
</Box>
<Box p={2}>
<Box p={padding !== undefined ? padding : 2}>
{children}
</Box>
</CardContent>
Expand Down
Loading