score balancing
This commit is contained in:
parent
6180d2f097
commit
cdda87f3c6
@ -57,20 +57,24 @@ function searchHandler(dbConn) {
|
||||
|
||||
//response.data = searchResults
|
||||
const cutScores = !(_.isEmpty(scoreQueryObj.climate) && _.isEmpty(scoreQueryObj.costs) && _.isEmpty(scoreQueryObj.others))
|
||||
console.log(cutScores);
|
||||
//console.log(cutScores);
|
||||
const queryCounter = _.keys(q).length - 2
|
||||
|
||||
|
||||
// FILTER NULLSCORES
|
||||
if (!_.get(q, 'showRegionsWithNullScore', false)) {
|
||||
console.log('without null scores');
|
||||
searchResults = searchResults.filter(el => !_.some(el.scores, score => _.isNaN(score.score) || _.isNull(score.score) || _.isUndefined(score.score))).filter(el => {
|
||||
searchResults = searchResults.filter(el => !_.some(el.scores, score => _.isNaN(score.score) || _.isNil(score.score)/* || score.score <= 0*/)).filter(el => {
|
||||
console.log('scorrrrrr', el.score);
|
||||
return cutScores ? el.score > 3 : true
|
||||
let keepIt = true
|
||||
if (_.some(el.scores, score => score.score <= 0) && el.score < 1) keepIt = false
|
||||
return cutScores ? keepIt : true
|
||||
})//.filter(el => !_.isNaN(el.score))
|
||||
}
|
||||
// SEND RESPONSE
|
||||
if (_.isEmpty(searchResults)) {
|
||||
res.status(404).send('No regions found with your parameters')
|
||||
return
|
||||
}
|
||||
res.json(searchResults)
|
||||
|
||||
|
||||
@ -35,6 +35,14 @@ exports.easeInOut = function (sc, exponent) {
|
||||
return x < 0.5 ? Math.pow(2, exponent-1) * Math.pow(x,exponent) * 10 : (1 - Math.pow(-2 * x + 2, exponent)/2) * 10
|
||||
}
|
||||
|
||||
exports.easeInOut2 = function (sc, exponent) {
|
||||
const x = (sc ) / 10
|
||||
console.log(sc, x);
|
||||
if (x<0) return 0
|
||||
if (x>1) return 10
|
||||
return x < 0.5 ? (2 * x) - 0.5 * 10 : (1 - Math.pow(-2 * x + 2, exponent)/2) * 10
|
||||
}
|
||||
|
||||
exports.sigmoid = function (x, exponent) {
|
||||
// const sigm = (1 / (1 + Math.pow(Math.E, 5 * -x))) * 10 + 5
|
||||
// const sigm = 10 / (1 + Math.pow(Math.E, 1.2 * -x + 6))
|
||||
|
||||
@ -8,8 +8,8 @@ const SHOW_ALL_SCOREOBJECTS = false
|
||||
const MULTIPLIER = {
|
||||
temperature_mean_max: 5,
|
||||
precipitation: 5,
|
||||
rain_days: 4,
|
||||
sun_hours: 1,
|
||||
rain_days: 2,
|
||||
sun_hours: 1.8,
|
||||
|
||||
accommodation_costs: 17,
|
||||
food_costs: 4,
|
||||
@ -19,7 +19,7 @@ const MULTIPLIER = {
|
||||
entertainment_costs: 3,
|
||||
average_per_day_costs: 40,
|
||||
|
||||
avg_price_relative: 2.5
|
||||
avg_price_relative: 3
|
||||
}
|
||||
|
||||
module.exports = function (dbConn) {
|
||||
@ -87,7 +87,7 @@ module.exports = function (dbConn) {
|
||||
|
||||
// CALCULATE SCORE FOR OFFSEASON
|
||||
if (_.has(q, 'others.avg_price_relative')) {
|
||||
let offSeasonScoreObj = calculateScoreForPeriod('avg_price_relative', travelPeriods, reg, q.others.avg_price_relative[0], q.others.avg_price_relative[1], boundaryStatic, 'easeOut', 2.7)
|
||||
let offSeasonScoreObj = calculateScoreForPeriod('avg_price_relative', travelPeriods, reg, q.others.avg_price_relative[0], q.others.avg_price_relative[1], boundaryStatic, 'easeOut', 2)
|
||||
reg.scores.push(offSeasonScoreObj)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user