eval - AppDaddy-Software-Solutions-Inc/framework-markup-language GitHub Wiki

<EVAL/> : Transform

The <EVAL/> transform is used to perform row level evaluations in a data source.

The operation is applied to each row in the data set and the resulting value stored in the specified target field.

<CALC/>'s are often used to calculate row totals, min or max values etc. It is also useful when used in combination with other data transforms like <FILTER/>.

Be careful to specify a target field that is unique since calculations will overwrite fields by the same name.

Attributes

Name Type Default Description Req
operation string Calculation to perform, see operations ✔
source string Data key to perform the operation on* ✔
target string New data key in each row to assign the calculation to ✔
precision int Round the calculation precision value from the decimal, see fig. 4

Examples

logo See it in Action

For in-depth examples and full applications, visit fml.dev!

Other Widgets You May Find Useful:

Overview

Restrictions:

Like with all operational children of Datasource, they execute in order so you need to be aware that if you execute an operation on a data field created by a CALC, that it is in fact already created above. See fig. 7 for a working example of this.

Parent:

Datasources

Children:

None

Widget Attributes

Name Type Default Description Req
operation string null Calculation to perform, see operations ✔
target string null New data key in each row to assign the calculation to ✔
source string null Data key to perform the operation on* ✔
precision int null Round the calculation precision value from the decimal, see fig. 4

Operation List

  • sum: The average value of all occurrences of a specified source in the data, outputs the value to the target on each row, see fig. 1
  • avg: The average value of all occurrences of a specified source in the data, outputs the value to the target on each row, see fig. 2
  • min: The minimum value of all occurrences of a specified source in the data, outputs the value to the target on each row, see fig. 3
  • max: The maximum value of all occurrences of a specified source in the data, outputs the value to the target on each row, see fig. 4
  • count: The count of the number of existing source fields, outputs the value to the target on each row the source exists, see fig. 5
  • eval: An eval statement acting as the source for each datarow, outputting the evaluated value to the target, see fig. 6
  • total: An operation that returns the total occurrences of a fields value in the dataset, and outputs the value to the target, see fig. 7
eval operation note

The eval operation uses an evaluation statement as the source instead of a data key.

Examples

All examples will use this example data from this endpoint: api.web/cities/nearby

<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
	</ROW>
</DATA>
(fig. 1)

sum

<DATA id="DB1" autoexecute="false">
	<URL><![CDATA[api.web/cities/nearby]]></URL>
	<CALC target="TOTAL" source="POPULATION" operation="sum"/>
</DATA>
Show fig. 1 `Datasource`
<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<TOTAL>5700000</TOTAL>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<TOTAL>5700000</TOTAL>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<TOTAL>5700000</TOTAL>
	</ROW>
</DATA>
(fig. 2)

avg

<DATA id="DB1" autoexecute="false">
	<URL><![CDATA[api.web/cities/nearby]]></URL>
	<CALC target="AVERAGEPOP" source="POPULATION" operation="avg"/>
</DATA>
Show fig. 2 `Datasource`
<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<AVERAGEPOP>1900000</AVERAGEPOP>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<AVERAGEPOP>1900000</AVERAGEPOP>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<AVERAGEPOP>1900000</AVERAGEPOP>
	</ROW>
</DATA>
(fig. 3)

min

<DATA id="DB1" autoexecute="false">
	<URL><![CDATA[api.web/cities/nearby]]></URL>
	<CALC target="LOWESTPOP" source="POPULATION" operation="min"/>
</DATA>
Show fig. 3 `Datasource`
<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<LOWESTPOP>990000</LOWESTPOP>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<LOWESTPOP>990000</LOWESTPOP>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<LOWESTPOP>990000</LOWESTPOP>
	</ROW>
</DATA>
(fig. 4)

max

<DATA id="DB1" autoexecute="false">
	<URL><![CDATA[api.web/cities/nearby]]></URL>
	<CALC target="HIGHESTPOP" source="POPULATION" operation="max" precision="-6"/>
</DATA>

*note the -6 precision rounds like so 2930000 -> 2.930000 -> 3 -> 3000000

Show fig. 4 `Datasource`
<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<HIGHESTPOP>3000000</HIGHESTPOP>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<HIGHESTPOP>3000000</HIGHESTPOP>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<HIGHESTPOP>3000000</HIGHESTPOP>
	</ROW>
</DATA>
(fig. 5)

Everyone datarow that contains a field will be counted count

<DATAid="DB1" autoexecute="false">
	<URL><![CDATA[api.web/cities/nearby]]></URL>
	<CALC target="ROWCOUNT" source="POPULATION" operation="count"/>
</DATA>
Show fig. 5 `Datasource`
<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<ROWCOUNT>3</ROWCOUNT>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<ROWCOUNT>3</ROWCOUNT>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<ROWCOUNT>3</ROWCOUNT>
	</ROW>
</DATA>
(fig. 6)

eval

<DATA id="fig6" autoexecute="false">
	<URL><![CDATA[api.web/cities/nearby]]></URL>
	<CALC target="GROWTH_20PERCENT" source="{POPULATION} * 1.2" operation="EVAL" />
</DATA>
Show fig. 6 `Datasource`
<DATA>
	<ROW>
		<POPULATION>17800000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<GROWTH_20PERCENT>2136000</GROWTH_20PERCENT>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<GROWTH_20PERCENT>1188000</GROWTH_20PERCENT>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<GROWTH_20PERCENT>3516000</GROWTH_20PERCENT>
	</ROW>
</DATA>
(fig. 7)

total Using the total, we get an added field to each row to count the unique occurrences of each. In this case we will use COUNTRY and add a target field COUNTRYCOUNT:

<DATA id="fig7" autoexecute="false">
	<CALC target="COUNTRYCOUNT" source="{data.COUNTRY}" operation="total"/>
</DATA>
Show fig. 7 `Datasource`
<DATA>
	<ROW>
		<POPULATION>1780000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
                <COUNTRYCOUNT>2</COUNTRYCOUNT>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
                <COUNTRYCOUNT>2</COUNTRYCOUNT>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Italy</COUNTRY>
                <COUNTRYCOUNT>1</COUNTRYCOUNT>
	</ROW>
</DATA>
(fig. 8)

Using Datasource id="fig6" fig. 6 as the starting point for Datasource id="fig7", we will expand upon those datarows using sequenced operations. Combining sequences of operations allows you to use previous CALCs within a later operation as shown below.

<DATA id="fig8" value="{fig6.data}" autoexecute="false">
	<CALC target="GROWTH_20PERCENT_W_INFLUX" source="{GROWTH_20PERCENT} + 135500" operation="EVAL" />
	<CALC target="GROWTH_PERCENTAGE_INC_INFLUX" source="(({GROWTH_20PERCENT_W_INFLUX} / {data.POPULATION}) - 1) * 100" operation="EVAL" precision="2" />
	<CALC target="AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX" source="GROWTH_PERCENTAGE_INC_INFLUX" operation="avg" precision="0"/>
</DATA>
Show fig. 8 `Datasource`
<DATA>
	<ROW>
		<POPULATION>1780000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Montreal</CITY>
		<GROWTH_20PERCENT>2136000</GROWTH_20PERCENT>
		<GROWTH_20PERCENT_W_INFLUX>2271500</GROWTH_20PERCENT_W_INFLUX>
		<GROWTH_PERCENTAGE_INC_INFLUX>27.61</GROWTH_PERCENTAGE_INC_INFLUX>
		<AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX>28</AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX>
	</ROW>
	<ROW>
		<POPULATION>990000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Ottawa</CITY>
		<GROWTH_20PERCENT>1188000</GROWTH_20PERCENT>
		<GROWTH_20PERCENT_W_INFLUX>1323500</GROWTH_20PERCENT_W_INFLUX>
		<GROWTH_PERCENTAGE_INC_INFLUX>33.67</GROWTH_PERCENTAGE_INC_INFLUX>
		<AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX>28</AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX>
	</ROW>
	<ROW>
		<POPULATION>2930000</POPULATION>
		<COUNTRY>Canada</COUNTRY>
		<CITY>Toronto</CITY>
		<GROWTH_20PERCENT>3516000</GROWTH_20PERCENT>
		<GROWTH_20PERCENT_W_INFLUX>3651500</GROWTH_20PERCENT_W_INFLUX>
		<GROWTH_PERCENTAGE_INC_INFLUX>24.62</GROWTH_PERCENTAGE_INC_INFLUX>
		<AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX>28</AVERAGE_PERCENTAGE_GROWTH_INC_INFLUX>
	</ROW>
</DATA>

Other Widgets You May Find Useful

⚠️ **GitHub.com Fallback** ⚠️