From 0ed58d6fa1219322f19362d192defd4a89e26b0a Mon Sep 17 00:00:00 2001 From: Timo John Date: Fri, 10 Jul 2020 15:35:38 +0200 Subject: [PATCH] Add more comments --- backend/models/getPlace.js | 2 +- backend/models/getPlaceNearby.js | 6 ++-- backend/models/getPriceData.js | 45 ------------------------- backend/models/getRegions.js | 11 ------ backend/models/getSearchPresets.js | 4 --- backend/models/handleClimateUpdate.js | 7 ++-- backend/models/handleClimateUpdateV2.js | 3 +- backend/models/handleRegionLonLat.js | 2 +- 8 files changed, 10 insertions(+), 70 deletions(-) delete mode 100644 backend/models/getPriceData.js diff --git a/backend/models/getPlace.js b/backend/models/getPlace.js index 81cc74b..5ec9d36 100644 --- a/backend/models/getPlace.js +++ b/backend/models/getPlace.js @@ -1,7 +1,7 @@ const axios = require("axios") const getPlacePhoto = require("./getPlacePhoto.js") -const fields = "photos,place_id,name,rating,geometry" +const fields = "photos,place_id,name,rating,geometry" // Parameters for Google Place API module.exports = async (q) => { const res = await axios.get( diff --git a/backend/models/getPlaceNearby.js b/backend/models/getPlaceNearby.js index 5df760a..29816c5 100644 --- a/backend/models/getPlaceNearby.js +++ b/backend/models/getPlaceNearby.js @@ -1,9 +1,9 @@ const axios = require("axios") const getPlacePhoto = require("./getPlacePhoto.js") -const radius = 20000 -const rankby = "prominence" -const types = "tourist_attraction" +const radius = 20000 // Search radius in meters +const rankby = "prominence" // Sorting of results +const types = "tourist_attraction" // Category which shall be searched module.exports = async (lat, lng) => { const res = await axios.get( diff --git a/backend/models/getPriceData.js b/backend/models/getPriceData.js deleted file mode 100644 index 324bd81..0000000 --- a/backend/models/getPriceData.js +++ /dev/null @@ -1,45 +0,0 @@ -exports.getBYTdataByRegion = async (dbConn, id, travelstyle = 1) => { - const res = await dbConn.query( - `SELECT - region_id, - travelstyle, - average_per_day AS average_per_day_costs, - accomodation AS accommodation_costs, - food AS food_costs, - water AS water_costs, - local_transportation AS local_transportation_costs, - entertainment AS entertainment_costs - FROM regions_byt - WHERE region_id = ? AND travelstyle = ?`, - [id, travelstyle] - ); - return res; - }; - -exports.getAllBYTdata = async (dbConn, travelstyle = 1) => { - const res = await dbConn.query( - `SELECT - region_id, - travelstyle, - average_per_day AS average_per_day_costs, - accomodation AS accommodation_costs, - food AS food_costs, - water AS water_costs, - local_transportation AS local_transportation_costs, - entertainment AS entertainment_costs - FROM regions_byt - WHERE travelstyle = ?`, - [travelstyle] - ); - return res; - }; - -exports.getTrivagoData = async (dbConn, id) => { - const region = await dbConn.query( - `...`, - [id] - ); - return region; - }; - - \ No newline at end of file diff --git a/backend/models/getRegions.js b/backend/models/getRegions.js index abf7372..0a0e500 100644 --- a/backend/models/getRegions.js +++ b/backend/models/getRegions.js @@ -58,17 +58,6 @@ module.exports = async (dbConn) => { return regions.map(region => { - /* - const emptyArr = Array.from({ length: 12 }, () => null) - if (region.avg_price_relative === null) region.avg_price_relative = undefined - if (region.temperature_mean === null) region.temperature_mean = undefined - if (region.temperature_mean_min === null) region.temperature_mean_min = undefined - if (region.temperature_mean_max === null) region.temperature_mean_max = undefined - if (region.precipitation === null) region.precipitation = undefined - if (region.rain_days === null) region.rain_days = undefined - if (region.sun_hours === null) region.sun_hours = undefined - if (region.humidity === null) region.humidity = undefined - */ region.tags = tags.filter(tag => tag.region_id === region.region_id).map(tag => { delete tag.region_id return tag diff --git a/backend/models/getSearchPresets.js b/backend/models/getSearchPresets.js index fccebae..e8c8037 100644 --- a/backend/models/getSearchPresets.js +++ b/backend/models/getSearchPresets.js @@ -11,15 +11,11 @@ module.exports = async (dbConn) => { ); for (k = 0; k < presets.length; k++) { - //if (presets[k].values.toString().includes("|")) { const value = presets[k].value presets[k].value = value.split("|"); for (i = 0; i < presets[k].value.length; i++) { presets[k].value[i] = parseFloat(presets[k].value[i]) } - //} else { - // presets[k].values = parseInt(presets[k].values) - //} } return presets; }; \ No newline at end of file diff --git a/backend/models/handleClimateUpdate.js b/backend/models/handleClimateUpdate.js index 45cf2c4..6d82436 100644 --- a/backend/models/handleClimateUpdate.js +++ b/backend/models/handleClimateUpdate.js @@ -1,11 +1,12 @@ const axios = require('axios') const _ = require('lodash') -// TODO: Automatically retrieve dates via aviable Data and get rid of random dates +// Constants +// TODO: Automatically retrieve dates via aviable Data from database and get rid of "random" dates 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 +// TODO: call method periodically, not over API (fine for prototyping, tho) module.exports = async (dbConn, startDate = rangeStartDate, endDate = rangeEndDate) => { console.log('update climate with:', startDate, endDate); @@ -54,7 +55,6 @@ async function createClimateObjectFrom(src, startDate, endDate) { sun_hours: element.sunshine, humidity: element.humidity ? element.humidity : null } - //console.log(result) return result }) return retVal @@ -62,7 +62,6 @@ async function createClimateObjectFrom(src, startDate, endDate) { async function writeToDatabase(dbConn, climateObjArr) { for (const element of climateObjArr) { - //console.log(element) try { await dbConn.query(` INSERT INTO region_climate diff --git a/backend/models/handleClimateUpdateV2.js b/backend/models/handleClimateUpdateV2.js index 8edd047..a7e7991 100644 --- a/backend/models/handleClimateUpdateV2.js +++ b/backend/models/handleClimateUpdateV2.js @@ -2,10 +2,11 @@ const axios = require('axios') const _ = require('lodash') // Constants +// TODO: Automatically retrieve dates via aviable Data from database and get rid of "random" dates const rangeStartDate = '2019-01-01' // If no date is given, this date will be used as startDate const rangeEndDate = '2019-12-31'// If no date is given, this date will be used as endDate -// TODO: call method periodically, not over API +// TODO: call method periodically, not over API (fine for prototyping, tho) module.exports = async (dbConn, startDate = rangeStartDate, endDate = rangeEndDate) => { console.log('update climate with:', startDate, endDate); diff --git a/backend/models/handleRegionLonLat.js b/backend/models/handleRegionLonLat.js index bfdd374..18df79b 100644 --- a/backend/models/handleRegionLonLat.js +++ b/backend/models/handleRegionLonLat.js @@ -1,7 +1,7 @@ const axios = require("axios") const getRegions = require("../models/getRegions.js") -const fields = "geometry" +const fields = "geometry" // Parameters for Google Places API module.exports = async (dbConn) => { const regions = await getRegions(dbConn)