This commit is contained in:
Martin Donnelly 2024-02-26 13:41:59 +00:00
parent ae314b0c2c
commit d994268317
10 changed files with 81 additions and 46 deletions

View File

@ -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('<div class="">');
@ -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('</div>');
html.push('<div class="endbumper"></div>');

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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');
</article>`;
*/
module.exports = { reduceOpenWeather, reduceNearby, reduceEuronews, reduceDarksky };
module.exports = { reduceOpenWeather, reduceNearby, reduceEuronews, reduceDarksky, reduceForcastToday, reduceForcastDaily };

View File

@ -73,8 +73,8 @@ const templates = {
<div class="forecastCurrently mui-panel glassy">
<div class="mui--text-title"><i class="medium wi wi-forecast-io-<%= icon %>"></i> <%=summary%></div>
<div>
<!-- <i class="small fa fa-up mui&#45;&#45;align-middle " ></i><%=tempMax%>°
<i class="small fa fa-down mui&#45;&#45;align-middle " ></i><%=tempMin%>°-->
<i class="small fa fa-up mui--align-middle " ></i><%=tempMax%>°
<i class="small fa fa-down mui--align-middle " ></i><%=tempMin%>°
</div>
<div class="large temp<%=~~(temperature) %>"><%=temperature%>°</div>
</div>