Link Search Menu Expand Document

Filter and transform

You can let the OOCSI server do some computing work for you and this works on ALL platforms that OOCSI supports: by subscribing from a client to a channel with additional filter and/or transform expressions, you can control which messages will be received on the client (“filter”) and/or you can compute new values based on the message contents (“transform”).

Let’s start with the filter example. We use the Processing OOCSI client, but any other platform should be fine. We subscribe to a channel “testchannel” and this is a built-in channel in the OOCSI system that delivers a steady stream of messages automatically.

    // subscribe to receive ALL messages
    oocsi.subscribe("testchannel", "handleMessages");

Now we want to filter this stream and only receive messages in which the position value is larger than 100:

    // subscribe with filter to only receive messages that match the filter expression
    oocsi.subscribe("testchannel[filter(position > 100)]", "handleMessages");

We can also create more complex filter expressions, such as:

    // subscribe and filter messages with position value > 100 and color value < 100
    oocsi.subscribe("testchannel[filter(position > 100 && color < 100)]", "handleMessages");

For the transform, it’s not much different. You can use expressions similar to filtering, but this time for computing new values that are assigned to existing or new attributes in the transformed message. This is an example:

    // subscribe and transform messages with new value position_sq
    oocsi.subscribe("testchannel[transform(position_sq, position * position)]", "handleMessages");

The first parameter of transform is the message value that the computed result will be assigned to. This can be a new value (see above) or an existing value that is simply replaced.

You can also combine filter and transform in a single expression as well as multiple filter and transform expressions. They just need to be separated by semicolon ‘;’:

    // subscribe and transform messages with new value position_sq
    oocsi.subscribe("testchannel[filter(position<100);transform(position_sq, position * position)]", "handleMessages");

Expressions

Supported Operators

Mathematical Operators
OperatorDescription
+Additive operator / Unary plus
-Subtraction operator / Unary minus
*Multiplication operator, can be omitted in front of an open bracket
/Division operator
%Remainder operator (Modulo)
^Power operator
Boolean Operators*
OperatorDescription
=Equals
==Equals
!=Not equals
<>Not equals
<Less than
<=Less than or equal to
>Greater than
>=Greater than or equal to
&&Boolean and
||Boolean or

*Boolean operators result always in a BigDecimal value of 1 or 0 (zero). Any non-zero value is treated as a true value. Boolean not is implemented by a function.

Supported Functions

Function*Description
NOT(expression)Boolean negation, 1 (means true) if the expression is not zero
IF(condition,value_if_true,value_if_false)Returns one value if the condition evaluates to true or the other if it evaluates to false
RANDOM()Produces a random number between 0 and 1
MIN(e1,e2, ...)Returns the smallest of the given expressions
MAX(e1,e2, ...)Returns the biggest of the given expressions
ABS(expression)Returns the absolute (non-negative) value of the expression
ROUND(expression,precision)Rounds a value to a certain number of digits, uses the current rounding mode
FLOOR(expression)Rounds the value down to the nearest integer
CEILING(expression)Rounds the value up to the nearest integer
LOG(expression)Returns the natural logarithm (base e) of an expression
LOG10(expression)Returns the common logarithm (base 10) of an expression
SQRT(expression)Returns the square root of an expression
SIN(expression)Returns the trigonometric sine of an angle (in degrees)
COS(expression)Returns the trigonometric cosine of an angle (in degrees)
TAN(expression)Returns the trigonometric tangens of an angle (in degrees)
COT(expression)Returns the trigonometric cotangens of an angle (in degrees)
ASIN(expression)Returns the angle of asin (in degrees)
ACOS(expression)Returns the angle of acos (in degrees)
ATAN(expression)Returns the angle of atan (in degrees)
ACOT(expression)Returns the angle of acot (in degrees)
ATAN2(y,x)Returns the angle of atan2 (in degrees)
SINH(expression)Returns the hyperbolic sine of a value
COSH(expression)Returns the hyperbolic cosine of a value
TANH(expression)Returns the hyperbolic tangens of a value
COTH(expression)Returns the hyperbolic cotangens of a value
SEC(expression)Returns the secant (in degrees)
CSC(expression)Returns the cosecant (in degrees)
SECH(expression)Returns the hyperbolic secant (in degrees)
CSCH(expression)Returns the hyperbolic cosecant (in degrees)
ASINH(expression)Returns the angle of hyperbolic sine (in degrees)
ACOSH(expression)Returns the angle of hyperbolic cosine (in degrees)
ATANH(expression)Returns the angle of hyperbolic tangens of a value
RAD(expression)Converts an angle measured in degrees to an approximately equivalent angle measured in radians
DEG(expression)Converts an angle measured in radians to an approximately equivalent angle measured in degrees
FACT(expression)Retuns the factorial value of an integer. Will return 1 for 0 or a negative number

*Functions names are case insensitive.

Supported Constants

ConstantDescription
eThe value of e, exact to 70 digits
PIThe value of PI, exact to 100 digits
TRUEThe value one
FALSEThe value zero
NULLThe null value

OOCSI-specific functions

Function*Description
STDEV(expression,n)The standard deviation value of the expression computed over the last n (<= 50) events.
MEAN(expression,n)The mean value of the expression computed over the last n (<= 50) events.
SUM(expression,n)The sum of the expression computed over the last n (<= 50) events.
MIN(expression,n)The minimum of the expression computed over the last n (<= 50) events.
MAX(expression,n)The maximum of the expression computed over the last n (<= 50) events.

*Functions names are case insensitive.

Credits

All expressions are evaluated with the EvalEx library. Therefore, the expressions overview above is directly copied from the EvalEx documentation.


Copyright © 2013-2024 Mathias Funk. test