User defined analytics
Declarative stateful math expressions evaluated in real-time
Last updated
Declarative stateful math expressions evaluated in real-time
Last updated
The analytics processor provides a rich set of features that enable developers to define and execute analytics. This feature is idea for executing an event based analytic expression using attributes present within the event, linked reference data and passed variables.
Currently only Javascript and Python are supported
The key analytic processor objective is to provide analytic deployment flexibility for the developer. The ambition is to enable a quick test, learn and refine cycle that reduces time to production deployment.
This section covers methods for executing expressions in stream processing, focusing on three key approaches:
Expression only Execute independent event-based calculations using simple mathematical formulas by defining core attributes.
Expression and state Incorporate constants and manage state to initialise calculations and update them with new data.
Expression and script Leverage pre-existing scripts alongside expressions for more complex calculations.
See User Defined Scripts documentation for script based execution models.
When you only want to execute an expression that can be defined as a mathematical formula use this method to execute independent event based calculations provide the expression along with the required core attributes.
This example demonstrates how you would use provided constants for a calculation. This same method can be used to prime a calculation with a starting value for the initial calculation and then being it replaced with updated values by using the same assign to
variable.
See Stateful variables for further documentation.
Use this option when you have pre-existing scripts which you want to leverage within a stream processing context.
Javascript function
The example will apply the bid
and ask
event attributes to the expression.
Note the current implementation requires the script to be provided using the js
extension due to the way the expression is defined.
Variables are provided as a map of key and numerical values.
Variables and the event are passed in to the execution context per event, including stateful variables. This example demonstrates how to apply a constant as a scaling factor for a calculation.
Stateful variables provide a key function whereby the previous value(s) can be used within the current calculation context.
The example primes the first calculation with a starting value for the initial calculation and thereafter replaced with the computed values from the stateful memory. This is achieved using the same assign to
variable set within the variables
section.
The follow attributes are used for expression and scripting.
Attribute | Description | Data Type | Required |
---|---|---|---|
language | Language runtime to use to execute required execution definitions. Currently Javascript (js) and Python (python) are supported | String Default: js | |
assign to | Assignment variable for the evaluated expression result | String Default: result | |
variables | Map of constants and seed values for the expression to use. This is an optional variable. | Map<String, Number> | |
stateful | Store previous computed values for next computation cycle | See stateful section | |
assignment datatype | Data type to cast too for the assignment variable. See scripting supported data types section | DataType Default: Double |
These attributes define what is need to execute analytical functions over a stream events.
Attribute | Description | Data Type |
---|---|---|
expression | Math expression without an assignment variable. Required if method has not been provided. | String |
script | Path of the script to loaded within the Joule processing context | String |
Store previous computed values for next computation cycle. Honours the groupby definition. The previous computed value can be used on the next calculation.
Attribute | Description | Data Type | Required |
---|---|---|---|
assign to | Assignment variable for the result | String | |
memory capacity | Number of rolling elements to store within a FIFO array | Integer Default: 10 | |
attach memory | Attach a copy of the array contents to the computed event | Boolean Default: false |