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