Expression Filter

The fledge-filter-expression allows an arbitrary mathematical expression to be applied to data values. The expression filter allows user to augment the data at the edge to include values calculate from one or more asset to be added and acted upon both within the Fledge system itself, but also forwarded on to the up stream systems. Calculations can range from very simply manipulates of a single value to convert ranges, e.g. a linear scale to a logarithmic scale, or can combine multiple values to create composite value. E.g. create a power reading from voltage and current or work out a value that is normalized for speed.

Expression filters are added in the same way as any other filters.

  • Click on the Applications add icon for your service or task.

  • Select the expression plugin from the list of available plugins.

  • Name your expression filter.

  • Click Next and you will be presented with the following configuration page

expression

  • Configure the expression filter

    • Datapoint Name: The name of the new data point into which the new value will be stored.

    • Expression to apply: This is the expression that will be evaluated for each asset reading. The expression will use the data points within the reading as symbols within the asset. See Expressions below.

  • Enable the plugin and click Done to activate your filter

Expressions

The fledge-filter-expression plugin makes use of the ExprTk library to do run time expression evaluation. This library provides a rich mathematical operator set, the most useful of these in the context of this plugin are;

  • Logical operators (and, nand, nor, not, or, xor, xnor, mand, mor)

  • Mathematical operators (+, -, *, /, %, ^)

  • Functions (min, max, avg, sum, abs, ceil, floor, round, roundn, exp, log, log10, logn, pow, root, sqrt, clamp, inrange, swap)

  • Trigonometry (sin, cos, tan, acos, asin, atan, atan2, cosh, cot, csc, sec, sinh, tanh, d2r, r2d, d2g, g2d, hyp)

Within the expression the data points of the asset become symbols that may be used; therefore if an asset contains values “voltage” and “current” the expression will contain those as symbols and an expression of the form

voltage * current

can be used to determine the power in Watts.

When the filter is used in an environment in which more than one asset is passing through the filter then symbols are created of the form <asset name>.<data point>. As an example if you have one asset called “electrical” that has data points of “voltage” and “current” and another asset called “speed” that has a data point called “rpm” then you can write an expression to obtain the power per 1000 RPM’s of the motor as follows;

(electrical.voltage * electrical.current) / (speed.rpm / 1000)

Known Restrictions

If your asset name or datapoint name contains any characters that are mathematical symbols, i.e. +, -, *, /, %, ^, (, ), [ or ], then these can not be used in the expressions supported by this filter.

Likewise if your asset name or datapoint name is one of the reserved names of operators or functioned they can also not be used.

To resolve this problem it is recommended to use the asset filter to rename the offending assets or datapoint prior to passing the data through the expression filter.

See Also

fledge-filter-fft - A Fledge processing filter plugin that calculates a Fast Fourier Transform across sensor data

fledge-filter-metadata - A Fledge processing filter plugin that adds metadata to the readings in the data stream

fledge-filter-omfhint - A filter plugin that allows data to be added to assets that will provide extra information to the OMF north plugin.

fledge-filter-python35 - A Fledge processing filter that allows Python 3 code to be run on each sensor value.

fledge-filter-rms - A Fledge processing filter plugin that calculates RMS value for sensor data

fledge-filter-scale-set - A Fledge processing filter plugin that applies a set of sale factors to the data

fledge-south-Expression - A Fledge south plugin that uses a user define expression to generate data