Removed getRegions.js for internal usage

This commit is contained in:
Timo John 2020-06-18 14:53:37 +02:00
parent 64abbe4e30
commit 724ebfe35c
4 changed files with 60 additions and 104 deletions

View File

@ -1,43 +1,64 @@
exports.getRegions = async (dbConn) => {
let sql = `SELECT
regions.id AS region_id,
regions.region AS name,
countries.country AS country
FROM regions
JOIN countries
ON regions.country_id = countries.id`
let regions = await dbConn.query(sql);
return regions;
};
const arrayFormatting = require("../util/databaseArrayFormatting.js");
const { takeRightWhile } = require("lodash");
exports.getRegionsInternal = async (dbConn) => {
let regions = await dbConn.query(`SELECT
regions.id AS region_id,
regions.region AS name,
countries.country AS country,
regions.meteostat_id AS meteostat_id
FROM regions
JOIN countries
ON regions.country_id = countries.id`);
return regions;
};
exports.getRegionsById = async (dbConn, id) => {
const region = await dbConn.query(
`SELECT regions.id AS region_id,
module.exports = async (dbConn) => {
const regions = await dbConn.query(
`SELECT regions.id AS region_id,
regions.region AS name,
regions.description,
countries.country AS country,
regions.meteostat_id AS meteostat_id
regions.description AS description,
rcma.temperature_mean_max AS temperature_mean_max,
rcma.precipitation AS precipitation,
rcma.rain_days AS rain_days,
rcma.sun_hours AS sun_hours,
regions_byt.average_per_day_costs AS average_per_day_costs,
rtma.avg_price_relative AS avg_price_relative,
regions_byt.accommodation_costs AS accommodation_costs,
regions_byt.food_costs AS food_costs,
regions_byt.water_costs AS water_costs,
regions_byt.local_transportation_costs AS local_transportation_costs,
regions_byt.entertainment_costs AS entertainment_costs,
regions_byt.alcohol_costs AS alcohol_costs
FROM regions
JOIN countries
ON regions.country_id = countries.id
WHERE regions.id = ?`,
[id]
);
return region;
LEFT JOIN countries ON regions.country_id = countries.id
LEFT JOIN (SELECT rcma.region_id,
GROUP_CONCAT(IFNULL(rcma.temperature_mean,"") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean,
GROUP_CONCAT(IFNULL(rcma.temperature_mean_min, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_min,
GROUP_CONCAT(IFNULL(rcma.temperature_mean_max, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_max,
GROUP_CONCAT(IFNULL(rcma.precipitation, "") ORDER BY rcma.month SEPARATOR ', ') AS precipitation,
GROUP_CONCAT(IFNULL(rcma.rain_days, "") ORDER BY rcma.month SEPARATOR ', ') AS rain_days,
GROUP_CONCAT(IFNULL(rcma.sun_hours, "") ORDER BY rcma.month SEPARATOR ', ') AS sun_hours,
GROUP_CONCAT(IFNULL(rcma.humidity, "") ORDER BY rcma.month SEPARATOR ', ') AS humidity
FROM region_climate_monthly_avg AS rcma
GROUP BY rcma.region_id) rcma ON rcma.region_id = regions.id
LEFT JOIN regions_byt ON regions.id = regions_byt.region_id
LEFT JOIN (SELECT rtma.region_id,
GROUP_CONCAT(IFNULL(rtma.avg_price_relative,"") ORDER BY rtma.month SEPARATOR ', ') AS avg_price_relative
FROM regions_trivago_monthly_avg AS rtma
GROUP BY rtma.region_id) rtma
ON regions.id = rtma.region_id
WHERE regions_byt.travelstyle = 1`
);
for (k = 0; k < regions.length; k++) {
regions[k].avg_price_relative = arrayFormatting(regions[k].avg_price_relative);
//regions[k].temperature_mean = arrayFormatting(regions[k].temperature_mean);
//regions[k].temperature_mean_min = arrayFormatting(regions[k].temperature_mean_min);
regions[k].temperature_mean_max = arrayFormatting(regions[k].temperature_mean_max);
regions[k].precipitation = arrayFormatting(regions[k].precipitation);
regions[k].rain_days = arrayFormatting(regions[k].rain_days);
regions[k].sun_hours = arrayFormatting(regions[k].sun_hours);
//regions[k].humidity = arrayFormatting(regions[k].humidity);
}
//console.log(regions.filter(region => region.rain_days === null))
return regions.map(region => {
const emptyArr = Array.from({ length: 12 }, () => null)
if (region.temperature_mean_max === null) region.temperature_mean_max = emptyArr
if (region.precipitation === null) region.precipitation = emptyArr
if (region.rain_days === null) region.rain_days = emptyArr
if (region.sun_hours === null) region.sun_hours = emptyArr
return region
});
};

View File

@ -1,64 +0,0 @@
const arrayFormatting = require("../util/databaseArrayFormatting.js");
const { takeRightWhile } = require("lodash");
module.exports = async (dbConn) => {
const regions = await dbConn.query(
`SELECT regions.id AS region_id,
regions.region AS name,
countries.country AS country,
regions.description AS description,
rcma.temperature_mean_max AS temperature_mean_max,
rcma.precipitation AS precipitation,
rcma.rain_days AS rain_days,
rcma.sun_hours AS sun_hours,
regions_byt.average_per_day_costs AS average_per_day_costs,
rtma.avg_price_relative AS avg_price_relative,
regions_byt.accommodation_costs AS accommodation_costs,
regions_byt.food_costs AS food_costs,
regions_byt.water_costs AS water_costs,
regions_byt.local_transportation_costs AS local_transportation_costs,
regions_byt.entertainment_costs AS entertainment_costs,
regions_byt.alcohol_costs AS alcohol_costs
FROM regions
LEFT JOIN countries ON regions.country_id = countries.id
LEFT JOIN (SELECT rcma.region_id,
GROUP_CONCAT(IFNULL(rcma.temperature_mean,"") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean,
GROUP_CONCAT(IFNULL(rcma.temperature_mean_min, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_min,
GROUP_CONCAT(IFNULL(rcma.temperature_mean_max, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_max,
GROUP_CONCAT(IFNULL(rcma.precipitation, "") ORDER BY rcma.month SEPARATOR ', ') AS precipitation,
GROUP_CONCAT(IFNULL(rcma.rain_days, "") ORDER BY rcma.month SEPARATOR ', ') AS rain_days,
GROUP_CONCAT(IFNULL(rcma.sun_hours, "") ORDER BY rcma.month SEPARATOR ', ') AS sun_hours,
GROUP_CONCAT(IFNULL(rcma.humidity, "") ORDER BY rcma.month SEPARATOR ', ') AS humidity
FROM region_climate_monthly_avg AS rcma
GROUP BY rcma.region_id) rcma ON rcma.region_id = regions.id
LEFT JOIN regions_byt ON regions.id = regions_byt.region_id
LEFT JOIN (SELECT rtma.region_id,
GROUP_CONCAT(IFNULL(rtma.avg_price_relative,"") ORDER BY rtma.month SEPARATOR ', ') AS avg_price_relative
FROM regions_trivago_monthly_avg AS rtma
GROUP BY rtma.region_id) rtma
ON regions.id = rtma.region_id
WHERE regions_byt.travelstyle = 1`
);
for (k = 0; k < regions.length; k++) {
regions[k].avg_price_relative = arrayFormatting(regions[k].avg_price_relative);
//regions[k].temperature_mean = arrayFormatting(regions[k].temperature_mean);
//regions[k].temperature_mean_min = arrayFormatting(regions[k].temperature_mean_min);
regions[k].temperature_mean_max = arrayFormatting(regions[k].temperature_mean_max);
regions[k].precipitation = arrayFormatting(regions[k].precipitation);
regions[k].rain_days = arrayFormatting(regions[k].rain_days);
regions[k].sun_hours = arrayFormatting(regions[k].sun_hours);
//regions[k].humidity = arrayFormatting(regions[k].humidity);
}
//console.log(regions.filter(region => region.rain_days === null))
return regions.map(region => {
const emptyArr = Array.from({ length: 12 }, () => null)
if (region.temperature_mean_max === null) region.temperature_mean_max = emptyArr
if (region.precipitation === null) region.precipitation = emptyArr
if (region.rain_days === null) region.rain_days = emptyArr
if (region.sun_hours === null) region.sun_hours = emptyArr
return region
});
};

View File

@ -1,5 +1,5 @@
const router = require("express").Router();
const getRegions = require("../models/getRegions2.js");
const getRegions = require("../models/getRegions.js");
const getRegionById = require("../models/getRegionById.js");
const path = require("path");
const fs = require("fs");

View File

@ -4,8 +4,7 @@ const getClimateMinMax = require("./getClimateMinMax.js")
const oldToNewQuerySyntax = require("./oldToNewQuerySyntax.js")
const getAllRegionsWithClimatePerMonth = require('./getAllRegionsWithClimatePerMonth')
const score = require('./score')
// const getRegions = require('../models/getRegions.js').getRegionsInternal
const getRegions = require('../models/getRegions2.js')
const getRegions = require('../models/getRegions.js')
const SHOW_ALL_SCOREOBJECTS = false
const MULTIPLIER = {