diff --git a/backend/routes/search.js b/backend/routes/search.js index 0ad0702..ba5bf67 100644 --- a/backend/routes/search.js +++ b/backend/routes/search.js @@ -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) diff --git a/backend/util/score.js b/backend/util/score.js index 4238cef..6244ac3 100644 --- a/backend/util/score.js +++ b/backend/util/score.js @@ -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)) diff --git a/backend/util/scoreAndSearch.js b/backend/util/scoreAndSearch.js index ad0ef72..9ff97aa 100644 --- a/backend/util/scoreAndSearch.js +++ b/backend/util/scoreAndSearch.js @@ -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) }