# Scripting

## Objective

Joule core provides the ability to deploy declarative expressions using the custom analytics processor.

This has been reused within the context of feature engineering to enable users to define custom calculations within the DSL.

## Example & DSL attributes

The example demonstrates per-event calculation of a `spend_ratio` using a JavaScript-based expression, where users can define variables, such as `avg_spend` to customise the calculation.

### Example

```yaml
feature engineering:
  ...
  features:
    compute:
      spend_ratio:
        scripting:
          macro:
            expression: 1 - spend/avg_spend
            variables:
              avg_spend: 133.78
```

### Attributes schema

<table><thead><tr><th width="155">Attribute</th><th width="358">Description</th><th width="133">Data Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>expression</td><td>A valid mathematical expression</td><td>String</td><td>true</td></tr><tr><td>language</td><td>List of supported feature functions</td><td><p>String</p><p>Default: js</p></td><td>false</td></tr><tr><td>variables</td><td>Map of variables to be used during the execution of the expression. </td><td>Map</td><td>false</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fractalworks.io/joule/components/analytics/ml-inferencing/feature-engineering/scripting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
