Compare commits
1 Commits
refactor/c
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| b995123a36 |
BIN
KapitelGeschaftsidee_GruppeData.pdf
Normal file
BIN
KapitelGeschaftsidee_GruppeData.pdf
Normal file
Binary file not shown.
BIN
Travopti_Docs.pdf
Normal file
BIN
Travopti_Docs.pdf
Normal file
Binary file not shown.
@ -1,9 +1,5 @@
|
|||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
/**
|
|
||||||
* restructures queries to support old and new query syntax
|
|
||||||
* @param {*} queries
|
|
||||||
*/
|
|
||||||
module.exports = function (queries) {
|
module.exports = function (queries) {
|
||||||
let res = _.clone(queries)
|
let res = _.clone(queries)
|
||||||
console.log(res);
|
console.log(res);
|
||||||
@ -31,5 +27,12 @@ module.exports = function (queries) {
|
|||||||
res.tags.push(queries.tags)
|
res.tags.push(queries.tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// console.log(res);
|
||||||
|
|
||||||
|
// console.log('queries successfully transformed');
|
||||||
|
// } catch (error) {
|
||||||
|
// console.log('oldToNewQuerySyntax error');
|
||||||
|
// return queries
|
||||||
|
// }
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
@ -1,12 +1,11 @@
|
|||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
// simple averaging function for desired amount of elements
|
|
||||||
exports.calculateAvgScore = (...scores) => {
|
exports.calculateAvgScore = (...scores) => {
|
||||||
return avgScore = scores.reduce((total, score) => total += score) / scores.length;
|
return avgScore = scores.reduce((total, score) => total += score) / scores.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extends scoring function to be used with high and low bounded search parameters
|
|
||||||
exports.calculateScoreRange = (transitionRange, regionVal, sLowVal, sHighVal) => {
|
exports.calculateScoreRange = (transitionRange, regionVal, sLowVal, sHighVal) => {
|
||||||
|
//console.log('scores.calculateScoreRange:', min, max, multiplier, regionVal, sLowVal, sHighVal)
|
||||||
// return full score when in range
|
// return full score when in range
|
||||||
if (regionVal >= sLowVal && regionVal <= sHighVal) return 10;
|
if (regionVal >= sLowVal && regionVal <= sHighVal) return 10;
|
||||||
// choose value with smallest distance
|
// choose value with smallest distance
|
||||||
@ -14,34 +13,24 @@ exports.calculateScoreRange = (transitionRange, regionVal, sLowVal, sHighVal) =>
|
|||||||
return this.calculateScore(transitionRange, regionVal, sVal);
|
return this.calculateScore(transitionRange, regionVal, sVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* calculates a score from the distance of two values. returns value between 0 and 10
|
|
||||||
* @param {Number} transitionRange transition range defines the width of the area between 0 and 10
|
|
||||||
* @param {Number} regionVal actual value
|
|
||||||
* @param {Number} searchVal desired value
|
|
||||||
* @returns {Number} Score
|
|
||||||
*/
|
|
||||||
exports.calculateScore = (transitionRange, regionVal, searchVal) => {
|
exports.calculateScore = (transitionRange, regionVal, searchVal) => {
|
||||||
let score = 1 - (Math.abs(searchVal - regionVal) / transitionRange);
|
let score = 1 - (Math.abs(searchVal - regionVal) / transitionRange);
|
||||||
return (score) * 10;
|
return (score) * 10;
|
||||||
//return score <= 0 ? 0 : score * 10;
|
//return score <= 0 ? 0 : score * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// transistion function
|
|
||||||
exports.linear = function (x, exponent) {
|
exports.linear = function (x, exponent) {
|
||||||
if (x < 0) return 0
|
if (x < 0) return 0
|
||||||
if (x > 10) return 10
|
if (x > 10) return 10
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
// transistion function
|
|
||||||
exports.easeOut = function (x, exponent) {
|
exports.easeOut = function (x, exponent) {
|
||||||
if (x < 0) return 0
|
if (x < 0) return 0
|
||||||
if (x > 10) return 10
|
if (x > 10) return 10
|
||||||
return (1 - Math.pow(1 - (x / 10), exponent)) * 10
|
return (1 - Math.pow(1 - (x / 10), exponent)) * 10
|
||||||
}
|
}
|
||||||
|
|
||||||
// transistion function
|
|
||||||
exports.easeInOut = function (sc, exponent) {
|
exports.easeInOut = function (sc, exponent) {
|
||||||
const x = (sc ) / 10
|
const x = (sc ) / 10
|
||||||
// console.log(sc, x);
|
// console.log(sc, x);
|
||||||
@ -50,7 +39,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
// transistion function
|
|
||||||
exports.easeInOutAsymmetric = function (sc, exponent) {
|
exports.easeInOutAsymmetric = function (sc, exponent) {
|
||||||
const x = (sc ) / 10
|
const x = (sc ) / 10
|
||||||
// console.log(sc, x);
|
// console.log(sc, x);
|
||||||
@ -59,7 +47,6 @@ exports.easeInOutAsymmetric = function (sc, exponent) {
|
|||||||
return x < 0.5 ? (2 * x) - 0.5 * 10 : (1 - Math.pow(-2 * x + 2, exponent)/2) * 10
|
return x < 0.5 ? (2 * x) - 0.5 * 10 : (1 - Math.pow(-2 * x + 2, exponent)/2) * 10
|
||||||
}
|
}
|
||||||
|
|
||||||
// transistion function
|
|
||||||
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))
|
||||||
|
|||||||
@ -79,10 +79,14 @@ function sumForRangeAvg(from, to, avg) {
|
|||||||
return duration * avg
|
return duration * avg
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function sumForRangeFromDailyValues(from, to, dailyValues) {
|
||||||
* calculates Average for all scoreobjects of 'scores'
|
// NOT NEEDED YET
|
||||||
* @param {[score]} scores array of score objects
|
// for (var m = moment(from).subtract(1, 'months'); m.isSameOrBefore(moment(to).subtract(1, 'months')); m.add(1, 'day')) {
|
||||||
*/
|
// console.log(m);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function calculateAverage(scores) {
|
function calculateAverage(scores) {
|
||||||
let sum = 0
|
let sum = 0
|
||||||
let cnt = 0
|
let cnt = 0
|
||||||
@ -99,16 +103,20 @@ function calculateAverage(scores) {
|
|||||||
//if (sum === 0 && cnt === 0) return 0
|
//if (sum === 0 && cnt === 0) return 0
|
||||||
return _.round(sum / cnt, 3)
|
return _.round(sum / cnt, 3)
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Transforms common dateobject from search to travel periods needed for averaging calculations on climate and price data
|
|
||||||
* @param {customDateObject} dates
|
|
||||||
*/
|
|
||||||
function travelPeriodsFromDates(dates) {
|
function travelPeriodsFromDates(dates) {
|
||||||
let start = moment(`${dates.from.year}-${dates.from.month}-${dates.from.day}`, 'YYYY-MM-DD')
|
let start = moment(`${dates.from.year}-${dates.from.month}-${dates.from.day}`, 'YYYY-MM-DD')
|
||||||
let end = moment(`${dates.to.year}-${dates.to.month}-${dates.to.day}`, 'YYYY-MM-DD')
|
let end = moment(`${dates.to.year}-${dates.to.month}-${dates.to.day}`, 'YYYY-MM-DD')
|
||||||
console.log('start:', moment(start));
|
console.log('start:', moment(start));
|
||||||
console.log('end:', moment(end));
|
console.log('end:', moment(end));
|
||||||
|
// console.log('start:', moment(start).toISOString());
|
||||||
|
// console.log('end:', moment(end).toISOString());
|
||||||
|
// console.log('start:', moment(dates.from));
|
||||||
|
// console.log('end:', moment(dates.to));
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
|
||||||
let travelPeriods = []
|
let travelPeriods = []
|
||||||
|
|
||||||
@ -129,12 +137,6 @@ function travelPeriodsFromDates(dates) {
|
|||||||
return travelPeriods
|
return travelPeriods
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure that travel period is at least one day and "from" should not be after "to.
|
|
||||||
* supports old and new search query syntax (plain text & base64). returns common data structures for both.
|
|
||||||
* @param {*} from
|
|
||||||
* @param {*} to
|
|
||||||
*/
|
|
||||||
function validateDates(from, to) {
|
function validateDates(from, to) {
|
||||||
let fromAndTo = {
|
let fromAndTo = {
|
||||||
from: {},
|
from: {},
|
||||||
@ -167,7 +169,6 @@ function validateDates(from, to) {
|
|||||||
return fromAndTo
|
return fromAndTo
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function for calculating travelperiods
|
|
||||||
function createPeriod(start, end, currentMonth, currentYear) {
|
function createPeriod(start, end, currentMonth, currentYear) {
|
||||||
let period = {}
|
let period = {}
|
||||||
console.log(start, end, currentMonth, currentYear);
|
console.log(start, end, currentMonth, currentYear);
|
||||||
@ -194,15 +195,10 @@ function createPeriod(start, end, currentMonth, currentYear) {
|
|||||||
return period
|
return period
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic function for calculating the score for a certain scoreobject (type). i.e. 'humidity' or 'avg_price_relative'
|
function calculateScoreForPeriod(type, travelPeriods, region, searchLowParam, searchMaxParam) {
|
||||||
* @param {*} type can be every property of a region which consists of an array of 12 elements (one for each month)
|
// console.log('getScoreAndAverageFromClimate for', region.name, type)
|
||||||
* @param {*} travelPeriods
|
|
||||||
* @param {*} region
|
|
||||||
* @param {*} searchLowParam
|
|
||||||
* @param {*} searchMaxParam
|
|
||||||
*/
|
|
||||||
function calculateScoreForPeriod(type, travelPeriods, region, searchLowParam, searchMaxParam) {
|
|
||||||
const singleScores = travelPeriods. map(period => {
|
const singleScores = travelPeriods. map(period => {
|
||||||
let res = {
|
let res = {
|
||||||
type: type,
|
type: type,
|
||||||
@ -222,6 +218,10 @@ function calculateScoreForPeriod(type, travelPeriods, region, searchLowParam, se
|
|||||||
if (el.value !== null && !_.isNaN(el.value)) {
|
if (el.value !== null && !_.isNaN(el.value)) {
|
||||||
averagedScore.value += (el.value * el.days)
|
averagedScore.value += (el.value * el.days)
|
||||||
averagedScore.days += (el.days)
|
averagedScore.days += (el.days)
|
||||||
|
} else {
|
||||||
|
// console.log('skip averaging')
|
||||||
|
// console.log(el)
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
averagedScore.value = _.round(averagedScore.value / averagedScore.days, 3)
|
averagedScore.value = _.round(averagedScore.value / averagedScore.days, 3)
|
||||||
@ -240,11 +240,7 @@ function calculateScoreForPeriod(type, travelPeriods, region, searchLowParam, se
|
|||||||
|
|
||||||
return averagedScore
|
return averagedScore
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* special score calculating function for region tags.
|
|
||||||
* @param {*} regionTags
|
|
||||||
* @param {*} tagStringsFromQueries
|
|
||||||
*/
|
|
||||||
function scoresFromTags(regionTags, tagStringsFromQueries) {
|
function scoresFromTags(regionTags, tagStringsFromQueries) {
|
||||||
return tagStringsFromQueries.map(tagQuery => {
|
return tagStringsFromQueries.map(tagQuery => {
|
||||||
const tag = regionTags.find(tag => tagQuery === tag.name)
|
const tag = regionTags.find(tag => tagQuery === tag.name)
|
||||||
@ -262,16 +258,8 @@ function scoresFromTags(regionTags, tagStringsFromQueries) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* same as calculateScoreForPeriod, exept that it works for a single value property, valid for the whole year (not an array of 12)
|
|
||||||
* @param {*} type
|
|
||||||
* @param {*} region
|
|
||||||
* @param {*} searchLowParam
|
|
||||||
* @param {*} searchMaxParam
|
|
||||||
* @param {*} minMax
|
|
||||||
*/
|
|
||||||
function scoreFromSimpleRegionProperty(type, region, searchLowParam, searchMaxParam, minMax) {
|
function scoreFromSimpleRegionProperty(type, region, searchLowParam, searchMaxParam, minMax) {
|
||||||
|
// console.log('getScoreFromCosts for', region.name, type)
|
||||||
const sc = _.round(scorer.calculateScoreRange(SETTINGS[type][0], region[type], searchLowParam, searchMaxParam), 3)
|
const sc = _.round(scorer.calculateScoreRange(SETTINGS[type][0], region[type], searchLowParam, searchMaxParam), 3)
|
||||||
|
|
||||||
let finScore = {
|
let finScore = {
|
||||||
@ -286,13 +274,9 @@ function scoreFromSimpleRegionProperty(type, region, searchLowParam, searchMaxPa
|
|||||||
return finScore
|
return finScore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* simple function to calculate average price tendencies for given travel time
|
|
||||||
* @param {*} travelPeriods
|
|
||||||
* @param {*} region
|
|
||||||
*/
|
|
||||||
function getAverageFromTrivago(travelPeriods, region) {
|
function getAverageFromTrivago(travelPeriods, region) {
|
||||||
|
// console.log('getAverageFromTrivago for', region.name)
|
||||||
|
|
||||||
const singleScores = travelPeriods.map(period => {
|
const singleScores = travelPeriods.map(period => {
|
||||||
let res = {
|
let res = {
|
||||||
value: region.avg_price_relative[period.month - 1],
|
value: region.avg_price_relative[period.month - 1],
|
||||||
@ -310,6 +294,10 @@ function getAverageFromTrivago(travelPeriods, region) {
|
|||||||
if (el.value !== null && !_.isNaN(el.value)) {
|
if (el.value !== null && !_.isNaN(el.value)) {
|
||||||
averagedScore.value += (el.value * el.days)
|
averagedScore.value += (el.value * el.days)
|
||||||
averagedScore.days += (el.days)
|
averagedScore.days += (el.days)
|
||||||
|
} else {
|
||||||
|
// console.log('skip averaging')
|
||||||
|
// console.log(el)
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
averagedScore.value = _.round(averagedScore.value / averagedScore.days, 2)
|
averagedScore.value = _.round(averagedScore.value / averagedScore.days, 2)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user