Commit f81dbbc3 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH

[js][exp] add some comments

parent db6e3c93
......@@ -480,7 +480,7 @@ export class ExperimentEditor extends React.Component<Props, State> {
// finds any issues/errors/misconfiguration throughout the experiment. things it checks:
// - whether a block doesnt have a dataset/algorithm assigned yet
// - whether a block with an algorithm doesnt have an input/output assigned yet
// - TODO: whether a connection of a block has different types at the output and input
// - whether a connection of a block has different types at the output and input
getErrorMap = (): {
dataSourceMissing: string[],
algorithmMissing: string[],
......@@ -719,26 +719,29 @@ export class ExperimentEditor extends React.Component<Props, State> {
</FormGroup>
);
// renders the currently selected block to edit, if any
renderBlock = (blockName: string, block: any, isAnalyzer: boolean, key: number) => {
// gets the block info from the tc
const tcBlock = isAnalyzer ? this.props.toolchain.contents.analyzers.find(b => b.name === blockName) : this.props.toolchain.contents.blocks.find(b => b.name === blockName);
// gets the possible algorithms
const algorithms = isAnalyzer ? this.props.analyzerBlocks : this.props.normalBlocks;
/*
if(!tcBlock)
return;
*/
// finds the current algorithm, if any
const alg = algorithms.find(nb => nb.name === block.algorithm) || {contents: {groups: []}};
// gets the input & output info of the current alg
const [ inputs, outputs ] = algIOs(alg);
// calculates the inferred types throughout the experiment
const inferredTypes = this.getConnectionInferredTypes();
const arrCount = (arr: string[]): any => arr.reduce((o, e) => ({...o, [e]: o.hasOwnProperty(e) ? o[e] + 1 : 1}), {});
// filters through the algs based on shape (input/output count) and type inferrence
// to get the list of possible algs for this block
const possibleAlgorithms = algorithms.filter(pa => {
const [iAlg, oAlg] = algIOs(pa);
return isValidEntity(blockName, tcBlock, {inputs: iAlg, outputs: oAlg}, inferredTypes);
});
// func to update the exp's block info
const updateBlock = (newBlock, globals = this.props.data.contents.globals, newName = blockName) => {
if(isAnalyzer)
delete newBlock.outputs;
......@@ -753,6 +756,7 @@ export class ExperimentEditor extends React.Component<Props, State> {
});
};
// get info that could be from the block or from the global settings
const envInfo = block.environment || this.props.data.contents.globals.environment;
const queue = block.queue || this.props.data.contents.globals.queue;
const envDisabled = !block.hasOwnProperty('environment');
......@@ -771,18 +775,6 @@ export class ExperimentEditor extends React.Component<Props, State> {
title={`Block is synchronized to the "${ tcBlock.synchronized_channel }" channel`}
color='info'
>{ tcBlock.synchronized_channel }</Badge>
{/*
{' '}
<Button
color={this.state.lockMap[blockName] ? 'primary' : 'secondary'}
title={`When unlocked, neighboring blocks will not restrict their available algorithms to those compatible with this block's algorithm's input & output types. When locked, neighboring blocks will take into account this block's algorithm's input & output types.`}
onClick={() => {
this.setLockMap(blockName, !this.state.lockMap[blockName] && block.algorithm !== '');
}}
>
{ this.state.lockMap[blockName] ? 'Locked' : 'Unlocked' }
</Button>
*/}
</h4>
<FormGroup row>
<Col sm='2'>
......@@ -848,9 +840,12 @@ export class ExperimentEditor extends React.Component<Props, State> {
valid={block.algorithm !== ''}
value={block.algorithm}
onChange={e => {
// user selected a different algorithm
const str = e.target.value;
// find the alg or use a dummy algorithm instead
const alg = algorithms.find(nb => nb.name === str) || {name: '', contents: {groups: []}};
const [ inputs, outputs ] = algIOs(alg);
// try to map the IOs from the algorithm to the block via names
const findCloseIOMatch = (s: string, arr: string[]): string => {
if(arr.length === 1)
return arr[0];
......@@ -860,15 +855,19 @@ export class ExperimentEditor extends React.Component<Props, State> {
return '';
};
// create the new block obj with the new alg
const thisBlock = {
...block,
algorithm: str,
};
// assign new inputs
if(tcBlock.inputs)
thisBlock.inputs = levMapStrings(Object.keys(inputs), tcBlock.inputs);
// assign new outputs
if(tcBlock.outputs)
thisBlock.outputs = levMapStrings(Object.keys(outputs), tcBlock.outputs);
// setup the parameters (erase & create stuff)
const globals = {
...this.props.data.contents.globals,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment