Expression Library and Expression Editor |
Content |
||||||||||||||
|
Overview |
|
|
LabVantage provides two tools to assist in generating expressions used for arithmetic data manipulation and evaluation in Calculations: the Expression Library and the Expression Editor.
|
At a minimum, you should be familiar with these concepts and the related LabVantage features described therein:
• | Concepts of Parameters and Parameter Lists |
• | Concepts of Parameter Limits |
• | Concepts of Specifications |
• | Concepts of Transformations and Calculations |
Expression Library |
|
|
The Expression Library (System Admin → Configuration → Expressions) lets you define Groovy and Java expressions that can be reused in the Expression Editor.
Example Expression in the Expression Library
![]() |
Field | Description | ||||||
ExpressionId | Identifier of the Expression SDI. | ||||||
Description | Text description of the Expression displayed on the Expression List page. | ||||||
Type | Specifies how the expression is implemented:
|
||||||
Namespace
Method |
"Namespace" defines the object on which the
"Method" is called:
|
||||||
Implementation |
Defines the code required to define and execute the expression:
|
Button | Description |
Verify Expression | Conducts a code syntax and structure check, then returns any errors detected in the expression. |
These example expressions (called on the LV object) are currently provided OOB:
Expression | Description | ||||||||
Average | Returns an average with a <
or > operator depending on the entered value. For example:
|
||||||||
DateOffsetInDays | Calculates the date by adding or subtracting an offset in days. | ||||||||
DaysBetween | Calculates the number of days between two dates. | ||||||||
Difference | Returns the absolute value of the algebraic difference between two integers. | ||||||||
HourMinsBetween | Calculates the difference (in hours:minutes) between two date times. | ||||||||
HoursBetween | Calculates the difference (in hours) between two date times. | ||||||||
UnitConv* | General purpose Unit conversion expressions. | ||||||||
UOM* | See Parameter Lists → Description → Uncertainty → Uncertainty Calculations. |
Expression Editor |
|
|
Description |
The Expression Editor provides an interface to build expressions. It is accessed at these locations:
• | "Calculation Rule" field in the Reference detail of the Parameter List Maintenance page. |
• | "Transformation Rule" field in the Display detail of the Parameter List Maintenance page. |
• | "Transformation Rule" field in the Parameter Details detail of the Specification Maintenance page. |
![]() |
Field | Description | ||||
Expression Type | Determines the syntax rules used to write the expression.
"Internal" refers to LabVantage syntax. "Groovy" refers
to syntax used by Apache Groovy.
|
||||
Expression | Arithmetic expression for evaluation. | ||||
Expression Library | Predefined expressions from the Expression Library (if
using Groovy) or the LabVantage Aggregate Library (if using LabVantage).
Set the cursor where in the Expression area where you want to insert the
expression, then click the expression (Groovy example shown):
|
||||
Parameters | Parameters used in the expression. Replace the variable
in the Expression area with the desired Parameter (Groovy example shown):
For assistance with specifying Parameters and Parameter Lists, use the Expression Helpers. |
||||
Test | Tests the expression. Enter test values for the expression,
then choose the "Data Type" (Numeric, Text, or Date). Clicking
"Test" executes the test (Groovy example shown):
As described in Referencing Data Items by an SDIDataItem Column, you can use the (all) syntax for Groovy expressions to return a map of an entire SDIDataItem record. However, the Expression Editor does not have the capability to return actual values from an SDIDataItem record. Accordingly, it cannot interpret actual values when using the "Test" function for expressions that use the (all) syntax to return a map of an entire SDIDataItem record. The message shown below will be returned.
|
Expression Helpers |
Expression Helpers assist with specifying Parameters (Param Helper), Parameter Lists (ParamList Helper), Primary SDIs (Primary Helper) and Reference Calculations (Cross SDI Helper). Functionality is identical for LabVantage and Groovy expressions (syntax is automatically adjusted for each). Selections are displayed in a cascading fashion, providing the subsequent column based on your selection. As you choose each item, the expression is updated at the top of the page.
|
|
|
||||||||||||||||||
The Parameter dropdown lets you select any Parameter associated
with the current Parameter List.
Selecting a Parameter prompts for a Parameter Type. Choose from the list of values for the current Parameter List, or choose a wildcard. You can then select a Replicate. Specify the Replicate number, or choose a wildcard or max value. For examples demonstrating syntax and usage, see these areas of Referencing Data Items by an SDIDataItem Column:
|
The Parameter List Helper functionality is similar to the Parameter Helper (offering successive choice of Parameter List, Version, Variant and Data Set). For examples demonstrating syntax and usage, see these areas of Referencing Data Sets by an SDIData Column:
The Param tab functionality is the same as in the Parameter Helper. |
The Primary Helper lets you choose the current SDI and SDI column or SDI Attribute. |
Cross SDI Helper |
The Cross SDI Helper handles Reference Calculations.
Begin by selecting the Source SDC (this is the SDC associated with the Parameter List). Then, select options for any of the Reference Calculation scenarios described below (follow the links for conceptual examples). As you choose each option, LabVantage provides an textual explanation of what you have chosen. ParamList and Param tab behavior is identical to that of the Parameter List Helper.
NOTE: | The "Primary" tab in the Cross
SDI Helper lets you choose SDCs that allow Attributes along with SDCs that
allow Data Entry. The Primary tab in other Helpers shows only SDCs that
allow Data Entry.
If an SDC that does not allow Data Entry is selected, the ParamList and Param tabs prevent selecting a Data Set or Data Item with the selected link. |
Option | Scenario and Link to Example | Choose... |
Absolute | Explicit Reference to a Single SDI | SDC and SDI. |
Foreign Key | Foreign Key Reference to a Single SDI |
Column that contains the link.
The dropdown shows foreign key links from SDIWorkitem, SDIData, and SDIDataItem to the primary SDC that allows Data Entry and Attributes. When a foreign key link is selected, the linked SDC is automatically selected in the Primary tab and its columns and Attributes (if any) are shown in the dropdown. |
Reverse FK | Reverse Foreign Key Link |
SDC and its column.
When a reverse foreign key link is selected, the linked SDC is automatically selected in the Primary tab and its columns and Attributes (if any) are shown in the dropdown. |
SDIRelation | SDI Relation | Relation Type. Multiple Relation Types can be specified. |
SDIDataRelation | SDI Data Relation | Relation Type. Multiple Relation Types can be specified. |
Array | Array Calculation | See Master Data Setup → Array Methods → Adding a New Array Method → Parameters → Calculation Rule. |
Sample Parent/Child Relation | Sample Parent/Child Relation | Relationship between Parent and Child Sample. |
AQC | Using Calculations with QC Samples (AQC) | QC Sample, Position, and Level. |
Absolute | Foreign Key | Reverse FK | ||
![]() |
![]() |
![]() |
||
SDIRelation | SDIDataRelation | Array | ||
![]() |
![]() |
![]() |
||
Sample Parent/Child Relation | ||||
![]() |
LabVantage Aggregate Expressions |
This is the library of predefined expressions available for use in the Expression Editor. All are in LabVantage expression syntax.
|
|
Function | Description |
abs( [x] ) | Calculates the absolute value of x. |
astmround( [x], n ) | Rounds according to ASTM E29-02 rounding rules (see Note 1). |
avg( [x] ) | Calculates the average of x, where x represents multiple values. Example: If x = 119 246 322, this returns 229. |
case( [x] when [a] then [b] when [c] then [d]... else [e]) | Standard case statement. Compares
the value of x against other values (a, b, c, d, ..., n), then returns e
if no match is found. |
ceiling( [x] ) | Determines the smallest whole number that is greater than or equal to x. |
clpinorgsigfig( [x], n ) | Rounds a number x to n significant figures according to USEPA rounding rules for inorganics analysis (see Note 2). |
clporgsigfig( [x], n ) | Rounds a number x to n significant figures according to USEPA rounding rules for organics analysis (see Note 2). |
cos( [x] ) | Calculates the cosine of x (where x is in radians). |
count( [x] ) | Determines the number of rows specified by the argument. |
exp( [x] ) | Raises e to the power x, where e is the base of natural logarithms. |
fact( [x] ) | Calculates the factorial of x. |
first( [x] ) | Returns the first value of x, where x represents multiple values. Example: If x = 7 9 11, this returns 7. |
if( [b], [t], [f] ) | Evaluates the condition where:
b is a boolean expression that evaluates to True or
False. See Note 3. |
int( [x] ) | Determines the largest whole number less than or equal to x. |
isnull([x]) | Reports whether or not the value of x is Null. Returns True if Null and False if not. |
last( [x] ) | Returns the last value of x, where x represents multiple values. Example: If x = 7 9 11, this returns 11. |
log( [x] ) | Calculates the natural logarithm of x. |
logten ( [x] ) | Calculates the base 10 logarithm of x. |
max( [x] ) | Returns the largest value of x, where x represents multiple values. Example: If x = 2 17 9, this returns 17. |
maxsigfigdp( [x], n ) | Rounds a number x to both n significant figures and n decimal places (see Note 2). |
min( [x] ) | Returns the smallest value of x, where x represents multiple values. Example: If x = 17 2 9, this returns 2. |
mod( [x], n ) | Calculates the remainder (modulus) of a division operation, where x is the numerator. |
pi( [x] ) | Calculates the product of p and x. |
rand( [x] ) | Obtains a random whole number between 1 and the upper limit specified by x. The lower limit is always 1. The upper limit is 32,767. |
round( [x], n ) | Rounds a number x to the specified number n of decimal places (see Note 4). |
sigfig([x], n ) | Rounds a number x to n significant figures (see Note 2). |
sign( [x] ) | Reports if x is negative, zero, or
positive. |
sin( [x] ) | Calculates the sine of x (where x is in radians). |
sqrt( [x] ) | Calculates the square root of x. |
stdev( [x] ) | Returns the standard deviation of x. |
sum( [x] ) | Returns the sum of x, where x represents multiple values. Example: If x = 10 100 1000, this returns 1110. |
tan( [x] ) | Calculates the tangent of x (where x is in radians). |
truncate( [x], n ) | Truncates a number x to the specified number n of decimal places. |
var( [x] ) | Calculates an estimate of the variance for the specified column. The variance is the square of the standard deviation. |
NOTES |
|
astmround( [x], n ) This function rounds a value to a specified number of decimal places. The rounding method is defined in ASTM Designation E29-02 "Standard Practice for Using Significant Digits in Test Data to Determine Conformance with Specifications", paragraph 6 "Rounding Methods". Note that although the term "Significant Digits" appears in the title of the ASTM Designation, only the decimal-based rounding methods in paragraph 6 apply. Example: astmround([this], 2) rounds to 2 decimal places according to the rules demonstrated in the following examples:
|
|||||||||||||||||||||||||||||||||||||||
|
sigfig( [x], n ) These basic rules apply to sigfig( [x], n ):
When rounding to the least significant digit, sigfig( [x], n ) uses basic rounding when looking at the first non-significant digit, with optional increment of the least significant digit. For example:
clpinorgsigfig( [x], n ) Rounding rules for clpinorgsigfig( [x], n ) differ from sigfig( [x], n ) when the first non-significant digit is equal to 5. For example:
clporgsigfig( [x], n ) Rounding rules for clporgsigfig( [x], n ) differ from clpinorgsigfig( [x], n ) in that the odd/even rule is used even when there are non-zero digits to the right of the 5. For example, when the first non-significant digit is equal to 5:
maxsigfigdp( [x], n ) This uses the same rounding rules as sigfig( [x], n ). However, maxsigfigdp( [x], n ) always limits the number of decimal places to n, even if n significant figures cannot be displayed in n decimal places. For example:
|
|||||||||||||||||||||||||||||||||||||||
|
if( [b], [t], [f] ) When evaluating an if(b, t, f) function that contains null values, the value returned depends on the "Honor Null in Relational Expressions" and "Honor Null in AND/OR Conditional Expressions" properties of the Data Entry Policy. |
|||||||||||||||||||||||||||||||||||||||
|
round( [x], n ) In general, this is intended to be a conventional rounding function, i.e., rounding 1.2345 to 2 decimal places results in a returned numeric value of 1.23. However, rounding an integer expressed as a decimal (such as 4.00) returns only the integer. For example, rounding 4.00 to 2 decimal places actually calculates and returns 4. This is because Transformation and Calculation expressions return a numeric value, and in this case, 4 and 4.00 have the same numeric value. In order to render the return as 4.00 in the interface, the "Display Format" must be set to render 4.00 (see Parameter Lists → Description → Display), as the Display Format determines the result that is actually displayed. Be advised that rounding the numeric result affects downstream Calculations and Limit evaluations. As such, it is usually a better option to round using the Display Format. |