If no value is there in a region, null is returned
This commit is contained in:
parent
d67c0ef625
commit
85efd83485
@ -26,18 +26,18 @@ module.exports = async (dbConn, id) => {
|
||||
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
|
||||
GROUP_CONCAT(rcma.temperature_mean ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean,
|
||||
GROUP_CONCAT(rcma.temperature_mean_min ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_min,
|
||||
GROUP_CONCAT(rcma.temperature_mean_max ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_max,
|
||||
GROUP_CONCAT(rcma.precipitation ORDER BY rcma.month SEPARATOR ', ') AS precipitation,
|
||||
GROUP_CONCAT(rcma.rain_days ORDER BY rcma.month SEPARATOR ', ') AS rain_days,
|
||||
GROUP_CONCAT(rcma.sun_hours ORDER BY rcma.month SEPARATOR ', ') AS sun_hours,
|
||||
GROUP_CONCAT(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
|
||||
GROUP_CONCAT(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
|
||||
@ -56,18 +56,6 @@ module.exports = async (dbConn, id) => {
|
||||
region.sun_hours = arrayFormatting(region.sun_hours);
|
||||
region.humidity = arrayFormatting(region.humidity);
|
||||
|
||||
|
||||
const emptyArr = Array.from({length: 12}, () => null)
|
||||
if (region.avg_price_relative === null) region.avg_price_relative = emptyArr
|
||||
if (region.temperature_mean === null) region.temperature_mean = emptyArr
|
||||
if (region.temperature_mean_min === null) region.temperature_mean_min = emptyArr
|
||||
if (region.temperature_mean_max === null) region.temperature_mean_max = emptyArr
|
||||
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
|
||||
if (region.humidity === null) region.humidity = emptyArr
|
||||
|
||||
return region;
|
||||
};
|
||||
|
||||
|
||||
@ -26,22 +26,23 @@ module.exports = async (dbConn) => {
|
||||
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
|
||||
GROUP_CONCAT(rcma.temperature_mean ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean,
|
||||
GROUP_CONCAT(rcma.temperature_mean_min ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_min,
|
||||
GROUP_CONCAT(rcma.temperature_mean_max ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_max,
|
||||
GROUP_CONCAT(rcma.precipitation ORDER BY rcma.month SEPARATOR ', ') AS precipitation,
|
||||
GROUP_CONCAT(rcma.rain_days ORDER BY rcma.month SEPARATOR ', ') AS rain_days,
|
||||
GROUP_CONCAT(rcma.sun_hours ORDER BY rcma.month SEPARATOR ', ') AS sun_hours,
|
||||
GROUP_CONCAT(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
|
||||
GROUP_CONCAT(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`
|
||||
|
||||
const [regions, tags] = await Promise.all([dbConn.query(sqlRegions), allTagsWithValues(dbConn)])
|
||||
|
||||
for (k = 0; k < regions.length; k++) {
|
||||
@ -55,17 +56,18 @@ module.exports = async (dbConn) => {
|
||||
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.avg_price_relative === null) region.avg_price_relative = emptyArr
|
||||
if (region.temperature_mean === null) region.temperature_mean = emptyArr
|
||||
if (region.temperature_mean_min === null) region.temperature_mean_min = emptyArr
|
||||
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
|
||||
if (region.humidity === null) region.humidity = emptyArr
|
||||
if (region.avg_price_relative === null) region.avg_price_relative = undefined
|
||||
if (region.temperature_mean === null) region.temperature_mean = undefined
|
||||
if (region.temperature_mean_min === null) region.temperature_mean_min = undefined
|
||||
if (region.temperature_mean_max === null) region.temperature_mean_max = undefined
|
||||
if (region.precipitation === null) region.precipitation = undefined
|
||||
if (region.rain_days === null) region.rain_days = undefined
|
||||
if (region.sun_hours === null) region.sun_hours = undefined
|
||||
if (region.humidity === null) region.humidity = undefined
|
||||
|
||||
region.tags = tags.filter(tag => tag.region_id === region.region_id).map(tag => {
|
||||
delete tag.region_id
|
||||
@ -74,5 +76,8 @@ module.exports = async (dbConn) => {
|
||||
|
||||
return region
|
||||
});
|
||||
*/
|
||||
|
||||
return regions;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user