Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 867194ad5c | |||
|
|
24971248c9 |
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
|
# credentials
|
||||||
|
.env
|
||||||
|
|
||||||
# compiled output
|
# compiled output
|
||||||
/dist
|
/dist
|
||||||
|
|
||||||
|
|||||||
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
|
- import `setup.sql` for sample data
|
||||||
|
|
||||||
### Start
|
### Start
|
||||||
|
- If you run for the first time: `$(cd backend && npm i)`
|
||||||
- Run `$(cd backend && npm run start)`
|
- Run `$(cd backend && npm run start)`
|
||||||
- call http://localhost:3000/v1/update/climate to fetch climate data for sample entries.
|
- 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
|
- sunhours=NUMBER,NUMBER
|
||||||
- percipitation=NUMBER,NUMBER
|
- percipitation=NUMBER,NUMBER
|
||||||
|
|
||||||
|
Alternatively:
|
||||||
|
- q=<base64encoded>
|
||||||
|
- q supports all params from above but values are passed as array.
|
||||||
|
|
||||||
__Examples:__
|
__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&temperature=27,29&raindays=8,12&sunhours=250,300
|
||||||
http://localhost:3000/v1/search?from=2020-06-14&to=2020-07-29
|
http://localhost:3000/v1/search?from=2020-06-14&to=2020-07-29
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
-- Exportiere Datenbank Struktur für travopti
|
-- Exportiere Datenbank Struktur für travopti
|
||||||
DROP DATABASE IF EXISTS `travopti`;
|
DROP DATABASE IF EXISTS `travopti`;
|
||||||
CREATE DATABASE IF NOT EXISTS `travopti` /*!40100 DEFAULT CHARACTER SET latin1 */;
|
CREATE DATABASE IF NOT EXISTS `travopti` /*!40100 DEFAULT CHARACTER SET utf8 */;
|
||||||
USE `travopti`;
|
USE `travopti`;
|
||||||
|
|
||||||
-- Exportiere Struktur von Tabelle travopti.countries
|
-- Exportiere Struktur von Tabelle travopti.countries
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
METEOSTAT_API_KEY=LMlDskju
|
|
||||||
DB_HOST=localhost
|
|
||||||
DB_USER=root
|
|
||||||
DB_PASSWORD=devtest
|
|
||||||
DB_PORT=3306
|
|
||||||
5
backend/.env.sample
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
METEOSTAT_API_KEY=
|
||||||
|
DB_HOST=
|
||||||
|
DB_USER=
|
||||||
|
DB_PASSWORD=
|
||||||
|
DB_PORT=
|
||||||
@ -11,7 +11,7 @@ const app = express()
|
|||||||
const port = 3000
|
const port = 3000
|
||||||
//const multiplier_temp = 5
|
//const multiplier_temp = 5
|
||||||
const multiplier = {
|
const multiplier = {
|
||||||
temperature_mean: 5,
|
temperature_mean_max: 5,
|
||||||
percipitation: 3.5,
|
percipitation: 3.5,
|
||||||
raindays: 3,
|
raindays: 3,
|
||||||
sunhours: 2.5,
|
sunhours: 2.5,
|
||||||
@ -28,12 +28,18 @@ const samplePresets = [
|
|||||||
|
|
||||||
app.get('/', (req, res) => res.send('Hello Timo!'))
|
app.get('/', (req, res) => res.send('Hello Timo!'))
|
||||||
app.get('/v1/regions', (req, res) => getAllRegions().then(x => res.json({ data: x })))
|
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/presets', (req, res) => res.json({ data: samplePresets}))
|
||||||
app.get('/v1/search', searchHandler)
|
app.get('/v1/search', searchHandler)
|
||||||
app.get('/v1/update/climate', climateUpdateHandler)
|
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}`))
|
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) {
|
function climateUpdateHandler(req, res) {
|
||||||
let parameter = []
|
let parameter = []
|
||||||
if (req.query.startDate) parameter.push(req.query.startDate)
|
if (req.query.startDate) parameter.push(req.query.startDate)
|
||||||
@ -64,7 +70,7 @@ function searchHandler(req, res) {
|
|||||||
console.log('Q:', q)
|
console.log('Q:', q)
|
||||||
|
|
||||||
let queryObj = {}
|
let queryObj = {}
|
||||||
if (q.temperature) queryObj['temperature_mean'] = q.temperature
|
if (q.temperature) queryObj['temperature_mean_max'] = q.temperature
|
||||||
if (q.percipitation) queryObj['percipitation'] = q.percipitation
|
if (q.percipitation) queryObj['percipitation'] = q.percipitation
|
||||||
if (q.raindays) queryObj['raindays'] = q.raindays
|
if (q.raindays) queryObj['raindays'] = q.raindays
|
||||||
if (q.sunhours) queryObj['sunhours'] = q.sunhours
|
if (q.sunhours) queryObj['sunhours'] = q.sunhours
|
||||||
@ -88,11 +94,11 @@ async function scoreAndSearch(from, to, queries) {
|
|||||||
|
|
||||||
// randomize if empty queries
|
// randomize if empty queries
|
||||||
if (_.isEmpty(queries)) {
|
if (_.isEmpty(queries)) {
|
||||||
let t = _.round(_.random(minMax.min.temperature_mean, minMax.max.temperature_mean-5),0)
|
let t = _.round(_.random(minMax.min.temperature_mean_max, minMax.max.temperature_mean_max-5),0)
|
||||||
let p = _.round(_.random(minMax.min.percipitation, minMax.max.percipitation - 50), 0)
|
let p = _.round(_.random(minMax.min.percipitation, minMax.max.percipitation - 50), 0)
|
||||||
let r = _.round(_.random(minMax.min.raindays, minMax.max.raindays - 5), 0)
|
let r = _.round(_.random(minMax.min.raindays, minMax.max.raindays - 5), 0)
|
||||||
let s = _.round(_.random(minMax.min.sunhours, minMax.max.sunhours - 50), 0)
|
let s = _.round(_.random(minMax.min.sunhours, minMax.max.sunhours - 50), 0)
|
||||||
queries.temperature_mean = `${t},${t + 5}`
|
queries.temperature_mean_max = `${t},${t + 5}`
|
||||||
queries.percipitation = `${p},${p + 50}`
|
queries.percipitation = `${p},${p + 50}`
|
||||||
queries.raindays = `${r},${r + 5}`
|
queries.raindays = `${r},${r + 5}`
|
||||||
queries.sunhours = `${s},${s + 50}`
|
queries.sunhours = `${s},${s + 50}`
|
||||||
@ -238,6 +244,14 @@ function getAllRegions() {
|
|||||||
return getQueryRows(sql)
|
return getQueryRows(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllCountries() {
|
||||||
|
const sql = `SELECT
|
||||||
|
id AS id,
|
||||||
|
country AS name,
|
||||||
|
FROM countries`
|
||||||
|
return getQueryRows(sql)
|
||||||
|
}
|
||||||
|
|
||||||
function getClimatePerRegionAndMonth(regionId, month) {
|
function getClimatePerRegionAndMonth(regionId, month) {
|
||||||
console.log('getClimatePerRegionAndMonth')
|
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}`
|
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}`
|
||||||
@ -263,7 +277,7 @@ function getAllRegionsWithClimatePerMonth(month) {
|
|||||||
function oldToNewQuerySyntax(queries) {
|
function oldToNewQuerySyntax(queries) {
|
||||||
let res = {}
|
let res = {}
|
||||||
try {
|
try {
|
||||||
if (queries.temperature_mean) res.temperature_mean = [queries.temperature_mean.split(',')[0], queries.temperature_mean.split(',')[1]]
|
if (queries.temperature_mean_max) res.temperature_mean_max = [queries.temperature_mean_max.split(',')[0], queries.temperature_mean_max.split(',')[1]]
|
||||||
if (queries.percipitation) res.percipitation = [queries.percipitation.split(',')[0], queries.percipitation.split(',')[1]]
|
if (queries.percipitation) res.percipitation = [queries.percipitation.split(',')[0], queries.percipitation.split(',')[1]]
|
||||||
if (queries.raindays) res.raindays = [queries.raindays.split(',')[0], queries.raindays.split(',')[1]]
|
if (queries.raindays) res.raindays = [queries.raindays.split(',')[0], queries.raindays.split(',')[1]]
|
||||||
if (queries.sunhours) res.sunhours = [queries.sunhours.split(',')[0], queries.sunhours.split(',')[1]]
|
if (queries.sunhours) res.sunhours = [queries.sunhours.split(',')[0], queries.sunhours.split(',')[1]]
|
||||||
|
|||||||
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) => {
|
exports.transform = (data) => {
|
||||||
|
data = _.cloneDeep(data)
|
||||||
// get data
|
// get data
|
||||||
// let data = JSON.parse(fs.readFileSync('transformer-test.json'));
|
// let data = JSON.parse(fs.readFileSync('transformer-test.json'));
|
||||||
const types = Object.keys(data[0].scores)
|
const types = Object.keys(data[0].scores)
|
||||||
|
|||||||