31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
/**
|
|
*
|
|
*/
|
|
const multiplier_temperature = 5;
|
|
|
|
|
|
/**
|
|
*
|
|
* @param {...any} scores expects objects which contains score and their weight
|
|
*/
|
|
exports.calculateAvgScore = (...scores) => {
|
|
return avgScore = scores.reduce((total, score) => total += score) / scores.length;
|
|
}
|
|
|
|
exports.calculateScoreRange = (min, max, multiplier, regionVal, sLowVal, sHighVal) => {
|
|
//console.log('scores.calculateScoreRange:', min, max, multiplier, regionVal, sLowVal, sHighVal)
|
|
// return full score when in range
|
|
if (regionVal >= sLowVal && regionVal <= sHighVal) return 10;
|
|
// choose value with smallest distance
|
|
let sVal = Math.abs(regionVal - sLowVal) < Math.abs(regionVal - sHighVal) ? sLowVal : sHighVal;
|
|
//console.log('nearest value',sVal, regionVal)
|
|
return this.calculateScore(min, max, multiplier, regionVal, sVal);
|
|
}
|
|
|
|
exports.calculateScore = (min, max, multiplier, regionVal, searchVal) => {
|
|
|
|
let score = 1 - (Math.abs(searchVal - regionVal) / (max - min) * multiplier);
|
|
return score <= 0 ? 0 : score * 10;
|
|
}
|
|
|
|
console.log('test score calculation. result: ' + this.calculateScoreRange(-15, 45, 5, 24, 15, 22)) |