Skip to main content

IFormulaEngine

Namespace: Meshmakers.Octo.Runtime.Contracts.Formulas

Shared formula engine over the mXparser dialect used across OctoMesh (adapter DataPointMapping expressions, archive computed columns, runtime-query @-expressions). A single implementation wraps OctoExpression; consumers depend on this interface so they need no direct mXparser reference.

public interface IFormulaEngine

Methods

NormalizeTernary(String)

Converts C-style ternary operators (cond ? a : b) to mXparser if(cond, a, b) syntax. A no-op for expressions that contain no ternary.

string NormalizeTernary(string expression)

Parameters

expression String

Returns

String

Validate(String, IReadOnlyDictionary<String, Double>)

Validates an expression by binding the supplied test values to their argument names and checking syntax plus that it evaluates to a finite number. The keys of are the column / variable names the formula is allowed to reference; the values are test bindings (e.g. 42.0 per column, or a caller-supplied preview value). An expression referencing a name not present here fails the syntax check.

FormulaSyntaxResult Validate(string expression, IReadOnlyDictionary<string, double> arguments)

Parameters

expression String

arguments IReadOnlyDictionary<String, Double>

Returns

FormulaSyntaxResult

CheckSyntax(String, IReadOnlyCollection<String>)

Checks an expression's syntax and that every referenced name is in — without evaluating it. Unlike IFormulaEngine.Validate(String, IReadOnlyDictionary<String, Double>) this never fails for a finite-but-undefined-at-probe-values result (e.g. a division that is zero only for the dummy values). Use for schema-time validation where only syntax and reference resolution matter.

FormulaSyntaxResult CheckSyntax(string expression, IReadOnlyCollection<string> argumentNames)

Parameters

expression String

argumentNames IReadOnlyCollection<String>

Returns

FormulaSyntaxResult

EvaluateRaw(String, IReadOnlyDictionary<String, Double>)

Evaluates the expression to a raw Double. Returns Double.NaN on evaluation failure; Double.NegativeInfinity is the engine's null sentinel.

double EvaluateRaw(string expression, IReadOnlyDictionary<string, double> arguments)

Parameters

expression String

arguments IReadOnlyDictionary<String, Double>

Returns

Double

Evaluate(String, IReadOnlyDictionary<String, Double>, FormulaResultType)

Evaluates the expression and casts the Double result back to . Returns null for the null sentinel (Double.NegativeInfinity) or a Double.NaN result.

object Evaluate(string expression, IReadOnlyDictionary<string, double> arguments, FormulaResultType resultType)

Parameters

expression String

arguments IReadOnlyDictionary<String, Double>

resultType FormulaResultType

Returns

Object