eval node
This commit is contained in:
80
src/nodes/Eval.ts
Normal file
80
src/nodes/Eval.ts
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import Node from './Node';
|
||||||
|
import {
|
||||||
|
NumberVar,
|
||||||
|
StringVar,
|
||||||
|
} from './io/AbstractIOSet';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
|
||||||
|
const inputs = {
|
||||||
|
i0: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i1: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i2: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i3: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i4: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i5: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i6: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
i7: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 0,
|
||||||
|
} as NumberVar,
|
||||||
|
formula: {
|
||||||
|
type: 'String',
|
||||||
|
default: '',
|
||||||
|
} as StringVar
|
||||||
|
};
|
||||||
|
|
||||||
|
const outputs = {
|
||||||
|
result: {
|
||||||
|
type: 'Number'
|
||||||
|
} as NumberVar,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class NumberBinaryOperation extends Node<typeof inputs, typeof outputs> {
|
||||||
|
constructor() {
|
||||||
|
super('Eval', inputs, outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
interpolate() {
|
||||||
|
return this.in.formula.value.replace(/\{(\w+)\}/g, (_, paramName) => {
|
||||||
|
const value = get(this.in, [paramName, 'value']);
|
||||||
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate() {
|
||||||
|
try {
|
||||||
|
this.out.result.value = eval(this.interpolate());
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _update() {
|
||||||
|
return this.evaluate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,3 +29,4 @@ export {default as Disable} from './Disable';
|
|||||||
export {default as Api} from './Api';
|
export {default as Api} from './Api';
|
||||||
export {default as BodySegmentation} from './AI/BodySegmentation';
|
export {default as BodySegmentation} from './AI/BodySegmentation';
|
||||||
export {default as FaceFeaturePosition} from './AI/FaceFeaturePosition';
|
export {default as FaceFeaturePosition} from './AI/FaceFeaturePosition';
|
||||||
|
export {default as Eval} from './Eval';
|
||||||
|
|||||||
Reference in New Issue
Block a user