added images endpoint and some tweaks

This commit is contained in:
Timo Volkmann 2020-06-16 10:09:25 +02:00
parent 24971248c9
commit 867194ad5c
15 changed files with 42 additions and 0 deletions

22
.vscode/launch.json vendored Normal file
View 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",
}
]
}

View File

@ -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

View File

@ -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}`

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 995 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 KiB

View File

@ -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)