Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public toExpression(expression: Expression, name: string, nestingLevel: number): ApplyExpression {
const relativeNesting = this.relativeNesting(nestingLevel);
const formulaName = `__formula_${name}`;
if (relativeNesting < 0) throw new Error(`wrong nesting level: ${relativeNesting}`);
return new ApplyExpression({
name,
operand: new ApplyExpression({ expression, name: formulaName }),
expression: $(formulaName).divide($(formulaName, relativeNesting)).fallback(0)
});
}
toExpression(expression: Expression, name: string, _nestingLevel: number): ApplyExpression {
return new ApplyExpression({
name,
expression: this.calculate(expression)
});
}
}
protected applyExpression(quantileExpression: PlywoodExpression, name: string, nestingLevel: number): ApplyExpression {
if (!(quantileExpression instanceof QuantileExpression)) throw new Error(`Expected QuantileExpression, got ${quantileExpression}`);
const expression = new QuantileExpression({ ...quantileExpression.valueOf(), value: this.definition.percentile / 100 });
return new ApplyExpression({ name, expression });
}
}
protected applyExpression(expression: Expression, name: string, nestingLevel: number): ApplyExpression {
return new ApplyExpression({ expression, name });
}
}
public toExpression(expression: Expression, name: string, nestingLevel: number): ApplyExpression {
const relativeNesting = this.relativeNesting(nestingLevel);
const formulaName = `__formula_${name}`;
if (relativeNesting < 0) throw new Error(`wrong nesting level: ${relativeNesting}`);
return new ApplyExpression({
name,
operand: new ApplyExpression({ expression, name: formulaName }),
expression: $(formulaName).divide($(formulaName, relativeNesting)).fallback(0)
});
}