Sum
The sum function returns the sum of all values in the given expression. Sum can be used with a numeric expression only.
Typically you use the sum function to calculate the total of the selected item over all the blocks in the block model.
The sum function offers three different overloads.
Name | Description |
---|---|
Sum (expression) | Returns the sum of all values in the given expression. |
Sum (expression, filter) | Returns the sum of all values in the given expression where the given filter is true. |
Sum (expressionIfTrue, expressionFalse, filter) | Returns the sum total of all values in the given expression where the given filter is true together with the sum of all values in the 2nd given expression where the given filter is false. |
Sum(expression)
The sum function returns the sum of all values in the given expression.
The sum function is used to return the total of the selected item over all the blocks in the block model.
For example, there's an item in the block model containing truck hours and you want to sum the truck hours over the whole block model, you could write this like so:
truckhours = sum(block.hours)
Sum(expression, filter)
The sum(expression, filter) function returns the sum of all values in the given expression where the given filter is true.
The sum function is used to return the total of the selected item over all the blocks in the block model.
For example, you want to aggregate the truck hours for only the ore blocks. Start by defining what is ore. In this case ore blocks with an iron grade above 50 and fresh material; e.g.: Weathering = 1.
orecriteria = define(block.Fe > 50 & block.Weathering = 1)
The summation formula then becomes:
truckhours = sum(block.Hours, orecriteria)
The final formula is:
orecriteria = define(block.Fe > 50 & block.Weathering = 1
truckhours = sum(block.Hours, orecriteria)
Sum(expressionIfTrue, expressionFalse, filter)
The sum(expressionIfTrue, expressionFalse, filter) function returns the sum total of all values in the given expression where the given filter is true together with the sum of all values in the 2nd given expression or where the given filter is false.
For example, you have an ore precent in your block model and you want to calculate the ore tonnes and waste tonnes in the block model above a certain cut-off.
Firstly, define your cut-off:
cutoff = define(block.Fe > 50)
Next, define how the total tonnes on a block by block basis is being calculated:
totaltonnes = define(block.BlockVolume * block.SG * block.Topo)
Next, define how waste tonnes are being calculated:
wastetonnes = define(totaltonnes * (1 - block.OrePercent))
Finally, define the columns in the report:
wt = sum(wastetonnes, totaltonnes, cutoff)
If the block is below the cutoff, the total tonnage will be used in the summation. If the block is above the cut-off, the block waste tonnes will be used.
Final formula:
cutoff = define(block.Fe > 50)
totaltonnes = define(block.BlockVolume * block.SG * block.Topo)
wastetonnes = define(totaltonnes * (1 - block.OrePercent)
wt = sum(wastetonnes, totaltonnes, cutoff)