Define analytics

Create custom analytic functions for window processing that drive advanced analytic use cases

Pre-computed metrics generated by the Metrics Engine can be used within a custom processing component. For example, events could be filtered by user-defined metrics using time intervals, scoring models use metrics as part of the input feature space or build KPIs that combine metrics with event data.

Development steps

API

The below API is provided for developers to implement.

public abstract class AnalyticsFunction<T> {

    protected Logger logger;
    protected Properties parameters;

    public AnalyticsFunction() {
        logger = LoggerFactory.getLogger(this.getClass().getName());
    }

    /**
     * Set function parameters
     *
     * @param parameters
     */
    @JsonProperty(value = "parameters")
    public void setParameters(Properties parameters) {
        this.parameters = parameters;
    }


    /**
     * Referenceable function ID for use in projections and window processing
     *
     * @return name of function as String
     */
    public abstract String getVariablePostFixID();

    /**
     * AnalyticDefinition function to compute
     *
     * @param values to use in the computation
     * @param previousValue computed
     * @param context state                     
     * @return computed result
     */
    public T compute(Number[] values, Number previousValue, Context context) {
        return null;
    }

    /**
     * 
     * @param column raw values to use in the computation
     * @param previousValue computed
     * @param context state
     * @return
     */
    public T compute(NumberColumn column, Number previousValue, Context context) {
        return null;
    }

Development steps

  1. Implement AnalyticsFunction interface

  2. Validate and test

  3. Deploy

  4. Add to a use case DSL

Explaining each step

Step 1: Implement AnalyticsFunction interface

See the Bollinger bands example

Step 2: Build, test and package

The template project provides basic JUnit test to validate DSL. The project will execute these tests during the gradle build cycle and deploy to your local maven repository.

gradle build publishToMavenLocal

Step 3: Deploy

Once your package has been successfully created you are ready to deploy to a Joule project. The resulting jar artefact needs to be placed in to the userlibs directory in your Joule projects directory. See provided examples documentation for further directions.

cp build/libs/<your-connector>.jar <location>/userlibs

Step 4: Add to a use case DSL

Now the jar is created and deployed the use case can use the implementation within the DSL definition file.

Example

processing unit:
  pipeline:
    - filter:
      expression: "symbol == 'CVCO'"
    - sliding window analytics:
        function: com.fractalworks.examples.banking.analytics.BollingerBands
        windowSize: 5
        fields: [ ask ]
        parameters:
          deviations: 2

Last updated