Transform Custom Formula
Overview
The Transform Function in K3 Labs allows users to manipulate and enrich data within workflows. The Custom Formula feature enables users to apply complex mathematical expressions and logical operations on input data, making it a powerful tool for data transformation.
Supported Expressions
The Custom Formula function supports a variety of mathematical operations on floating-point numbers:
Binary Operators
+
(addition)-
(subtraction)*
(multiplication)/
(division)%
(remainder/modulus)^
(power/exponentiation)
Unary Operators
+
(positive sign)-
(negation)
Built-in Functions
The Custom Formula function provides built-in mathematical functions, similar to those found in the Rust standard library:
Basic Functions:
sqrt(x)
: Square rootabs(x)
: Absolute valueexp(x)
: Exponential function (e^x)ln(x)
: Natural logarithm
Trigonometric Functions:
sin(x)
,cos(x)
,tan(x)
: Sine, cosine, and tangentasin(x)
,acos(x)
,atan(x)
,atan2(y, x)
: Inverse trigonometric functionssinh(x)
,cosh(x)
,tanh(x)
: Hyperbolic sine, cosine, and tangentasinh(x)
,acosh(x)
,atanh(x)
: Inverse hyperbolic functions
Rounding Functions:
floor(x)
: Rounds down to the nearest integerceil(x)
: Rounds up to the nearest integerround(x)
: Rounds to the nearest integer
Sign Function:
signum(x)
: Returns -1, 0, or 1 depending on the sign ofx
Other Functions
max(x, ...)
: Returns the maximum value from one or more numbersmin(x, ...)
: Returns the minimum value from one or more numbers
Constants
pi
: Mathematical constant π (3.14159...)e
: Euler's number (2.718...)
Usage
The Custom Formula function can be used within a Transform Function node in the K3 Labs workflow builder. Users can define custom variables and apply formulas directly to input data.
Example 1: Basic Arithmetic
Expression:
Usage:
If
x = 5
andy = 3
, the result will be16
.
Example 2: Using Built-in Functions
Expression:
Usage:
If
a = 3
andb = 4
, the result will be5
(Pythagorean theorem).
Example 3: Conditional Calculation
Expression:
Usage:
If
x = 10
, the result will beln(10) ≈ 2.302
.If
x = -5
, the result will be0
(avoiding logarithm of a negative number).
Example 4: Finding Maximum Value
Expression:
Usage:
If
a = 10
,b = 15
, andc = 7
, the result will be15
.
Integration with K3 Labs Workflows
The Custom Formula function can be used in:
Data Filtering: Modify or filter data before passing it to the next step.
Alert Triggers: Calculate thresholds and trigger alerts based on computed values.
Trading Strategies: Apply mathematical operations on financial data for automated trading.
API Data Processing: Transform API responses before sending them to another service.
Last updated