From f81dbbc35b735b3f7681fdc7fb2c3bc913fca697 Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <jaden.diefenbaugh@idiap.ch> Date: Fri, 27 Jul 2018 10:08:54 -0700 Subject: [PATCH] [js][exp] add some comments --- .../experiment/ExperimentEditor.jsx | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/conda/js/src/components/experiment/ExperimentEditor.jsx b/conda/js/src/components/experiment/ExperimentEditor.jsx index eea6bdea..0d9221b3 100644 --- a/conda/js/src/components/experiment/ExperimentEditor.jsx +++ b/conda/js/src/components/experiment/ExperimentEditor.jsx @@ -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, }; -- GitLab