Overview
AMPI offers two main concepts for doing calculations: Scores and Blackboxes. Blackboxes are meant to evaluate one or several part Properties. That means a blackbox looks at the value of one property (can also be several properties if they are correlated) and decides whether that value is rather good (for AM) or rather bad (for AM).
Scores are meant to evaluate one or several Blackboxes, to produce an overall assessment of a part’s characteristics. Through reports and charts, the score results can then be shown to users.
The following example illustrates a typical setup:
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
Home › B3_Ampi › Blackboxes
When defining blackboxes, the following fields are available.
Name
The name of the blackbox
Description
Additional description for the blackbox. Currently not displayed anywhere.
Script
The core of the blackbox is a script written in Javascript
Slug
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.
Blackboxes can access a part’s property values through the property’s Variable namespace and Variable name:
variables.<Variable namespace>.<Variable name>
Variable namespace and Variable name are configured on the property itself.
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)
// 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
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
// 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