Merge branch 'feature/accomodation-accumulated-backend' into 'develop'
calculate accommodation total See merge request tjohn/cc-data!23
This commit is contained in:
commit
8c1daa308c
0
backend/util/prices.js
Normal file
0
backend/util/prices.js
Normal file
@ -71,8 +71,11 @@ module.exports = function (dbConn) {
|
|||||||
if (!q.climate.sun_hours) q.climate.sun_hours = [null, null]
|
if (!q.climate.sun_hours) q.climate.sun_hours = [null, null]
|
||||||
if (!q.climate.accommodation_costs) q.climate.accommodation_costs = [null, null]
|
if (!q.climate.accommodation_costs) q.climate.accommodation_costs = [null, null]
|
||||||
}
|
}
|
||||||
// CALCULATE SCORES FOR CLIMATE PROPS
|
|
||||||
|
// CALCULATE PROPERTIES FOR EACH REGION
|
||||||
regions.forEach(reg => {
|
regions.forEach(reg => {
|
||||||
|
|
||||||
|
// CALCULATE SCORES FOR CLIMATE PROPS
|
||||||
Object.entries(q.climate).forEach(([key, value]) => {
|
Object.entries(q.climate).forEach(([key, value]) => {
|
||||||
let finalScoreObj = calculateScoreForPeriod(key, travelPeriods, reg, value[0], value[1], boundaryClimate)
|
let finalScoreObj = calculateScoreForPeriod(key, travelPeriods, reg, value[0], value[1], boundaryClimate)
|
||||||
reg.scores.push(finalScoreObj)
|
reg.scores.push(finalScoreObj)
|
||||||
@ -91,8 +94,18 @@ module.exports = function (dbConn) {
|
|||||||
reg.scores.push(offSeasonScoreObj)
|
reg.scores.push(offSeasonScoreObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CALCULATE PRICE TENDENCY FOR TIMEFRAME
|
||||||
reg.price_tendency_relative = getAverageFromTrivago(travelPeriods, reg)
|
reg.price_tendency_relative = getAverageFromTrivago(travelPeriods, reg)
|
||||||
|
|
||||||
|
// CALCULATE SUM FOR ACCOMODATION FROM AVERAGE PRICES
|
||||||
|
reg.total_accommodation_costs = _.round(sumForRangeAvg(dates.from, dates.to, reg.accommodation_costs), 2)
|
||||||
|
//reg.total_avg_lifestyle = _.round(sumForRangeAvg(dates.from, dates.to, reg.average_per_day_costs - reg.accommodation_costs), 2)
|
||||||
|
//reg.name = `${reg.name} ca. ${_.round(sumForRangeAvg(dates.from, dates.to, reg.accommodation_costs), 2)}€`
|
||||||
|
|
||||||
|
// CALCULATE TOTAL PRICE WITH TRANSPORTATION
|
||||||
|
|
||||||
|
// CALCULATE TOTAL PRICE WITH TRANSPORTATION AND ESTEEMED LIFE COSTS
|
||||||
|
|
||||||
// CALCULATE AVERAGE SCORE Stage 1
|
// CALCULATE AVERAGE SCORE Stage 1
|
||||||
let scoreSubGroups = []
|
let scoreSubGroups = []
|
||||||
if (!_.isEmpty(q.climate)) scoreSubGroups.push(calculateAverage(reg.scores.filter(el => _.some(Object.keys(q.climate), entry => entry === el.type ) )) )
|
if (!_.isEmpty(q.climate)) scoreSubGroups.push(calculateAverage(reg.scores.filter(el => _.some(Object.keys(q.climate), entry => entry === el.type ) )) )
|
||||||
@ -106,6 +119,19 @@ module.exports = function (dbConn) {
|
|||||||
return _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score))
|
return _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sumForRangeAvg(from, to, avg) {
|
||||||
|
let duration = moment(to).diff(moment(from), 'days')
|
||||||
|
return duration * avg
|
||||||
|
}
|
||||||
|
|
||||||
|
function sumForRangeFromDailyValues(from, to, dailyValues) {
|
||||||
|
// NOT NEEDED YET
|
||||||
|
// 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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user