Quick Processor

The Quick Processor allows you to create filters and modify records using JavaScript. In this article, we show how to create a Quick Processor and how to access, filter and modify records.

QuickProcessor.jpg

Add a Quick Processor by clicking the "Quick Pro" button in the record browser menu bar.

Accessing attributes

The Quick Processor is executed for each record individually. You can access the attributes of a data record using the rec object. E.g.:

rec.value     // record's decoded value
rec.key // record's decoded key

// If the value or key is a JSON object
rec.value.myValueAttribute
rec.key.myKeyAttribute

By the way: writing the path of an attribute can be annoying. Therefore, select a record in the record list. The detail view opens. Click on the corresponding attribute and in the filter bubble that opens, click on the name of the attribute. You now have the complete path in your clipboard.

 

Filtering data

To filter records, return a boolean value as the return value of the Quick Processor.

Example:
Suppose we have a record of a sensor that has an attribute called "temperature". For monitoring purposes, we are particularly interested in critical temperatures that exceed a certain threshold value:

return rec.value.temperature > 212 || rec.value.temperature < 32;

 

Transforming data

In addition to boolean values, you can also use complete data objects as return values. This allows you to modify a data record completely. Note that filtering and transforming a record can be combined: return false if the record does not meet the criteria; otherwise, return the modified record.

Example:
We have sensor data that shows us temperature information from our machines in Fahrenheit. But we are interested in the values in Celsius.

rec.value.celsius = (rec.value.temperature - 32) * 5/9;
return rec;

Note how we add a new attribute celsius to our data object's value.

Was this article helpful?
1 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.