58 lines
3.3 KiB
JavaScript
58 lines
3.3 KiB
JavaScript
const climateArrayFormatting = require("./../util/climateArrayFormatting.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,
|
|
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
|
|
WHERE regions_byt.travelstyle = 1`
|
|
);
|
|
|
|
for (k = 0; k < regions.length; k++) {
|
|
//regions[k].temperature_mean = climateArrayFormatting(regions[k].temperature_mean);
|
|
//regions[k].temperature_mean_min = climateArrayFormatting(regions[k].temperature_mean_min);
|
|
regions[k].temperature_mean_max = climateArrayFormatting(regions[k].temperature_mean_max);
|
|
regions[k].precipitation = climateArrayFormatting(regions[k].precipitation);
|
|
regions[k].rain_days = climateArrayFormatting(regions[k].rain_days);
|
|
regions[k].sun_hours = climateArrayFormatting(regions[k].sun_hours);
|
|
//regions[k].humidity = climateArrayFormatting(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
|
|
});
|
|
};
|
|
|