From 063f1e19939457dca739ce3bad10b5a97b9d0266 Mon Sep 17 00:00:00 2001 From: Timo John Date: Mon, 15 Jun 2020 15:02:33 +0200 Subject: [PATCH] Stage 1: Restructuring the Express Backend --- .gitignore | 1 + backend/app.js | 11 +- backend/config.json.sample | 10 + backend/index.js | 51 ++ backend/{ => models}/base64.js | 0 backend/{ => models}/climate.js | 0 backend/models/dbConnection.js | 43 + backend/models/getRegions.js | 0 backend/models/getSearchPresets.js | 0 backend/models/getSearchResults.js | 0 backend/{ => models}/mysql.js | 0 backend/{ => models}/score.js | 0 backend/{ => models}/transformer.js | 0 backend/package-lock.json | 109 +++ backend/package.json | 8 +- backend/routes/regions.js | 15 + backend/routes/search.js | 25 + backend/transformer-test.json | 1205 --------------------------- package-lock.json | 11 + 19 files changed, 277 insertions(+), 1212 deletions(-) create mode 100644 backend/config.json.sample create mode 100644 backend/index.js rename backend/{ => models}/base64.js (100%) rename backend/{ => models}/climate.js (100%) create mode 100644 backend/models/dbConnection.js create mode 100644 backend/models/getRegions.js create mode 100644 backend/models/getSearchPresets.js create mode 100644 backend/models/getSearchResults.js rename backend/{ => models}/mysql.js (100%) rename backend/{ => models}/score.js (100%) rename backend/{ => models}/transformer.js (100%) create mode 100644 backend/routes/regions.js create mode 100644 backend/routes/search.js delete mode 100644 backend/transformer-test.json create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 602f445..6546f90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # credentials .env +config.json # compiled output /dist diff --git a/backend/app.js b/backend/app.js index 150213e..09b2294 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1,13 +1,14 @@ const express = require('express') const moment = require('moment') const _ = require('lodash') -const db = require('./mysql') -const score = require('./score') -const transformer = require('./transformer') -const climate = require('./climate') -const base = require('./base64') +const db = require('./models/mysql') +const score = require('./models/score') +const transformer = require('./models/transformer') +const climate = require('./models/climate') +const base = require('./models/base64') const app = express() + const port = 3000 //const multiplier_temp = 5 const multiplier = { diff --git a/backend/config.json.sample b/backend/config.json.sample new file mode 100644 index 0000000..57632dc --- /dev/null +++ b/backend/config.json.sample @@ -0,0 +1,10 @@ +{ + "port":, + "dbCredentials":{ + "host": "", + "port": , + "user": "", + "password": "", + "database": "" + } +} diff --git a/backend/index.js b/backend/index.js new file mode 100644 index 0000000..53475e0 --- /dev/null +++ b/backend/index.js @@ -0,0 +1,51 @@ +const express = require("express"); +const bodyParser = require("body-parser"); +const path = require("path"); +const morgan = require("morgan"); +const dbConnection = require("./models/dbConnection"); +const fs = require("fs"); +const httpolyglot = require("httpolyglot"); + +// credentials +const config = require("./config.json"); +const port = config.port; + +// Router +const search = require("./routes/search"); +const regions = require("./routes/regions"); + +const app = express(); + +(async () => { + try { + // console.log(process.env); + const dbConn = await dbConnection(config); + + // Express middleware + app.use(morgan("dev")); + app.use(express.static(path.join(__dirname, "../../dist"))); + app.use(bodyParser.json()); + + // Express routes + app.use(search(dbConn)); + app.use(regions(dbConn)); + + app.use((err, req, res, next) => { + // 500 + if (true) { + next(); + } else { + res.status(500).send(); + } + }); + + // Start webserver + app.listen(port, () => { + console.log(`Travopti backend listening at http://localhost:${port}`) + }); + } catch (error) { + // TODO: logging + console.error("Failed to start the webserver"); + console.error(error); + } +})(); diff --git a/backend/base64.js b/backend/models/base64.js similarity index 100% rename from backend/base64.js rename to backend/models/base64.js diff --git a/backend/climate.js b/backend/models/climate.js similarity index 100% rename from backend/climate.js rename to backend/models/climate.js diff --git a/backend/models/dbConnection.js b/backend/models/dbConnection.js new file mode 100644 index 0000000..44741dd --- /dev/null +++ b/backend/models/dbConnection.js @@ -0,0 +1,43 @@ +const mariadb = require("mariadb"); +let dbConn; +let conPool; +// mariadb doc: https://github.com/MariaDB/mariadb-connector-nodejs/blob/master/documentation/promise-api.md + +async function reconnect() { + try { + dbConn = await conPool.getConnection(); + } catch (e) { + if (e.code === "ECONNREFUSED") { + let err = new Error("Lost connection to the database"); + err.code = "ERR_DB_CONN_LOST"; + throw err; + } else { + throw e; + } + } +} + +module.exports = async config => { + conPool = mariadb.createPool({ + ...config.dbCredentials, + connectionLimit: 10 + }); + + dbConn = await conPool.getConnection(); + return { + async query(q, p) { + let res; + try { + res = await dbConn.query(q, p); + } catch (e) { + if (e.code === "ER_CMD_CONNECTION_CLOSED") { + await reconnect(); + await this.query(q, p); + } else { + throw e; + } + } + return res; + } + }; +}; diff --git a/backend/models/getRegions.js b/backend/models/getRegions.js new file mode 100644 index 0000000..e69de29 diff --git a/backend/models/getSearchPresets.js b/backend/models/getSearchPresets.js new file mode 100644 index 0000000..e69de29 diff --git a/backend/models/getSearchResults.js b/backend/models/getSearchResults.js new file mode 100644 index 0000000..e69de29 diff --git a/backend/mysql.js b/backend/models/mysql.js similarity index 100% rename from backend/mysql.js rename to backend/models/mysql.js diff --git a/backend/score.js b/backend/models/score.js similarity index 100% rename from backend/score.js rename to backend/models/score.js diff --git a/backend/transformer.js b/backend/models/transformer.js similarity index 100% rename from backend/transformer.js rename to backend/models/transformer.js diff --git a/backend/package-lock.json b/backend/package-lock.json index 7d000fc..7b08128 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -25,6 +25,16 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/geojson": { + "version": "7946.0.7", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.7.tgz", + "integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==" + }, + "@types/node": { + "version": "13.13.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.12.tgz", + "integrity": "sha512-zWz/8NEPxoXNT9YyF2osqyA9WjssZukYpgI4UYZpOjcyqwIUqWGkcCionaEb9Ki+FULyPyvNFpg/329Kd2/pbw==" + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -112,6 +122,14 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "requires": { + "safe-buffer": "5.1.2" + } + }, "binary-extensions": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", @@ -842,6 +860,30 @@ } } }, + "mariadb": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-2.4.0.tgz", + "integrity": "sha512-78zrj9SpF6I3eVWMMkdm+SEfcsMb/uWVKPo7pKhhCfuGywEf3I1dK0ewSTjD0SyTEgSEuWn/H/I4TIErGgYTCQ==", + "requires": { + "@types/geojson": "^7946.0.7", + "@types/node": "^13.9.8", + "denque": "^1.4.1", + "iconv-lite": "^0.5.1", + "long": "^4.0.0", + "moment-timezone": "^0.5.31", + "please-upgrade-node": "^3.2.0" + }, + "dependencies": { + "iconv-lite": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.2.tgz", + "integrity": "sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + } + } + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -901,6 +943,33 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.26.0.tgz", "integrity": "sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw==" }, + "moment-timezone": { + "version": "0.5.31", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz", + "integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==", + "requires": { + "moment": ">= 2.9.0" + } + }, + "morgan": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", + "integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==", + "requires": { + "basic-auth": "~2.0.1", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-finished": "~2.3.0", + "on-headers": "~1.0.2" + }, + "dependencies": { + "depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" + } + } + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -1025,6 +1094,11 @@ "ee-first": "1.1.1" } }, + "on-headers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", + "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==" + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1065,6 +1139,15 @@ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, + "path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=", + "requires": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", @@ -1076,12 +1159,25 @@ "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", "dev": true }, + "please-upgrade-node": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz", + "integrity": "sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==", + "requires": { + "semver-compare": "^1.0.0" + } + }, "prepend-http": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=", "dev": true }, + "process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=" + }, "proxy-addr": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", @@ -1214,6 +1310,11 @@ "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true }, + "semver-compare": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", + "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=" + }, "semver-diff": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-3.1.1.tgz", @@ -1471,6 +1572,14 @@ "prepend-http": "^2.0.0" } }, + "util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "requires": { + "inherits": "2.0.3" + } + }, "utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", diff --git a/backend/package.json b/backend/package.json index c02c6df..53fe656 100644 --- a/backend/package.json +++ b/backend/package.json @@ -4,17 +4,21 @@ "description": "", "main": "app.js", "scripts": { - "start": "nodemon ./app.js" + "start": "nodemon ./index.js" }, "author": "", "license": "ISC", "dependencies": { "axios": "^0.19.2", + "body-parser": "^1.19.0", "dotenv": "^8.2.0", "express": "^4.17.1", "lodash": "^4.17.15", + "mariadb": "^2.4.0", "moment": "^2.26.0", - "mysql2": "^2.1.0" + "morgan": "^1.10.0", + "mysql2": "^2.1.0", + "path": "^0.12.7" }, "devDependencies": { "nodemon": "^2.0.4" diff --git a/backend/routes/regions.js b/backend/routes/regions.js new file mode 100644 index 0000000..32a892b --- /dev/null +++ b/backend/routes/regions.js @@ -0,0 +1,15 @@ +const router = require("express").Router(); +const getRegions = require("../models/getRegions.js"); + +module.exports = dbConn => { + router.get("/api/v1/search", async (req, res) => { + const query = req.query.q; + if (query != undefined) { + res.json(await getRegions(dbConn, query)); + } else { + res.status(400).send(); + } + }); + + return router; +}; diff --git a/backend/routes/search.js b/backend/routes/search.js new file mode 100644 index 0000000..3a6b707 --- /dev/null +++ b/backend/routes/search.js @@ -0,0 +1,25 @@ +const router = require("express").Router(); +const getSearchResults = require("../models/getSearchResults.js"); +const getSearchPresets = require("../models/getSearchPresets.js"); + +module.exports = dbConn => { + router.get("/api/v1/search", async (req, res) => { + const query = req.query.q; + if (query != undefined) { + res.json(await getSearchResults(dbConn, query)); + } else { + res.status(400).send(); + } + }); + + router.get("/api/v1/search/presets", async (req, res) => { + const query = req.query.q; + if (query != undefined) { + res.json(await getSearchPresets(dbConn, query)); + } else { + res.status(400).send(); + } + }); + + return router; +}; diff --git a/backend/transformer-test.json b/backend/transformer-test.json deleted file mode 100644 index cb444bd..0000000 --- a/backend/transformer-test.json +++ /dev/null @@ -1,1205 +0,0 @@ -[ - { - "month": 5, - "days": 31, - "climate": [ - { - "region_id": 2, - "country_id": 2, - "name": "Melbourne", - "temperature_mean": 12.6, - "temperature_mean_min": 8.3, - "temperature_mean_max": 17, - "percipitation": 35.4, - "raindays": 7.8, - "sunhours": 139 - }, - { - "region_id": 3, - "country_id": 2, - "name": "Sydney", - "temperature_mean": 16.6, - "temperature_mean_min": 12, - "temperature_mean_max": 21.2, - "percipitation": 59.2, - "raindays": 5.6, - "sunhours": 218.4 - }, - { - "region_id": 6, - "country_id": 4, - "name": "Sao Paolo", - "temperature_mean": 19, - "temperature_mean_min": 16.1, - "temperature_mean_max": 22.8, - "percipitation": 42.3, - "raindays": 5, - "sunhours": null - }, - { - "region_id": 7, - "country_id": 5, - "name": "Toronto", - "temperature_mean": 16.1, - "temperature_mean_min": 10.8, - "temperature_mean_max": 21.5, - "percipitation": 52, - "raindays": 11, - "sunhours": 268 - }, - { - "region_id": 9, - "country_id": 7, - "name": "Peking", - "temperature_mean": 22.1, - "temperature_mean_min": 15.8, - "temperature_mean_max": 28, - "percipitation": 26.7, - "raindays": 3.3, - "sunhours": 261.5 - }, - { - "region_id": 10, - "country_id": 7, - "name": "Shanghai", - "temperature_mean": 21.3, - "temperature_mean_min": 17.7, - "temperature_mean_max": 25.5, - "percipitation": 105.9, - "raindays": 8.6, - "sunhours": 165.9 - }, - { - "region_id": 11, - "country_id": 8, - "name": "Bogota", - "temperature_mean": 14.3, - "temperature_mean_min": 10.5, - "temperature_mean_max": 19.5, - "percipitation": 108, - "raindays": 13.3, - "sunhours": 103.6 - }, - { - "region_id": 12, - "country_id": 9, - "name": "Kairo", - "temperature_mean": 26.4, - "temperature_mean_min": 20.7, - "temperature_mean_max": 32.5, - "percipitation": 0.1, - "raindays": 0, - "sunhours": null - }, - { - "region_id": 13, - "country_id": 10, - "name": "London", - "temperature_mean": 13.9, - "temperature_mean_min": 9.2, - "temperature_mean_max": 18.4, - "percipitation": 47, - "raindays": 8, - "sunhours": 188 - }, - { - "region_id": 18, - "country_id": 15, - "name": "Reykjavik", - "temperature_mean": 6.8, - "temperature_mean_min": 4.1, - "temperature_mean_max": 10.3, - "percipitation": 53.4, - "raindays": 10.4, - "sunhours": 208.9 - }, - { - "region_id": 24, - "country_id": 20, - "name": "Kuala Lumpur", - "temperature_mean": 28.7, - "temperature_mean_min": 25.3, - "temperature_mean_max": 33.8, - "percipitation": 301.9, - "raindays": 15.4, - "sunhours": null - } - ], - "scores": { - "temperature_mean": [ - { - "region_id": 2, - "type": "temperature_mean", - "value": 12.6, - "score": 0 - }, - { - "region_id": 3, - "type": "temperature_mean", - "value": 16.6, - "score": 2.97 - }, - { - "region_id": 6, - "type": "temperature_mean", - "value": 19, - "score": 6.09 - }, - { - "region_id": 7, - "type": "temperature_mean", - "value": 16.1, - "score": 2.32 - }, - { - "region_id": 9, - "type": "temperature_mean", - "value": 22.1, - "score": 10 - }, - { - "region_id": 10, - "type": "temperature_mean", - "value": 21.3, - "score": 9.09 - }, - { - "region_id": 11, - "type": "temperature_mean", - "value": 14.3, - "score": 0 - }, - { - "region_id": 12, - "type": "temperature_mean", - "value": 26.4, - "score": 5.57 - }, - { - "region_id": 13, - "type": "temperature_mean", - "value": 13.9, - "score": 0 - }, - { - "region_id": 18, - "type": "temperature_mean", - "value": 6.8, - "score": 0 - }, - { - "region_id": 24, - "type": "temperature_mean", - "value": 28.7, - "score": 2.58 - } - ], - "percipitation": [ - { - "region_id": 2, - "type": "percipitation", - "value": 35.4, - "score": 10 - }, - { - "region_id": 3, - "type": "percipitation", - "value": 59.2, - "score": 10 - }, - { - "region_id": 6, - "type": "percipitation", - "value": 42.3, - "score": 10 - }, - { - "region_id": 7, - "type": "percipitation", - "value": 52, - "score": 10 - }, - { - "region_id": 9, - "type": "percipitation", - "value": 26.7, - "score": 10 - }, - { - "region_id": 10, - "type": "percipitation", - "value": 105.9, - "score": 9.95 - }, - { - "region_id": 11, - "type": "percipitation", - "value": 108, - "score": 9.93 - }, - { - "region_id": 12, - "type": "percipitation", - "value": 0.1, - "score": 10 - }, - { - "region_id": 13, - "type": "percipitation", - "value": 47, - "score": 10 - }, - { - "region_id": 18, - "type": "percipitation", - "value": 53.4, - "score": 10 - }, - { - "region_id": 24, - "type": "percipitation", - "value": 301.9, - "score": 8.14 - } - ], - "raindays": [ - { - "region_id": 2, - "type": "raindays", - "value": 7.8, - "score": 5.78 - }, - { - "region_id": 3, - "type": "raindays", - "value": 5.6, - "score": 8.22 - }, - { - "region_id": 6, - "type": "raindays", - "value": 5, - "score": 8.89 - }, - { - "region_id": 7, - "type": "raindays", - "value": 11, - "score": 2.22 - }, - { - "region_id": 9, - "type": "raindays", - "value": 3.3, - "score": 10 - }, - { - "region_id": 10, - "type": "raindays", - "value": 8.6, - "score": 4.89 - }, - { - "region_id": 11, - "type": "raindays", - "value": 13.3, - "score": 0 - }, - { - "region_id": 12, - "type": "raindays", - "value": 0, - "score": 8.89 - }, - { - "region_id": 13, - "type": "raindays", - "value": 8, - "score": 5.56 - }, - { - "region_id": 18, - "type": "raindays", - "value": 10.4, - "score": 2.89 - }, - { - "region_id": 24, - "type": "raindays", - "value": 15.4, - "score": 0 - } - ], - "sunhours": [ - { - "region_id": 2, - "type": "sunhours", - "value": 139, - "score": 1.27 - }, - { - "region_id": 3, - "type": "sunhours", - "value": 218.4, - "score": 7.52 - }, - { - "region_id": 6, - "type": "sunhours", - "value": null, - "score": null - }, - { - "region_id": 7, - "type": "sunhours", - "value": 268, - "score": 10 - }, - { - "region_id": 9, - "type": "sunhours", - "value": 261.5, - "score": 10 - }, - { - "region_id": 10, - "type": "sunhours", - "value": 165.9, - "score": 3.39 - }, - { - "region_id": 11, - "type": "sunhours", - "value": 103.6, - "score": 0 - }, - { - "region_id": 12, - "type": "sunhours", - "value": null, - "score": null - }, - { - "region_id": 13, - "type": "sunhours", - "value": 188, - "score": 5.13 - }, - { - "region_id": 18, - "type": "sunhours", - "value": 208.9, - "score": 6.77 - }, - { - "region_id": 24, - "type": "sunhours", - "value": null, - "score": null - } - ] - } - }, - { - "month": 6, - "days": 30, - "climate": [ - { - "region_id": 2, - "country_id": 2, - "name": "Melbourne", - "temperature_mean": 10, - "temperature_mean_min": 6.1, - "temperature_mean_max": 14, - "percipitation": 51.4, - "raindays": 8, - "sunhours": 122.9 - }, - { - "region_id": 3, - "country_id": 2, - "name": "Sydney", - "temperature_mean": 14.2, - "temperature_mean_min": 10.2, - "temperature_mean_max": 18.3, - "percipitation": 154.7, - "raindays": 9.4, - "sunhours": 160 - }, - { - "region_id": 6, - "country_id": 4, - "name": "Sao Paolo", - "temperature_mean": 17.5, - "temperature_mean_min": 14.6, - "temperature_mean_max": 21.8, - "percipitation": 48.8, - "raindays": 4.5, - "sunhours": null - }, - { - "region_id": 7, - "country_id": 5, - "name": "Toronto", - "temperature_mean": 19.3, - "temperature_mean_min": 15.1, - "temperature_mean_max": 23.8, - "percipitation": 192, - "raindays": 14, - "sunhours": 253 - }, - { - "region_id": 9, - "country_id": 7, - "name": "Peking", - "temperature_mean": 25.4, - "temperature_mean_min": 20.1, - "temperature_mean_max": 30.9, - "percipitation": 85, - "raindays": 7.9, - "sunhours": 209.2 - }, - { - "region_id": 10, - "country_id": 7, - "name": "Shanghai", - "temperature_mean": 24.2, - "temperature_mean_min": 21.6, - "temperature_mean_max": 27.5, - "percipitation": 199.4, - "raindays": 10.6, - "sunhours": 94.1 - }, - { - "region_id": 11, - "country_id": 8, - "name": "Bogota", - "temperature_mean": 14, - "temperature_mean_min": 9.4, - "temperature_mean_max": 18.6, - "percipitation": 57.8, - "raindays": 9.8, - "sunhours": 121.6 - }, - { - "region_id": 12, - "country_id": 9, - "name": "Kairo", - "temperature_mean": 28.6, - "temperature_mean_min": 23.1, - "temperature_mean_max": 34.6, - "percipitation": 0, - "raindays": 0, - "sunhours": null - }, - { - "region_id": 13, - "country_id": 10, - "name": "London", - "temperature_mean": 17, - "temperature_mean_min": 12.2, - "temperature_mean_max": 21.8, - "percipitation": 45.7, - "raindays": 7.6, - "sunhours": 180.8 - }, - { - "region_id": 18, - "country_id": 15, - "name": "Reykjavik", - "temperature_mean": 10.1, - "temperature_mean_min": 7.6, - "temperature_mean_max": 13.5, - "percipitation": 49.3, - "raindays": 9.8, - "sunhours": 171.3 - }, - { - "region_id": 24, - "country_id": 20, - "name": "Kuala Lumpur", - "temperature_mean": 29, - "temperature_mean_min": 25.5, - "temperature_mean_max": 33.8, - "percipitation": 137.9, - "raindays": 7.4, - "sunhours": null - } - ], - "scores": { - "temperature_mean": [ - { - "region_id": 2, - "type": "temperature_mean", - "value": 10, - "score": 0 - }, - { - "region_id": 3, - "type": "temperature_mean", - "value": 14.2, - "score": 0 - }, - { - "region_id": 6, - "type": "temperature_mean", - "value": 17.5, - "score": 4.14 - }, - { - "region_id": 7, - "type": "temperature_mean", - "value": 19.3, - "score": 6.48 - }, - { - "region_id": 9, - "type": "temperature_mean", - "value": 25.4, - "score": 6.88 - }, - { - "region_id": 10, - "type": "temperature_mean", - "value": 24.2, - "score": 8.44 - }, - { - "region_id": 11, - "type": "temperature_mean", - "value": 14, - "score": 0 - }, - { - "region_id": 12, - "type": "temperature_mean", - "value": 28.6, - "score": 2.71 - }, - { - "region_id": 13, - "type": "temperature_mean", - "value": 17, - "score": 3.49 - }, - { - "region_id": 18, - "type": "temperature_mean", - "value": 10.1, - "score": 0 - }, - { - "region_id": 24, - "type": "temperature_mean", - "value": 29, - "score": 2.19 - } - ], - "percipitation": [ - { - "region_id": 2, - "type": "percipitation", - "value": 51.4, - "score": 10 - }, - { - "region_id": 3, - "type": "percipitation", - "value": 154.7, - "score": 9.5 - }, - { - "region_id": 6, - "type": "percipitation", - "value": 48.8, - "score": 10 - }, - { - "region_id": 7, - "type": "percipitation", - "value": 192, - "score": 9.15 - }, - { - "region_id": 9, - "type": "percipitation", - "value": 85, - "score": 10 - }, - { - "region_id": 10, - "type": "percipitation", - "value": 199.4, - "score": 9.09 - }, - { - "region_id": 11, - "type": "percipitation", - "value": 57.8, - "score": 10 - }, - { - "region_id": 12, - "type": "percipitation", - "value": 0, - "score": 10 - }, - { - "region_id": 13, - "type": "percipitation", - "value": 45.7, - "score": 10 - }, - { - "region_id": 18, - "type": "percipitation", - "value": 49.3, - "score": 10 - }, - { - "region_id": 24, - "type": "percipitation", - "value": 137.9, - "score": 9.65 - } - ], - "raindays": [ - { - "region_id": 2, - "type": "raindays", - "value": 8, - "score": 5.56 - }, - { - "region_id": 3, - "type": "raindays", - "value": 9.4, - "score": 4 - }, - { - "region_id": 6, - "type": "raindays", - "value": 4.5, - "score": 9.44 - }, - { - "region_id": 7, - "type": "raindays", - "value": 14, - "score": 0 - }, - { - "region_id": 9, - "type": "raindays", - "value": 7.9, - "score": 5.67 - }, - { - "region_id": 10, - "type": "raindays", - "value": 10.6, - "score": 2.67 - }, - { - "region_id": 11, - "type": "raindays", - "value": 9.8, - "score": 3.56 - }, - { - "region_id": 12, - "type": "raindays", - "value": 0, - "score": 8.89 - }, - { - "region_id": 13, - "type": "raindays", - "value": 7.6, - "score": 6 - }, - { - "region_id": 18, - "type": "raindays", - "value": 9.8, - "score": 3.56 - }, - { - "region_id": 24, - "type": "raindays", - "value": 7.4, - "score": 6.22 - } - ], - "sunhours": [ - { - "region_id": 2, - "type": "sunhours", - "value": 122.9, - "score": 0.01 - }, - { - "region_id": 3, - "type": "sunhours", - "value": 160, - "score": 2.92 - }, - { - "region_id": 6, - "type": "sunhours", - "value": null, - "score": null - }, - { - "region_id": 7, - "type": "sunhours", - "value": 253, - "score": 10 - }, - { - "region_id": 9, - "type": "sunhours", - "value": 209.2, - "score": 6.79 - }, - { - "region_id": 10, - "type": "sunhours", - "value": 94.1, - "score": 0 - }, - { - "region_id": 11, - "type": "sunhours", - "value": 121.6, - "score": 0 - }, - { - "region_id": 12, - "type": "sunhours", - "value": null, - "score": null - }, - { - "region_id": 13, - "type": "sunhours", - "value": 180.8, - "score": 4.56 - }, - { - "region_id": 18, - "type": "sunhours", - "value": 171.3, - "score": 3.81 - }, - { - "region_id": 24, - "type": "sunhours", - "value": null, - "score": null - } - ] - } - }, - { - "month": 7, - "days": 14, - "climate": [ - { - "region_id": 2, - "country_id": 2, - "name": "Melbourne", - "temperature_mean": 9.8, - "temperature_mean_min": 5.9, - "temperature_mean_max": 13.7, - "percipitation": 33.4, - "raindays": 8.7, - "sunhours": 139.3 - }, - { - "region_id": 3, - "country_id": 2, - "name": "Sydney", - "temperature_mean": 13.6, - "temperature_mean_min": 8.8, - "temperature_mean_max": 18.4, - "percipitation": 68.2, - "raindays": 6.7, - "sunhours": 221 - }, - { - "region_id": 6, - "country_id": 4, - "name": "Sao Paolo", - "temperature_mean": 18.1, - "temperature_mean_min": 13.6, - "temperature_mean_max": 22.5, - "percipitation": 19.4, - "raindays": 2.8, - "sunhours": null - }, - { - "region_id": 7, - "country_id": 5, - "name": "Toronto", - "temperature_mean": 23.6, - "temperature_mean_min": 18.5, - "temperature_mean_max": 28.5, - "percipitation": 90, - "raindays": 7, - "sunhours": 308 - }, - { - "region_id": 9, - "country_id": 7, - "name": "Peking", - "temperature_mean": 27.7, - "temperature_mean_min": 23.6, - "temperature_mean_max": 32.2, - "percipitation": 199.9, - "raindays": 8.6, - "sunhours": 174.9 - }, - { - "region_id": 10, - "country_id": 7, - "name": "Shanghai", - "temperature_mean": 29.5, - "temperature_mean_min": 26.5, - "temperature_mean_max": 33.3, - "percipitation": 125.9, - "raindays": 8.2, - "sunhours": 183.6 - }, - { - "region_id": 11, - "country_id": 8, - "name": "Bogota", - "temperature_mean": 13.7, - "temperature_mean_min": 9.4, - "temperature_mean_max": 18.7, - "percipitation": 55.3, - "raindays": 9.7, - "sunhours": 129.2 - }, - { - "region_id": 12, - "country_id": 9, - "name": "Kairo", - "temperature_mean": 29.4, - "temperature_mean_min": 24.3, - "temperature_mean_max": 34.9, - "percipitation": 0, - "raindays": 0, - "sunhours": null - }, - { - "region_id": 13, - "country_id": 10, - "name": "London", - "temperature_mean": 19.5, - "temperature_mean_min": 14.5, - "temperature_mean_max": 24.4, - "percipitation": 45.3, - "raindays": 7.7, - "sunhours": 204 - }, - { - "region_id": 18, - "country_id": 15, - "name": "Reykjavik", - "temperature_mean": 11.8, - "temperature_mean_min": 9.3, - "temperature_mean_max": 15.3, - "percipitation": 51, - "raindays": 10.9, - "sunhours": 178.1 - }, - { - "region_id": 24, - "country_id": 20, - "name": "Kuala Lumpur", - "temperature_mean": 28.6, - "temperature_mean_min": 25, - "temperature_mean_max": 33.2, - "percipitation": 150.2, - "raindays": 10, - "sunhours": null - } - ], - "scores": { - "temperature_mean": [ - { - "region_id": 2, - "type": "temperature_mean", - "value": 9.8, - "score": 0 - }, - { - "region_id": 3, - "type": "temperature_mean", - "value": 13.6, - "score": 0 - }, - { - "region_id": 6, - "type": "temperature_mean", - "value": 18.1, - "score": 4.92 - }, - { - "region_id": 7, - "type": "temperature_mean", - "value": 23.6, - "score": 9.22 - }, - { - "region_id": 9, - "type": "temperature_mean", - "value": 27.7, - "score": 3.88 - }, - { - "region_id": 10, - "type": "temperature_mean", - "value": 29.5, - "score": 1.54 - }, - { - "region_id": 11, - "type": "temperature_mean", - "value": 13.7, - "score": 0 - }, - { - "region_id": 12, - "type": "temperature_mean", - "value": 29.4, - "score": 1.67 - }, - { - "region_id": 13, - "type": "temperature_mean", - "value": 19.5, - "score": 6.74 - }, - { - "region_id": 18, - "type": "temperature_mean", - "value": 11.8, - "score": 0 - }, - { - "region_id": 24, - "type": "temperature_mean", - "value": 28.6, - "score": 2.71 - } - ], - "percipitation": [ - { - "region_id": 2, - "type": "percipitation", - "value": 33.4, - "score": 10 - }, - { - "region_id": 3, - "type": "percipitation", - "value": 68.2, - "score": 10 - }, - { - "region_id": 6, - "type": "percipitation", - "value": 19.4, - "score": 10 - }, - { - "region_id": 7, - "type": "percipitation", - "value": 90, - "score": 10 - }, - { - "region_id": 9, - "type": "percipitation", - "value": 199.9, - "score": 9.08 - }, - { - "region_id": 10, - "type": "percipitation", - "value": 125.9, - "score": 9.76 - }, - { - "region_id": 11, - "type": "percipitation", - "value": 55.3, - "score": 10 - }, - { - "region_id": 12, - "type": "percipitation", - "value": 0, - "score": 10 - }, - { - "region_id": 13, - "type": "percipitation", - "value": 45.3, - "score": 10 - }, - { - "region_id": 18, - "type": "percipitation", - "value": 51, - "score": 10 - }, - { - "region_id": 24, - "type": "percipitation", - "value": 150.2, - "score": 9.54 - } - ], - "raindays": [ - { - "region_id": 2, - "type": "raindays", - "value": 8.7, - "score": 4.78 - }, - { - "region_id": 3, - "type": "raindays", - "value": 6.7, - "score": 7 - }, - { - "region_id": 6, - "type": "raindays", - "value": 2.8, - "score": 10 - }, - { - "region_id": 7, - "type": "raindays", - "value": 7, - "score": 6.67 - }, - { - "region_id": 9, - "type": "raindays", - "value": 8.6, - "score": 4.89 - }, - { - "region_id": 10, - "type": "raindays", - "value": 8.2, - "score": 5.33 - }, - { - "region_id": 11, - "type": "raindays", - "value": 9.7, - "score": 3.67 - }, - { - "region_id": 12, - "type": "raindays", - "value": 0, - "score": 8.89 - }, - { - "region_id": 13, - "type": "raindays", - "value": 7.7, - "score": 5.89 - }, - { - "region_id": 18, - "type": "raindays", - "value": 10.9, - "score": 2.33 - }, - { - "region_id": 24, - "type": "raindays", - "value": 10, - "score": 3.33 - } - ], - "sunhours": [ - { - "region_id": 2, - "type": "sunhours", - "value": 139.3, - "score": 1.3 - }, - { - "region_id": 3, - "type": "sunhours", - "value": 221, - "score": 7.72 - }, - { - "region_id": 6, - "type": "sunhours", - "value": null, - "score": null - }, - { - "region_id": 7, - "type": "sunhours", - "value": 308, - "score": 9.37 - }, - { - "region_id": 9, - "type": "sunhours", - "value": 174.9, - "score": 4.1 - }, - { - "region_id": 10, - "type": "sunhours", - "value": 183.6, - "score": 4.78 - }, - { - "region_id": 11, - "type": "sunhours", - "value": 129.2, - "score": 0.5 - }, - { - "region_id": 12, - "type": "sunhours", - "value": null, - "score": null - }, - { - "region_id": 13, - "type": "sunhours", - "value": 204, - "score": 6.38 - }, - { - "region_id": 18, - "type": "sunhours", - "value": 178.1, - "score": 4.35 - }, - { - "region_id": 24, - "type": "sunhours", - "value": null, - "score": null - } - ] - } - } -] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..4b187ce --- /dev/null +++ b/package-lock.json @@ -0,0 +1,11 @@ +{ + "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=" + } + } +}