Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 16x 6x 6x 6x 16x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
import { assert } from '@amalia/ext/typescript';
import { isComputedEngine2DTable, type ComputeEngineResult } from '@amalia/payout-calculation/types';
import { AmaliaFunctionDefault } from '../../AmaliaFunction';
export const indicesTier = new AmaliaFunctionDefault<[number, ComputeEngineResult], number>({
name: AmaliaFunctionKeys.TIER,
category: AmaliaFunctionCategory.INDICES,
nbParamsRequired: 2,
description: 'Compare a parameter to tiers in a table and return the corresponding value',
exec: (tierToCompare, table) => {
assert(isComputedEngine2DTable<number>(table), 'In TIER, wrong table format');
let toReturn = 0;
// Sorry for the worst quickaround ever, but I don't have time to fix the type of table
for (const tier of table as number[][]) {
if (tier[1] > tierToCompare) {
toReturn = tier[2];
break;
}
}
return toReturn;
},
params: [
{ name: 'parameter', description: 'Variables, fields, properties etc.' },
{ name: 'table', description: 'Table containing (min and max) and return values.' },
],
examples: [
{
desc: 'Returns 0.4',
formula: 'TIER(0.5548, [[0, 0.3, 0],[0.3, 0.5, 0.1],[0.5, 0.6, 0.4],[0.6, 0.7, 0.7]])' as AmaliaFormula,
result: 0.4,
},
{
desc: 'Returns the value from the 3rd column of the corresponding tier in the Payout Grid table based on target reach.',
formula: 'TIER(statement.targetReach, statement.payoutGrid)' as AmaliaFormula,
},
],
});
|