Expression Syntax for Calculated Quantities

Expressions can be combined using operators. Each operator has a precedence priority, as follows:

Primary > unary > power > multiplicative> additive > relational > logical

Primary

(, )

 

values

Values include:

  • integers
  • floating point numbers
  • scientific notation
  • dates/times
  • Booleans
  • strings
  • functions
  • parameters

Example:

2 * ( 3 + 2 )

Integers

They are represented using numbers and are evaluated as Int32.

Example:

123456

Floating point numbers

Use the dot to define the decimal part. They are evaluated as Decimal.

Examples:

123.456
.123

Scientific notation

You can use the e to define power of ten (10^). These are evaluated as Double.

Examples:

1.22e1
1e2
1e+2
1e-2
.1e-2
1e10

Dates and Times

Must be enclosed between sharps. These are evaluated as DateTime. and uses the current Culture to evaluate them.

Example:

#2008/01/31# // for en-US culture

Booleans

Booleans can be either true or false.

Example:

true

Strings

Any character between single quotes "'" are evaluated as String.

Example:

'hello'

You can escape special characters using: \\, \', \n, \r, \t

Functions

A function is made of a name followed by braces, containing optionally any value as arguments.

Example:

Abs(1), doSomething(1, 'dummy')

The following functions are available:

Name

Description

Usage

Result

Abs

Returns the absolute value of a specified number.

Abs(-1)

1M

Acos

Returns the angle whose cosine is the specified number.

Acos(1)

0d

Asin

Returns the angle whose sine is the specified number.

Asin(0)

0d

Atan

Returns the angle whose tangent is the specified number.

Atan(0)

0d

Ceiling

Returns the smallest integer greater than or equal to the specified number.

Ceiling(1.5)

2d

Cos

Returns the cosine of the specified angle.

Cos(0)

1d

Exp

Returns e raised to the specified power.

Exp(0)

1d

Floor

Returns the largest integer less than or equal to the specified number.

Floor(1.5)

1d

IEEERemainder

Returns the remainder resulting from the division of a specified number by another specified number.

IEEERemainder(3, 2)

-1d

Log

Returns the logarithm of a specified number.

Log(1, 10)

0d

Log10

Returns the base 10 logarithm of a specified number.

Log10(1)

0d

Max

Returns the larger of two specified numbers.

Max(1, 2)

2

Min

Returns the smaller of two numbers.

Min(1, 2)

1

Pow

Returns a specified number raised to the specified power.

Pow(3, 2)

9d

Round

Rounds a value to the nearest integer or specified number of decimal places. The mid number behaviour can be changed by using EvaluateOption.RoundAwayFromZero during construction of the Expression object.

Round(3.222, 2)

3.22d

Sign

Returns a value indicating the sign of a number.

Sign(-10)

-1

Sin

Returns the sine of the specified angle.

Sin(0)

0d

Sqrt

Returns the square root of a specified number.

Sqrt(4)

2d

Tan

Returns the tangent of the specified angle.

Tan(0)

0d

Truncate

Calculates the integral part of a number.

Truncate(1.7)

1

The following general purpose functions are also available:

Name

Description

Usage

Result

in

Returns whether an element is in a set of values.

in(1 + 1, 1, 2, 3)

true

if

Returns a value based on a condition.

if(3 % 2 = 1, 'value is true', 'value is false')

'value is true'

Parameters

A parameter as a name and can be optionally contained inside brackets.

Example:

2 + x, 2 + [x]

Static parameters

Static parameters are values which can be defined before the evaluation of an expression. These parameters can be accessed using the Parameters dictionary of the Expression instance.

Expression e = new Expression("2 * [x] ^ 2 + 5 * [y]");
e.Parameters["x"] = 5;
e.Parameters["y"] = 1;
Console.WriteLine(e.Evaluate());

Parameters can be useful when a value is unknown at compile time, or when performance is important and the parsing can be saved for further calculations.

Expression parameters

Expressions can be split into several ones by defining expression parameters. Those parameters are not simple values but Expression instances themselves.

Expression volume = new Expression("[surface] * h");
Expression surface = new Expression("[l] * [L]");
volume.Parameters["surface"] = surface;
surface.Parameters["l"] = 1;
surface.Parameters["L"] = 2;

Dynamic parameters

Sometimes parameters can be even more complex to evaluate and need a dedicated method to be evaluated. This can be done by intercepting there evaluation using the EvaluateParameter event published on Expression instances. Thus, each time a parameter is not defined in the dictionary, this event is called to try to resolve the value.

Expression e = new Expression("Round(Pow([Pi], 2) + Pow([Pi], 2) + [X], 2)");
e.Parameters["Pi2"] = new Expression("Pi * [Pi]");
e.Parameters["X"] = 10;
e.EvaluateParameter += delegate(string name, ParameterArgs args)
{
if (name == "Pi")
args.Result = 3.14;
};

Square brackets parameters

Parameters in between square brackets can contain special characters like spaces, dots, and also start with digits.

Expression e = new Expression("[My First Parameter] + [My Second Parameter]");

Multi-valued parameters

When parameters are IEnumerable and the EvaluationOptions.IterateParameters is used, the result is an IList made of the evaluation of each value in the parameter.

Expression e = new Expression("(a * b) ^ c", EvaluateOption.IterateParameters);
e.Parameters["a"] = new int[] { 1, 2, 3, 4, 5 };
e.Parameters["b"] = new int[] { 6, 7, 8, 9, 0 };
e.Parameters["c"] = 3;
foreach (var result in (IList)e.Evaluate())
{
Console.WriteLine(result);
}
// 216
// 2744
// 13824
// 46656
// 0

Unary

!, not, -, ~ (bitwise not)

Example:

not true

Bitwise

& (bitwise and), | (bitwise or), ^(bitwise xor), << (left shift), >>(right shift)

Example:

2 >> 3

Multiplicative

*, /, %

Example:

1 * 2 % 3

Additive

+, -

Example:

1 + 2 - 3

Relational

=, ==, !=, <>

<, <=, >, >=

Example:

1 < 2

Logical

These operators can perform a logical comparison between other expressions.

or, ||

and, &&

The and operator has higher priority than the or, thus in the following example, false and true is evaluated first.

Example:

true or false and true

Glossary

Area Equipment

Equipment, typically belonging to a plant or facility, that may affect loss at upstream measurement points.

Availability Event

A quantifiable time frame when a measurement point is not working or not working to an appropriate proportion of design capacity. Availability events can be a pre-cursor to loss events. Availability of a measurement point is an opportunity.

Cause

A predefined list of states or activities relating to a piece of equipment attributed to production event.

Downtime

A state where production has stopped over a period of time.

Equipment Hierarchy

A collection of equipment (grouped in a hierarchy) which summarises the equipment of interest for loss and downtime reporting.

Loss

A state where production is below a specified threshold but has not stopped over a period of time.

Loss Event

Loss is the incomplete utilisation of a piece of equipment, or a lost opportunity for production. While it may be possible to assign an actual cost of amount, the base Unit for loss is time.

Measurement Point Group

A mechanism for grouping measurement points into convenient geographical groups for reporting purposes.

Production Stream

A Production Stream provides a convenient way of grouping equipment for reporting purposes. A piece of equipment can belong to only one Production Stream.

Reason

A predefined list of states or activities relating to a piece of equipment attributed to production event.

Workflow

A set of activities that describe real world processes.

 

Comments are closed