# Evaluate

**Evaluate** &#x20;

Given an expression evaluates the expression string. If performed on the data frame row, it evaluates via passing the row as a dictionary. If performed on a single value, it expects an additional argument 'key' to be used in the expression. \
@param expr: The expression to evaluate. \
@param key: An optional 'key' if evaluated on a single value instead of a dictionary.

To perform arithmetic operations on columns, evaluate function is used. This function works on data type with 'Numeric' columns (Float or Integer).&#x20;

{% hint style="info" %}
To perform arithmetic operations on columns, make sure the column's data type is set to '**Integer**' (Numeric) or '**Float**'. Additionally, column values should not contain **NULL** or **Empty** values.
{% endhint %}

### Example 1:&#x20;

Note - This example demos the use of the 'dm: map evaluate' function using expression to calculate total VM CPU count.

Step 1: Create an empty **evaluate\_example\_1** using AIOps studio as shown in the below screenshot.

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-McuSIa3P4Eym1lYap6S%2F-McuVYIQIUTR-8USQ_RX%2FScreen%20Shot%202021-06-23%20at%201.14.06%20PM.png?alt=media\&token=f4d0209c-ee99-4f33-8df2-f9dde6d679d9)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a list of rows with vm_cpu_sockets along with vm_cpu_cores`* \
*`##### for virtual machines using AIOps studio.`*\
\
*`##### RDA function 'Evaluate' is used to demo this example that uses expression`*\
*`##### to calculate total CPU allocated to each virtual machine.`*\
\
*`@dm:empty`* \
&#x20;   *`--> @dm:addrow vm_cpu_sockets = 1 & vm_cpu_cores = 3 & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:addrow vm_cpu_sockets = 2 & vm_cpu_cores = 8 & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:addrow vm_cpu_sockets = 1 & vm_cpu_cores = 2 & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:addrow vm_cpu_sockets = 2 & vm_cpu_cores = 4 & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:addrow vm_cpu_sockets = 2 & vm_cpu_cores = 8 & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:addrow vm_cpu_sockets = 1 & vm_cpu_cores = 2 & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:map to = 'vm_cpu_total' & func = 'evaluate' & expr = 'vm_cpu_sockets * vm_cpu_cores'`*<br>

![Pipeline code added to example pipeline via AIOps Studio](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mcuf7IgHZ-GRs9jVuXM%2F-McufUWN3vh8I0KkU1N4%2FScreen%20Shot%202021-06-23%20at%202.01.39%20PM.png?alt=media\&token=3d7d3eec-39f1-45ee-90ca-9ad9964e1bd7)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![Click 'Verify' will validate the pipeline syntax and prints as shown above.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mcuf__lkryjXF5Sv63T%2F-Mcufs-Bg-3gVohm_yrx%2FScreen%20Shot%202021-06-23%20at%202.03.32%20PM.png?alt=media\&token=18de391a-717d-4a3c-893d-286daa007e3b)

Step 4:  Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Sucessful execution of pipeline](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-McufwDqo4pJipqm_cCa%2F-McugFc67_TowBR1kaqb%2FScreen%20Shot%202021-06-23%20at%202.05.12%20PM.png?alt=media\&token=a23998cb-ee81-4ba2-8836-fe5f43571862)

Step 5: RDA uses the evaluate function to calculate 'vm\_cpu\_total' (using expression as shown in the pipeline code snippet) as shown in the below screenshot.

![After successful execution of pipeline, inspect provides the output from evaluate function execution](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-McugnuIOObKwEpSZT9N%2F-McuhCk0vL8SxwJ1IhOM%2FScreen%20Shot%202021-06-23%20at%202.09.20%20PM.png?alt=media\&token=07713e68-75c6-421c-9adf-ff780b98289c)

### Example 2:

&#x20;Step 1: Create an empty **evaluate\_example\_2** using AIOps studio as shown in the below screenshot.

Note -  In the below example, **vm\_disk\_size\_bytes** is a column that has disk capacity in bytes, using the  '**evaluate**' function, create a new column '**vm\_disk\_size\_gb'** and convert the bytes into GB.

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mcuj2GJC-6at1NEmnua%2F-McujT018SI7-J4_0EPX%2FScreen%20Shot%202021-06-23%20at%202.19.10%20PM.png?alt=media\&token=7d73c872-035b-4c98-98c2-89e140307216)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.&#x20;

using the  '**evaluate**' function, create a new column '**vm\_disk\_size\_gb'** and convert the bytes into GB.\
\
\&#xNAN;*`##### This pipeline creates a list of rows with vm_disk_size_bytes column that has`*\
*`##### disk capacity in bytes. Pipeline uses 'evaluate' function and maps to new column`*\
*`##### and convert the data into 'vm_disk_size_gb'`*\
\
*`##### RDA function 'Evaluate' is used to demo this example that uses expression`*\
*`##### to calculate 'vm_disk_size_gb'`*\
\
*`@dm:empty`* \
&#x20;   *`--> @dm:addrow vm_disk_size_bytes = 10737418240  & vm_id = 'vm1'`*\
&#x20;   *`--> @dm:addrow vm_disk_size_bytes = 322122542    & vm_id = 'vm2'`*\
&#x20;   *`--> @dm:addrow vm_disk_size_bytes = 21474836480  & vm_id = 'vm3'`*\
&#x20;   *`--> @dm:addrow vm_disk_size_bytes = 322122542    & vm_id = 'vm4'`*\
&#x20;   *`--> @dm:addrow vm_disk_size_bytes = 53687091200  & vm_id = 'vm5'`*\
&#x20;   *`--> @dm:map from = 'vm_disk_size_bytes' & to = 'vm_disk_size_in_gb'`*\
&#x20;   *`--> @dm:map attr = 'vm_disk_size_gb' & func = 'evaluate' & expr = 'vm_disk_size_gb/1024 /1024 /1024 '`* \
&#x20;  &#x20;

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mcuo73bDJPHmVcLyL1F%2F-McuoQVLaNTBxkDYKXg7%2FScreen%20Shot%202021-06-23%20at%202.40.57%20PM.png?alt=media\&token=d7861720-d493-401b-a110-88af91d14d5a)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![PIpeline verification with out any errors.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-McuoYE_HEzfS70vHS6F%2F-McuoqWdxz8Boo5CmGJ3%2FScreen%20Shot%202021-06-23%20at%202.42.47%20PM.png?alt=media\&token=2fb45bfe-a3bd-4021-9065-4bb35b55f1a0)

Step 4:  Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Pipeline execution without any errors](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-McuoyuAshWQ9uOUHQFq%2F-McupHeVG5WfGWdU1RyD%2FScreen%20Shot%202021-06-23%20at%202.44.43%20PM.png?alt=media\&token=3b163a77-5014-435b-bd74-bec10ab8f381)

Step 5: RDA uses the evaluate function to calculate '**vm\_disk\_size\_gb**' (using expression as shown in the pipeline code snippet) as shown in the below screenshot.&#x20;

![After successful execution of pipeline, inspect provides the output from evaluate function execution](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-McuplW1UBu1KPfdPP3H%2F-Mcuq71UnXYBtzfzZzMF%2FScreen%20Shot%202021-06-23%20at%202.48.19%20PM.png?alt=media\&token=119fa1ad-1de2-4071-878f-5fc5b56653e1)

Similar to the above-provided examples, users can upload any files that require any mathematical calculation and use the 'evaluate' function/expression to print or store the data.
