Derived metrics can be used to compute new values by using an expression based on the value of other metrics. The expression can be used to compute a numeric, a boolean or a string value.
Creating a Derived metric
To add a new Derived metric to a Thing Definition, you should:
- Enter the Computed Data page.
- Select the Thing Definitions tab.
- Select the Thing Definition to edit.
- Press the Add Metric button.
- Select the Derived type and provide the required information.
- Press the Save button and edit the additional information, if needed.
Editing a Derived metric
In the main configuration panel, it is possible to select one or more metrics or properties to use within the expression.
Once the metrics/properties have been selected, it is possible to configure the derivation expression.
Pressing the Add Condition button, it is possible to add multiple result conditions to implement the IF, ELSE, OTHERWISE pattern.
Null Result
- IF metric1 > 100 -> left the result empty to do nothing
- ELSE RETURN (metric1 + metric2) -> save new value
Expressions
The expression language used to define Derived Metric expressions is based on the following operators.
OPERATOR |
NOTATION |
SAMPLE |
---|---|---|
Mathematical |
+ - * / % ^ |
(x + y^2)/4 |
Logical |
or and true/false |
x==y && (b==true || b==c) |
Relational |
= != < ⇐ > > |
a != b |
Elvis |
Ternary operator |
condition ? foo : bar |
MATHEMATICAL |
DESCRIPTION |
SAMPLE |
---|---|---|
cos |
Returns the trigonometric cosine of an angle, in radians. |
#cos(x) |
sen |
Returns the trigonometric sine of an angle, in radians. |
#sen(x) |
abs |
Returns the absolute value of a numeric value. |
#abs(x) |
sqrt |
Returns the rounded positive square root of a numeric value. |
#sqrt(x) |
pi |
The PI value (3.14159…). |
#pi |
ceil |
Returns the smallest integer value greater than or equal to the float argument. |
#ceil(x) |
floor |
Returns the largest integer value that is less than or equal to the float argument. |
#floor(x) |
log |
Returns the natural logarithm (base e) of the argument. |
#log(x) |
log10 |
Returns the base 10 logarithm of the argument. |
#log(x) |
max |
Returns the greater of two values. |
#max(x, y) |
min |
Returns the smallest of two values. |
#min(x, y) |
pow |
Returns the value of the first argument raised to the power of the second argument. |
#pow(x, exp) |
CONVERSION |
DESCRIPTION |
SAMPLE |
parseInt |
Converts the string argument to integer using the given radix (optional). |
#parseInt('12') or #parseInt('BF123', 16) |
intToString |
Converts an integer to string using a radix. |
#intToString(x, 16) |
parseFloat |
Converts the string argument to float using the given radix (optional). |
#parseFloat('12') or #parseFloat('BF123', 16) |
floatToString |
Converts a float to string using a radix. |
#floatToString(x, 16) |
toString |
Converts the source value to string. |
var.#toString() |
STRING |
DESCRIPTION |
SAMPLE |
substring |
Returns a substring considering the start (inclusive) and end (exclusive) zero based indexes. |
str.#substring(startIndex) or str.#substring(startIndex, endIndex) |
length |
Returns the length of the string. |
str.#length() |
charAt |
Returns the character at the specified index. |
str.#charAt(index) |
indexOf |
Returns the index (zero-based) of the first occurrence of the argument string. |
str.#indexOf('foo') |
lastIndexOf |
Returns the index (zero-based) of the last occurrence of the argument string. |
str.#lastIndexOf('foo') |
split |
Returns the arrays of tokens splitting by the argument string. |
str.#split(',') |
upperCase |
Converts the source string to upper-case. |
str.#toUpperCase() |
lowerCase |
Converts the source string to lower case. |
str.#toLowerCase() |
Comments
0 comments
Please sign in to leave a comment.