Versions Compared

Key

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

...

Full econ score script

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,
}

...