added images endpoint and some tweaks
22
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
|
||||
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
|
||||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"name": "NodeJS: nodemon debug",
|
||||
"program": "${workspaceFolder}/backend/app.js",
|
||||
"request": "launch",
|
||||
"restart": true,
|
||||
"runtimeExecutable": "nodemon",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node",
|
||||
"envFile": "${workspaceFolder}/backend/.env",
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -12,6 +12,7 @@ Campus Cup AKMC Data Traveloptimizer
|
||||
- import `setup.sql` for sample data
|
||||
|
||||
### Start
|
||||
- If you run for the first time: `$(cd backend && npm i)`
|
||||
- Run `$(cd backend && npm run start)`
|
||||
- call http://localhost:3000/v1/update/climate to fetch climate data for sample entries.
|
||||
|
||||
@ -26,6 +27,10 @@ Campus Cup AKMC Data Traveloptimizer
|
||||
- sunhours=NUMBER,NUMBER
|
||||
- percipitation=NUMBER,NUMBER
|
||||
|
||||
Alternatively:
|
||||
- q=<base64encoded>
|
||||
- q supports all params from above but values are passed as array.
|
||||
|
||||
__Examples:__
|
||||
http://localhost:3000/v1/search?from=2020-06-14&to=2020-07-29&temperature=27,29&raindays=8,12&sunhours=250,300
|
||||
http://localhost:3000/v1/search?from=2020-06-14&to=2020-07-29
|
||||
|
||||
@ -28,12 +28,18 @@ const samplePresets = [
|
||||
|
||||
app.get('/', (req, res) => res.send('Hello Timo!'))
|
||||
app.get('/v1/regions', (req, res) => getAllRegions().then(x => res.json({ data: x })))
|
||||
app.get('/v1/countries', (req, res) => getAllCountries().then(x => res.json({ data: x })))
|
||||
app.get('/v1/presets', (req, res) => res.json({ data: samplePresets}))
|
||||
app.get('/v1/search', searchHandler)
|
||||
app.get('/v1/update/climate', climateUpdateHandler)
|
||||
app.get('/v1/regions/:id/image', regionImageHandler)
|
||||
|
||||
app.listen(port, () => console.log(`Travopti backend listening at http://localhost:${port}`))
|
||||
|
||||
function regionImageHandler(req, res) {
|
||||
res.sendFile(__dirname+`/data/regions/images/${req.params.id}.jpg`)
|
||||
}
|
||||
|
||||
function climateUpdateHandler(req, res) {
|
||||
let parameter = []
|
||||
if (req.query.startDate) parameter.push(req.query.startDate)
|
||||
@ -238,6 +244,14 @@ function getAllRegions() {
|
||||
return getQueryRows(sql)
|
||||
}
|
||||
|
||||
function getAllCountries() {
|
||||
const sql = `SELECT
|
||||
id AS id,
|
||||
country AS name,
|
||||
FROM countries`
|
||||
return getQueryRows(sql)
|
||||
}
|
||||
|
||||
function getClimatePerRegionAndMonth(regionId, month) {
|
||||
console.log('getClimatePerRegionAndMonth')
|
||||
const sql = `SELECT region_id, AVG(temperature_mean), AVG(temperature_mean_min), AVG(temperature_mean_max), AVG(percipitation), AVG(sunshine) FROM region_climate WHERE month = ${month} AND region_id = ${regionId}`
|
||||
|
||||
BIN
backend/data/regions/images/10.jpg
Normal file
|
After Width: | Height: | Size: 238 KiB |
BIN
backend/data/regions/images/11.jpg
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
backend/data/regions/images/12.jpg
Normal file
|
After Width: | Height: | Size: 253 KiB |
BIN
backend/data/regions/images/13.jpg
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
backend/data/regions/images/18.jpg
Normal file
|
After Width: | Height: | Size: 555 KiB |
BIN
backend/data/regions/images/2.jpg
Normal file
|
After Width: | Height: | Size: 323 KiB |
BIN
backend/data/regions/images/24.jpg
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
backend/data/regions/images/3.jpg
Normal file
|
After Width: | Height: | Size: 995 KiB |
BIN
backend/data/regions/images/6.jpg
Normal file
|
After Width: | Height: | Size: 287 KiB |
BIN
backend/data/regions/images/7.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
backend/data/regions/images/9.jpg
Normal file
|
After Width: | Height: | Size: 504 KiB |
@ -3,6 +3,7 @@ const fs = require('fs')
|
||||
|
||||
|
||||
exports.transform = (data) => {
|
||||
data = _.cloneDeep(data)
|
||||
// get data
|
||||
// let data = JSON.parse(fs.readFileSync('transformer-test.json'));
|
||||
const types = Object.keys(data[0].scores)
|
||||
|
||||