...
Blackboxes and Scores are written in Javascript. It is helpful to have some prior exposure to any kind of scriptwriting or programming.
Blackboxes
Defining blackboxes
Blackboxes are defined in the admin panel under
...
Unique identifier of that blackbox. Used to reference this blackbox from a score.
Writing blackbox scripts
A blackbox can be considered a function that returns a value or an object.
...
Variable namespace and Variable name are configured on the property itself.
...
An example blackbox using the value of .
...
By convention, blackboxes used for tech and econ scores have a return value between 0..1 representing a percentage between 0-100%.
Example:
A blackbox assessing the integer property Lead time (days) could look like this
...
Code Block | ||
---|---|---|
| ||
// Lead time intervals const intervals = [8, 60] // Reading lead time from the property const leadTime = variables.custom.leadTimeExact if (leadTime === null) return null return mapInterval(leadTime, intervals[0], intervals[1]) |
Example:
A blackbox assessing the boolean property Qualification needed
Code Block | ||
---|---|---|
| ||
const propertyValue = variables.custom.qualificationNeeded switch (propertyValue) { case true: return 0.35 case false: return 1.0 default: return null } |
Scores
Scores can aggregate blackbox results into an overall result
Tech and Econ scores
The general setup of Tech and Econ scores in AMPI is the calculation of the Weighted Average (Wikipedia). In the weighted average score calculation, we calculate the average of the results of individual blackboxes and give a weight according to their importance or impact on the overall score.
The weights of the blackbox can be adjusted to indicate how much impact an individual blackbox should have on the score. By convention, the weights are between 0..1.
Helper functions
Helper functions are functions that are often used throughout multiple blackboxes or scores. To avoid defining such functions in each blackbox where it is used, they can just be defined once as a helper function. Then all blackboxes and scores can just use them without the need to define them redundantly.
Example helper function
Code Block | ||
---|---|---|
| ||
// Maps an input from a flexible interval into the corresponding value within standard interval [0, 1]
function mapInterval(val, a, b, c = 0.0, d = 1.0) {
return Math.min(1, Math.max(0, ((val - a) * (d - c)) / (b - a) + c))
} |
For an example where a helper function is used, see the example blackbox for Lead time (days) above.
Helper functions can be defined in the admin panel under
Home › B3_Ampi › Helper functions