Changed accordingly to database col namechanges
This commit is contained in:
parent
ef30abd8b5
commit
aba72921ea
@ -1,6 +1,7 @@
|
||||
PORT=
|
||||
METEOSTAT_API_KEY=
|
||||
DB_HOST=
|
||||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_PORT=
|
||||
PORT=3000
|
||||
METEOSTAT_API_KEY=LMlDskju
|
||||
DB_HOST=lhinderberger.dev
|
||||
DB_USER=root
|
||||
DB_PASSWORD=devtest
|
||||
DB_PORT=3306
|
||||
DATABASE=travopti
|
||||
@ -6,17 +6,17 @@ module.exports = async (dbConn, id) => {
|
||||
regions.region AS name,
|
||||
countries.country AS country,
|
||||
regions.description AS description,
|
||||
rcma.temperature_mean_max,
|
||||
rcma.temperature_mean_max AS temperature_mean_max,
|
||||
rcma.precipitation AS precipitation,
|
||||
rcma.raindays AS rain_days,
|
||||
rcma.sunshine AS sun_hours,
|
||||
regions_byt.average_per_day AS average_per_day_costs,
|
||||
regions_byt.accomodation AS accommodation_costs,
|
||||
regions_byt.food AS food_costs,
|
||||
regions_byt.water AS water_costs,
|
||||
regions_byt.local_transportation AS local_transportation_costs,
|
||||
regions_byt.entertainment AS entertainment_costs,
|
||||
regions_byt.alcohol AS alcohol_costs
|
||||
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,
|
||||
@ -24,8 +24,8 @@ module.exports = async (dbConn, id) => {
|
||||
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.raindays, "") ORDER BY rcma.month SEPARATOR ', ') AS raindays,
|
||||
GROUP_CONCAT(IFNULL(rcma.sunshine, "") ORDER BY rcma.month SEPARATOR ', ') AS sunshine,
|
||||
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
|
||||
|
||||
@ -9,15 +9,15 @@ module.exports = async (dbConn) => {
|
||||
regions.description AS description,
|
||||
rcma.temperature_mean_max AS temperature_mean_max,
|
||||
rcma.precipitation AS precipitation,
|
||||
rcma.raindays AS rain_days,
|
||||
rcma.sunshine AS sun_hours,
|
||||
regions_byt.average_per_day AS average_per_day_costs,
|
||||
regions_byt.accomodation AS accommodation_costs,
|
||||
regions_byt.food AS food_costs,
|
||||
regions_byt.water AS water_costs,
|
||||
regions_byt.local_transportation AS local_transportation_costs,
|
||||
regions_byt.entertainment AS entertainment_costs,
|
||||
regions_byt.alcohol AS alcohol_costs
|
||||
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,
|
||||
@ -25,8 +25,8 @@ module.exports = async (dbConn) => {
|
||||
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.raindays, "") ORDER BY rcma.month SEPARATOR ', ') AS raindays,
|
||||
GROUP_CONCAT(IFNULL(rcma.sunshine, "") ORDER BY rcma.month SEPARATOR ', ') AS sunshine,
|
||||
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
|
||||
|
||||
@ -2,8 +2,8 @@ const axios = require('axios')
|
||||
const _ = require('lodash')
|
||||
|
||||
// TODO: Automatically retrieve dates via aviable Data and get rid of random dates
|
||||
const rangeStartDate = '2010-01' // If no date is given, this date will be used as startDate
|
||||
const rangeEndDate = '2018-12'// If no date is given, this date will be used as endDate
|
||||
const rangeStartDate = '2019-01' // If no date is given, this date will be used as startDate
|
||||
const rangeEndDate = '2020-05'// If no date is given, this date will be used as endDate
|
||||
|
||||
// TODO: call method periodically, not over API
|
||||
module.exports = async (dbConn, startDate = rangeStartDate, endDate = rangeEndDate) => {
|
||||
@ -46,12 +46,12 @@ async function createClimateObjectFrom(src, startDate, endDate) {
|
||||
region_id: src.id,
|
||||
year: element.month.split("-")[0],
|
||||
month: element.month.split("-")[1],
|
||||
temperature: element.temperature_mean,
|
||||
temperature_min: element.temperature_mean_min,
|
||||
temperature_max: element.temperature_mean_max,
|
||||
temperature_mean: element.temperature_mean,
|
||||
temperature_mean_min: element.temperature_mean_min,
|
||||
temperature_mean_max: element.temperature_mean_max,
|
||||
precipitation: element.precipitation,
|
||||
raindays: element.raindays,
|
||||
sunshine: element.sunshine,
|
||||
rain_days: element.raindays,
|
||||
sun_hours: element.sunshine,
|
||||
humidity: element.humidity ? element.humidity : null
|
||||
}
|
||||
//console.log(result)
|
||||
@ -66,16 +66,16 @@ async function writeToDatabase(dbConn, climateObjArr) {
|
||||
try {
|
||||
await dbConn.query(`
|
||||
INSERT INTO region_climate
|
||||
(region_id, year, month, temperature_mean, temperature_mean_min, temperature_mean_max, precipitation, sunshine, humidity, raindays)
|
||||
VALUES (${element.region_id}, ${element.year}, ${element.month}, ${element.temperature}, ${element.temperature_min}, ${element.temperature_max}, ${element.precipitation}, ${element.sunshine}, ${element.humidity}, ${element.raindays})
|
||||
(region_id, year, month, temperature_mean, temperature_mean_min, temperature_mean_max, precipitation, sun_hours, humidity, rain_days)
|
||||
VALUES (${element.region_id}, ${element.year}, ${element.month}, ${element.temperature_mean}, ${element.temperature_mean_min}, ${element.temperature_mean_max}, ${element.precipitation}, ${element.sun_hours}, ${element.humidity}, ${element.rain_days})
|
||||
ON DUPLICATE KEY UPDATE
|
||||
temperature_mean = ${element.temperature},
|
||||
temperature_mean_min = ${element.temperature_min},
|
||||
temperature_mean_max = ${element.temperature_max},
|
||||
temperature_mean = ${element.temperature_mean},
|
||||
temperature_mean_min = ${element.temperature_mean_min},
|
||||
temperature_mean_max = ${element.temperature_mean_max},
|
||||
precipitation = ${element.precipitation},
|
||||
sunshine = ${element.sunshine},
|
||||
sun_hours = ${element.sun_hours},
|
||||
humidity = ${element.humidity},
|
||||
raindays = ${element.raindays};`)
|
||||
rain_days = ${element.rain_days};`)
|
||||
} catch (error) {
|
||||
if (error.code !== 'ER_DUP_ENTRY') {
|
||||
console.log("element which causes problems: ")
|
||||
|
||||
@ -13,7 +13,7 @@ module.exports = dbConn => {
|
||||
if (fs.existsSync(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))) {
|
||||
res.sendFile(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))
|
||||
} else {
|
||||
res.sendFile(path.join(__dirname, `../data/regions/images/x.jpg`))
|
||||
res.sendFile(path.join(__dirname, `../data/regions/images/x.png`))
|
||||
}
|
||||
})
|
||||
router.get("/api/v1/regions/:id", async (req, res) => {
|
||||
|
||||
@ -23,7 +23,7 @@ module.exports = async config => {
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
port: process.env.DB_PORT,
|
||||
database: 'travopti',
|
||||
database: process.env.DATABASE,
|
||||
connectionLimit: 10
|
||||
});
|
||||
|
||||
|
||||
10
package-lock.json
generated
10
package-lock.json
generated
@ -1,11 +1,3 @@
|
||||
{
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"httpolyglot": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/httpolyglot/-/httpolyglot-0.1.2.tgz",
|
||||
"integrity": "sha1-5NNH/omEpi9GfUBg31J/GFH2mXs="
|
||||
}
|
||||
}
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user