From d994268317774fa1a05c00c70230fdba8ca89b9f Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Mon, 26 Feb 2024 13:41:59 +0000 Subject: [PATCH] Update --- src/v1/js/Forecast.js | 31 +++++++++++++++++++++++++------ src/v1/js/Location.js | 14 +++++--------- src/v1/js/Nearby.js | 12 +++++++----- src/v1/js/NearbyList.js | 13 +++++-------- src/v1/js/RightByMe.js | 5 +---- src/v1/js/VenueDetail.js | 2 +- src/v1/js/Weather.js | 6 +----- src/v1/js/WeatherAlert.js | 6 +----- src/v1/js/libs/reducers.js | 34 +++++++++++++++++++++++++++++++++- src/v1/js/libs/templates.js | 4 ++-- 10 files changed, 81 insertions(+), 46 deletions(-) diff --git a/src/v1/js/Forecast.js b/src/v1/js/Forecast.js index ff74b0a..b756971 100644 --- a/src/v1/js/Forecast.js +++ b/src/v1/js/Forecast.js @@ -7,6 +7,7 @@ const { createPanel, addPanel } = require('./libs/panel'); const templates = require('./libs/templates'); const TimeFormat = require('hh-mm-ss'); const { hourFloor } = require('./libs/utils'); +const {reduceForcastToday, reduceForcastDaily} = require("./libs/reducers"); const ForecastModel = Backbone.Model.extend({ 'defaults': function (obj) { @@ -27,12 +28,8 @@ const ForecastModel = Backbone.Model.extend({ 'getForecast': function() { const ll = this.get('ll'); request({ - 'url': `${window.loc}/forecast`, + 'url': `${window.loc}/forecast/${ll.replace(',','/')}`, 'method': 'GET', - 'qs': { - 'll': ll, - 'w' : hourFloor() - } }, function(err, res, body) { console.log('statusCode', res.statusCode); if (err) @@ -45,6 +42,8 @@ const ForecastModel = Backbone.Model.extend({ this.set(fsJSON); // console.log(body); + this.set('time', Date.now()); + this.logUpdate(); } }.bind(this)); @@ -133,7 +132,7 @@ const ForecastView = Backbone.View.extend({ const html = []; const currently = this.model.get('currently'); - const forcastToday = { 'today':this.model.get('forcastToday'), 'daily':this.model.get('dailyForecast') }; + const forcastToday = { 'today':reduceForcastToday(this.model.get('forcastToday')), 'daily':reduceForcastDaily(this.model.get('dailyForecast')) }; const details = this.model.get('details'); html.push('
'); @@ -141,7 +140,25 @@ const ForecastView = Backbone.View.extend({ console.log(JSON.stringify(currently)); try { html.push(templates.templateCurrently(currently)); + + } + catch(e) { + console.log('ERROR!! Forecast templating failed'); + console.error(e); + } + + try { + html.push(templates.templateForecast(forcastToday)); + + + } + catch(e) { + console.log('ERROR!! Forecast templating failed'); + console.error(e); + } + + try { html.push(templates.templateDetails(details)); } @@ -149,6 +166,8 @@ const ForecastView = Backbone.View.extend({ console.log('ERROR!! Forecast templating failed'); console.error(e); } + + html.push('
'); html.push('
'); diff --git a/src/v1/js/Location.js b/src/v1/js/Location.js index bf20c59..10fe2e6 100644 --- a/src/v1/js/Location.js +++ b/src/v1/js/Location.js @@ -165,8 +165,9 @@ const LocationModel = Backbone.Model.extend({ const atWork = (workDistance < 0.10); const atHomeOrWork = (atHome || atWork); const latlong = { 'lat': latitude, 'lon': longitude }; + const latlong4 = { 'lat': Number.parseFloat(latitude).toFixed(4), 'lon': Number.parseFloat(longitude).toFixed(4) }; const ll = `${latitude},${longitude}`; - const llFixed = `${Number.parseFloat(latitude).toFixed(3)},${Number.parseFloat(longitude).toFixed(3)}`; + const llFixed = `${Number.parseFloat(latitude).toFixed(4)},${Number.parseFloat(longitude).toFixed(4)}`; const llSix = `${Number.parseFloat(latitude).toFixed(6)},${Number.parseFloat(longitude).toFixed(6)}`; const llShort = `${Number.parseFloat(latitude).toFixed(1)},${Number.parseFloat(longitude).toFixed(1)}`; const moving = true; @@ -184,6 +185,7 @@ const LocationModel = Backbone.Model.extend({ llFixed, llSix, llShort, + latlong4, moving, latlong, 'city': '', @@ -198,11 +200,8 @@ const LocationModel = Backbone.Model.extend({ console.info('>> Location:geocoder request'); request({ - 'url': `${window.loc}/geocode`, + 'url': `${window.loc}/geocode/${Number.parseFloat(latitude).toFixed(4)}/${Number.parseFloat(longitude).toFixed(4)}`, 'method': 'GET', - 'qs': { - 'll': ll - }, 'json': true }, function(err, res, body) { if (err) @@ -246,11 +245,8 @@ const LocationModel = Backbone.Model.extend({ console.log('>> Moved from previous', sinceLastGeocode, (sinceLastGeocode >= 1.8e+6)); console.info('>> Location:geocoder request'); request({ - 'url': `${window.loc}/geocode`, + 'url': `${window.loc}/geocode/${llFixed.replace(',','/')}`, 'method': 'GET', - 'qs': { - 'll': ll - }, 'json': true }, function(err, res, body) { if (err) diff --git a/src/v1/js/Nearby.js b/src/v1/js/Nearby.js index 10da299..993e0a3 100644 --- a/src/v1/js/Nearby.js +++ b/src/v1/js/Nearby.js @@ -47,12 +47,16 @@ const NearbyModel = Backbone.Model.extend({ this.throttledGetNearby(); }, 'getNearby': function() { - const llFixed = this.get('llFixed'); + const llFixed = this.get('llFixed').replace(',','/'); const hour = parseInt((new Date()).getHours().toString(), 10); const section = this.get('section'); const time = new Date().getTime() ; + const soqval = section; + + const soqtype = "s"; + const lastUpdate = time - (this.get('time') || 0); console.log('>> Nearby section:', hour, section); @@ -60,11 +64,9 @@ const NearbyModel = Backbone.Model.extend({ console.log(`>> Nearby last fetch: ${TimeFormat.fromMs(lastUpdate, 'hh:mm')} ago`); if (lastUpdate > 120000) { - const url = new URL(`${window.loc}/fsexplore`); + const url = new URL(`${window.loc}/fsexplore/${llFixed.replace(',','/')}/${soqval}/${soqtype}/10`); + - url.searchParams.append('ll', llFixed); - url.searchParams.append('section', section); - url.searchParams.append('w', hourFloor()); fetch(url) .then(res => { diff --git a/src/v1/js/NearbyList.js b/src/v1/js/NearbyList.js index dda562b..9edc15d 100644 --- a/src/v1/js/NearbyList.js +++ b/src/v1/js/NearbyList.js @@ -40,6 +40,10 @@ const NearbyListModel = Backbone.Model.extend({ const limit = this.get('limit'); const time = new Date().getTime() ; + const soqval = section || query; + + const soqtype = section ? "s" : "q"; + const lastUpdate = time - (this.get('time') || 0); console.log('>> Nearby section:', hour, section); @@ -49,14 +53,7 @@ const NearbyListModel = Backbone.Model.extend({ // this.fsCollection.reset( null, { 'silent':true }); if (lastUpdate > 120000 || force) { - const _url = new URL(`${window.loc}/fsexplore`); - - _url.search = new URLSearchParams({ - 'll': llFixed, - 'section': section, - 'query':query, - 'limit': limit - }); + const _url = new URL(`${window.loc}/fsexplore/${llFixed.replace(',','/')}/${soqval}/${soqtype}/${limit}`); console.log(_url); diff --git a/src/v1/js/RightByMe.js b/src/v1/js/RightByMe.js index 8b81565..e160112 100644 --- a/src/v1/js/RightByMe.js +++ b/src/v1/js/RightByMe.js @@ -45,11 +45,8 @@ const ByMeModel = Backbone.Model.extend({ // console.log(this.toJSON()); // const section = (partOfDay >= 11 && partOfDay <= 14) ? 'food' : 'topPicks'; request({ - 'url': `${window.loc}/rightbyme`, + 'url': `${window.loc}/rightbyme/${ll.replace(',','/')}`, 'method': 'GET', - 'qs': { - 'll': ll - } }, function(err, res, body) { console.log('statusCode', res.statusCode); if (err) diff --git a/src/v1/js/VenueDetail.js b/src/v1/js/VenueDetail.js index 9fc6bfa..ff1c739 100644 --- a/src/v1/js/VenueDetail.js +++ b/src/v1/js/VenueDetail.js @@ -19,7 +19,7 @@ const VenueDetailModel = Backbone.Model.extend({ 'getVenue': function() { const id = this.get('id'); request({ - 'url': `${window.loc}/nearbydetail`, + 'url': `${window.loc}/nearbydetail/${id}`, 'method': 'GET', 'qs': { 'id': id diff --git a/src/v1/js/Weather.js b/src/v1/js/Weather.js index 1d32265..e2b11f7 100644 --- a/src/v1/js/Weather.js +++ b/src/v1/js/Weather.js @@ -99,12 +99,8 @@ const WeatherModel = Backbone.Model.extend({ console.log('>> Weather request'); const llFixed = this.get('llFixed'); request({ - 'url': `${window.loc}/weather`, + 'url': `${window.loc}/weather/${llFixed.replace(',','/')}`, 'method': 'GET', - 'qs': { - 'll': llFixed, - 'w' : hourFloor() - } }, function(err, res, body) { console.log('statusCode', res.statusCode); if (err) diff --git a/src/v1/js/WeatherAlert.js b/src/v1/js/WeatherAlert.js index a871b76..fcae356 100644 --- a/src/v1/js/WeatherAlert.js +++ b/src/v1/js/WeatherAlert.js @@ -59,12 +59,8 @@ const WeatherAlertModel = Backbone.Model.extend({ console.log('>> WeatherAlert request'); const llFixed = this.get('ll'); request({ - 'url': `${window.loc}/weatheralert`, + 'url': `${window.loc}/weatheralert/${llFixed.replace(',','/')}`, 'method': 'GET', - 'qs': { - 'll': llFixed, - 'w' : hourFloor() - } }, function (err, res, body) { console.log('statusCode', res.statusCode); if (err) diff --git a/src/v1/js/libs/reducers.js b/src/v1/js/libs/reducers.js index b4b4841..aaee7f6 100644 --- a/src/v1/js/libs/reducers.js +++ b/src/v1/js/libs/reducers.js @@ -113,6 +113,38 @@ const reduceEuronews = function(item) { return obj; }; +const reduceForcastToday = function(listArray) { + + const newArray = listArray.map((item) => { + + const fts = new Date(item.time * 1000); + + return { + 'icon': item.icon, + 'temp': item.temp, + 'time': fecha.format(fts, 'HH:mm') + }; + }); + + return newArray.slice(0,24); +} +const reduceForcastDaily = function(listArray) { + + return listArray.map((item) => { + + const fts = new Date(item.time * 1000); + + return { + 'icon': item.icon, + 'tempHigh': item.tempHigh, + 'tempLow': item.tempLow, + 'time': fecha.format(fts, 'dddd') + }; + }); + + + +} /* const pubdateSrc = fecha.parse(item.pubdate, 'ddd, DD MMM YYYY HH:mm:SS ZZ'); const pubdate = fecha.format(pubdateSrc, 'dddd MMMM Do, YYYY'); @@ -126,4 +158,4 @@ const pubdateSrc = fecha.parse(item.pubdate, 'ddd, DD MMM YYYY HH:mm:SS ZZ'); `; */ -module.exports = { reduceOpenWeather, reduceNearby, reduceEuronews, reduceDarksky }; +module.exports = { reduceOpenWeather, reduceNearby, reduceEuronews, reduceDarksky, reduceForcastToday, reduceForcastDaily }; diff --git a/src/v1/js/libs/templates.js b/src/v1/js/libs/templates.js index 394c317..2d538e3 100644 --- a/src/v1/js/libs/templates.js +++ b/src/v1/js/libs/templates.js @@ -73,8 +73,8 @@ const templates = {
<%=summary%>
- + <%=tempMax%>° + <%=tempMin%>°
<%=temperature%>°