Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For a complete example of an econ score, see the Appendix

Text scores

The result of text scores is a String (text) - as opposed to numerical scores that produce numerical results. They can be used in charts with the type Text.

Text scores need to return an object with two variables

  • result - contains the results string, can be markdown formatted

  • type - variable with the value 'text'

Example:

A simple text score

Code Block
languagejs
const result_string = 'Text with __Markdown__ syntax'

return {
	result: result_string,
	type: 'text',
}

For a more comprehensive example see the Appendix.

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.

...

Code Block
languagejs
// Blackbox IDs
const LEAD_TIME_EXACT = 'BbEconLeadTimeExact'
const MIN_ORDER_QTY = 'BbEconMinOrderQuantity'
const PART_PRICE = 'BbEconCurrentPartPrice'
const PRICE_PER_KG = 'BbEconPricePerKg'
const QUALIFICATION_NEEDED = 'BbEconQualificationNeeded'
const SELECTION_LOGIC_ECON = 'BbEconSelectionLogic'

// Define blackbox weights
const blackboxes = [
	{
		name: 'Part price',
		weight: 0.5,
		id: PART_PRICE,
	},
	{
		name: 'Lead time',
		weight: 0.7,
		id: LEAD_TIME_EXACT,
	},
	{ name: 'Price/kg', weight: 0.5, id: PRICE_PER_KG },
	{
		name: 'Sel. Logic',
		weight: 1.0,
		id: SELECTION_LOGIC_ECON,
	},
]

let resultsBlackboxes = new Set()

let score = 0
let weightsum = 0
let weighttotal = 0

for (const { id, name, weight } of blackboxes) {
    
    // Retrieve blackbox result
	const value = results[id].result
	
	if (value !== null) {
		score += weight * value
		weightsum += weight

		resultsBlackboxes.add({
			name: name,
			weight: weight,
			id: id,
			result: value,
		})
	}
	weighttotal += weight
}
let result = score / weightsum
let certainty = weightsum / weighttotal

return {
	result: result,
	certainty: certainty,
	resultsBlackboxes: resultsBlackboxes,
}

Example

Text score for complexity

Code Block
languagejs
// Blackbox slugs
const COMPLEXITY = 'ComplexityExact'

const complexityExact = results[COMPLEXITY].result
let result_string

if (complexityExact !== null) {
	let complexityChoice
	if (complexityExact < 1.55) {
		complexityChoice = 'low'
	} else if (complexityExact < 2.1) {
		complexityChoice = 'medium'
	} else complexityChoice = 'high'
	result_string =
		'Complexity: ' + complexityExact.toFixed(2) + ' (' + complexityChoice + ')'
} else result_string = 'Insufficient data to calculate Complexity'

return {
	result: result_string,
	type: 'text',
}