Added traffic component

This commit is contained in:
Martin Donnelly 2018-03-14 08:34:16 +00:00
parent df9075f078
commit 9eef9cd8bb
4 changed files with 21 additions and 15 deletions

View File

@ -154,7 +154,7 @@ app.get('/agenda', cache('15 minutes'), (req, res) => {
}); });
}); });
app.get('/traffic', cache('1 hour'), (req, res) => { app.get('/traffic', cache('5 minutes'), (req, res) => {
logger.debug(req.query); logger.debug(req.query);
if (req.query.hasOwnProperty('olat')) { if (req.query.hasOwnProperty('olat')) {

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
const CACHE_VERSION = { 'version': '0.0.378' }; const CACHE_VERSION = { 'version': '0.0.391' };
const dataCacheName = 'jubileeData-v1'; const dataCacheName = 'jubileeData-v1';
const cacheName = 'jubilee-final-1'; const cacheName = 'jubilee-final-1';
const filesToCache = [ const filesToCache = [

View File

@ -80,9 +80,9 @@ const LocationModel = Backbone.Model.extend({
'formatter': null // 'gpx', 'string', ... 'formatter': null // 'gpx', 'string', ...
}; };
const geocoder = NodeGeocoder(options); const geocoder = NodeGeocoder(options);
//55.872407, -3.549003
const homeDistance = distance(55.942673, -4.556334, latitude, longitude); const homeDistance = distance(55.942673, -4.556334, latitude, longitude);
const workDistance = distance(55.861939, -4.259338, latitude, longitude); const workDistance = distance(55.872407, -3.549003, latitude, longitude);
const atHome = (homeDistance < 0.10); const atHome = (homeDistance < 0.10);
const atWork = (workDistance < 0.10); const atWork = (workDistance < 0.10);
const atHomeOrWork = (atHome || atWork); const atHomeOrWork = (atHome || atWork);

View File

@ -26,8 +26,8 @@ const TrafficModel = Backbone.Model.extend({
// ( ((hour >= 7) && (hour <= 9)) || ((hour >= 17) && (hour <= 19)) ) // ( ((hour >= 7) && (hour <= 9)) || ((hour >= 17) && (hour <= 19)) )
// //
console.log('this.updateID', this.updateID); console.log('this.has(\'latlong\')', this.has('latlong'));
if (this.updateID === 0) { if (this.has('latlong')) {
this.updateID = 1; this.updateID = 1;
this.getTraffic(); this.getTraffic();
} }
@ -54,13 +54,18 @@ const TrafficModel = Backbone.Model.extend({
let qs; let qs;
let mode = 0; let mode = 0;
if (!this.has('latlong'))
return;
// 55.872407, -3.549003
// const latlong = { 'lat':latitude, 'lon':longitude }; // const latlong = { 'lat':latitude, 'lon':longitude };
if ((hour >= 7) && (hour <= 9)) { if ((hour >= 7) && (hour <= 9)) {
this.set('dest', 'Work'); this.set('dest', 'Work');
mode = 1; mode = 1;
qs = { qs = {
'olat': latlong.lat, 'olon': latlong.lon, 'dlat': 55.861939, 'dlon': -4.259338 'olat': latlong.lat, 'olon': latlong.lon, 'dlat': 55.872407, 'dlon': -3.549003
}; };
} }
else if ((hour >= 17) && (hour <= 19)) { else if ((hour >= 17) && (hour <= 19)) {
@ -95,7 +100,7 @@ const TrafficModel = Backbone.Model.extend({
} }
}.bind(this)); }.bind(this));
}, 'logUpdate': function() { }, 'logUpdate': function() {
console.log('>> Agenda logging:'); console.log('>> Traffic logging:');
const time = new Date().getTime() ; const time = new Date().getTime() ;
@ -112,22 +117,22 @@ const TrafficView = Backbone.View.extend({
this.location = options.location; this.location = options.location;
this.location.bind('change:llFixed', this.updateLocation, this); this.location.bind('change:llFixed', this.updateLocation, this);
this.model.bind('change:timestamp change:mode', this.render, this); this.model.bind('change:timestamp', this.render, this);
this.model.bind('change:mode', this.render, this);
this.eventBus.on('focused', this.focused, this); this.eventBus.on('focused', this.focused, this);
}, 'focused': function() { }, 'focused': function() {
console.log('>> Traffic received focus msg'); console.log('>> Traffic received focus msg');
console.log(this.model.get('time')); console.log(this.model.get('time'));
if (typeof this.model.get('time') === 'undefined') { if (typeof this.model.get('time') === 'undefined')
return; return;
}
const now = new Date().getTime(); const now = new Date().getTime();
const since = now - this.model.get('time'); const since = now - this.model.get('time');
console.log(`Traffic was last updated: ${TimeFormat.fromMs(since, 'hh:mm')} ago`); console.log(`Traffic was last updated: ${TimeFormat.fromMs(since, 'hh:mm')} ago`);
if (since > (60 * 1000 * 10) ) if (since > (60 * 1000 * 10) )
this.model.set('update', now); this.model.set('update', now);
}, },
'template': _.template(` 'template': _.template(`
<div class=""> <div class="">
@ -148,13 +153,14 @@ const TrafficView = Backbone.View.extend({
console.log('>> Nearby No location yet'); console.log('>> Nearby No location yet');
}, },
'render': function() { 'render': function() {
console.info('>> Traffic:Render'); console.log('>> Traffic:Render');
this.$el.empty(); this.$el.empty();
if (this.model.get('mode') === 0) if (this.model.get('mode') === 0)
this.$el.parent().hide(); this.$el.parent().hide();
else { else
if (this.model.has('readable')) {
console.log(this.template(this.model.attributes)); console.log(this.template(this.model.attributes));
this.$el.html(this.template(this.model.attributes)); this.$el.html(this.template(this.model.attributes));
this.$el.parent().show(); this.$el.parent().show();