Expression
apama.analyticskit.blocks.core.Expression
Evaluates an expression to perform arithmetic or logical calculations or string operations.
On change of input values (once all in-use inputs have been received), the expression specified in the parameter is re-calculated.
The expression language is much like Apama EPL (see the EPL reference in the Apama documentation), but is restricted to float, integer, string and boolean types. All numeric literals are treated as float type values, even if they have no fractional part. Integer values can only be obtained as the result of functions such as floor(). Similar to Apama EPL, integer and float are not implicitly convertible within an expression. If the result of an expression is an integer value, it is converted to a float automatically (there might be a loss of precision). Boolean values can be specified using the Boolean literals true and false. Boolean literals are case insensitive, so for example, TRUE and True are allowed. String values can be specified by enclosing string literals in double quotes, for example "my value". Special characters are encoded with a backslash (\). The following special characters (along which their encoding) are supported in string literals:
Double quotes -
\"Backslash -
\\Newline -
\nTab -
\tThe values of the inputs are available as input1, input2, input3, input4 and input5. The input values can be of type float, string and boolean. Logical, relational, numerical and equality operators can be used on the values of the supported types. Logical operators are case insensitive, so for example, AND and And are allowed. Built-in methods on the float, integer, string and boolean types can be called, including x.abs() (absolute value of x), x.pow(y) (raise x to the power y), x.sin() (sine of x in radians), x.round() (rounds x to the nearest integer), and s.ltrim() (remove whitespace from the start of the string s). Built-in static methods of the supported types can be called by specifying the type name, followed by a dot (.) and the method name, for example, float.max(input1, input2) (find the larger of two input values). Built-in constants on the supported types can be accessed by specifying the type name, followed by a dot (.) and the constant name, for example, float.E (Euler's constant). For a full list of built-in methods and constants, consult the API Reference for EPL (ApamaDoc) which can be accessed from the Apama documentation.
Some examples:
Convert Fahrenheit to Celsius:
(input1 - 32) * 5/9Convert days to seconds:
input1 * 86400Average of 4 inputs:
(input1 + input2 + input3 + input4) / 4Threshold comparison:
input1 > 3.1412 (but also see the Threshold block)
Pythagoras to compute the hypotenuse of a right-angled triangle:
(input1.pow(2) + input2.pow(2)).sqrt()Comparison to 3 decimal places:
(input1 * 1000 - (input1 * 1000).fractionalPart()) = (input2 * 1000 - (input2 * 1000).fractionalPart())Range check:
input1 >= 1 and input1 <= 10String comparison:
input1 = "my value"Larger value:
float.max(input1, float.PI)Remainder of integer division:
input1.round() % input2.round()Parameters
Name | Description | Type | Notes |
Expression | An expression - a string representation of an EPL expression. Similar to EPL expressions, but with the differences as described above. | string | |
Input Port Details
Name | Description | Type |
input1 | First input, to be used as input1 in the expression. | any |
input2 | Second input, to be used as input2 in the expression. | any |
input3 | Third input, to be used as input3 in the expression. | any |
input4 | Fourth input, to be used as input4 in the expression. | any |
input5 | Fifth input, to be used as input5 in the expression. | any |
Output Port Details
Name | Description | Type |
Result | Result of the expression. | any |