Trimming Up Decimal Values in Inferno

This guide will explain step by step, how to create the first script in the new Inferno programming language. Inferno is a hybrid scripting language created by Plow Technologies, that brings powerful realtime scripting capabilities to applications that use it. Think of Inferno as Excel scripting for real-time data.

Create new script #

Begin by selecting the bookmark icon. Following this, choose ‘Virtual Parameter Setup’ from the dropdown menu.

Proceed by selecting ‘New Script (Inferno)’ on the left-hand side menu pane, which will navigate to the text editor interface.

Examine the interface’s distinct parts. The left side features the edit window for script input, indicating its save status. The right side includes the script properties window for naming the script.

For this example, the name of this script is ‘Hello Inferno’ and a description, ‘Our first inferno script’ is used. Choose a group for editing permissions and set visibility to control who can view it. The group in this example is set to “plowDemoUsers”.

Available visibility options include ‘Public’, allowing everyone to view the script, and ‘Private’, restricting visibility to group members or with admin access to the group. In this example, visibility is set to ‘Public’.

Below the script properties, find the Testing Console window for code verification. Further down, there’s an option to add a parameter. To begin, add a parameter. Selecting ‘Add Parameter’ creates a new field for input assignment.

Click on the pencil icon on the newly created parameter.

In the example ‘Plow Demo’ Company is selected, enabling the selection of one of the demo sites and the option to choose a specific parameter. In the following case, ‘Yesterday’s flow’ parameter is selected. It has to be confirmed by selecting the ‘Confirm Parameter’ button.

In the Testing Console parameter is renamed to ‘volume’.

Now it is possible to start typing the script. To find the available functions it is advised to have a look on the OnPing support page (www.onping.net/help/) and type in ‘inferno’ in the search bar and select ‘Inferno Programming Language – Function Reference’.

When opened then navigate to ‘Fetching Data From OnPing’ which will list the available functions.

In the following example, the ‘valueAt’ expression is used.

When typing the ‘valueAt’ function the help hint is visible which says that this function takes a series of ‘a and a time and returns an option of ‘a (series of ‘a -> time -> option of ‘a).

The series of ‘a is a volume parameter in our example. It’s called a series because it corresponds to a stream of values, not just one value.

When writing the script to accept the code proposal the ‘tab’ button has to be pressed.

Typed in the script is: ‘valueAt volume’. The next step is to define when the value has to be checked. In the following example, it will be defined as ‘now’. In the next step, the following code is added ‘valueAt volume ?now’. 

The reason it has a question mark before ‘now’ it is just to say that is the parameter that doesn’t have to be defined, it’s implicit.

Select ‘Test’ in the Testing Console to verify that everything works.

After the test procedure is finished then the result shows 121.27147674560547.

The first Inferno script is completed and tested.

Time Travel mode #

For the following example, historical testing data is available. The input and output parameters are visible next to each other and it is possible to view them for the requested time ranges. To enter the ‘Time Travel Mode’ select the clock icon.

It is possible to select the requested date by typing it in or by selecting it from the calendar.

After the time range is adjusted to reload the data the ‘Test’ button has to be pressed then the values in the table are updated. To get back to the initial mode select ‘Exit Time Travel Mode’.

Trimming Up Decimal Values – Pattern Match #

 

Note that values in column ‘Yesterday’s Flow’ have only two decimals showing and the ones in the ‘Script Output’ have a lot of decimals visible. 

Trimming values is a common requirement due to the raw nature of input values in inferno, which lack pre-applied masks. This explains why certain values might display with two decimals, often resulting from masking applied elsewhere. However, the values that come into the inferno inputs are always raw values so there’s no mask supplied, ensuring raw input values helps avoid unexpected behavior.

To customize the value display, applying a specific mask is possible. There are numerous methods to achieve this.

First, let’s analyze the last piece option of ‘a from the ‘valueAt’ command. It means that this value may or may not exist.

If it exists it’ll have a value as an example like ‘Some 1.0’. 

If it doesn’t exist it will have a value of ‘None’.

What can be done in OnPing is to match against values using the ‘valueAt’ command. Match ‘valueAt’ and ‘volume ?now’ and then it’s ‘Some value’ or ‘None’. This reproduces the same thing. This is a pattern match to extract this value and then it puts it right back in the same pattern matched against.

To trim the result, another function has to be added to the existing code. In the documentation, there is a function called ‘truncateTo’. This cuts off decimals after ‘n’ values, it is possible to truncate to 0, 1, or 2.

In the following example, the truncate to 2 is applied. Select ‘Test’ in the Testing Console to verify that everything works. After the test has been finished, values in the ‘Script Output’ column have been trimmed, similar to the ‘Result’ value in the Testing Console.


That’s one way to trim the result. The value is pattern matched and truncate to 2 is applied. 

Trimming Up Decimal Values – Map #

There is another possibility of trimming up the results using the ‘Option.map’ expression with arguments as truncated and the value read. The syntax is as follows:

Option.map (truncateTo 2) (valueAt volume ?now)

After updating the script, select ‘Test’ in the Testing Console to verify everything works. It produces the same result. The ‘Option.map’ takes the ‘truncateTo’ function and jumps inside of the ‘valueAt’ option and applies the function to it.

Inferno is a functional programming language and there are a lot of tricks possible like pattern matching and mapping. There is also nice type hinting which can tell a lot about what the respective function is doing.

If you have any other questions about Inferno please feel free to reach out.

 

Powered by BetterDocs