Comparing version 0.1.1 to 0.2.0
@@ -18,7 +18,8 @@ 'use strict'; | ||
// Use flatMap to flatten other observables | ||
// Use flatMapLatest to flatten other observables and only take the most | ||
// recently | ||
var trimetRequest$ = Rx.Observable | ||
.interval(60000) | ||
.startWith('') | ||
.flatMap(function() { | ||
.flatMapLatest(function() { | ||
return rxHttp.getJson$(BASE_URL, { | ||
@@ -41,2 +42,3 @@ locIDs: opts.stop | ||
date: moment(a.estimated || a.scheduled), | ||
scheduled: moment(a.scheduled), | ||
route: a.route | ||
@@ -111,3 +113,14 @@ }; | ||
var footer = minDiff.toString() + ' min'; | ||
var minutesOffSchedule = a.scheduled.diff(a.date, 'minutes', true); | ||
var onTimeMsg = Math.abs(minutesOffSchedule).toFixed(1) + ' mins '; | ||
var scheduledFormatted = a.scheduled.format('HH:mm'); | ||
if (minutesOffSchedule === 0) { | ||
onTimeMsg = 'on time'; | ||
} else if (minutesOffSchedule > 0) { | ||
onTimeMsg += 'ahead of ' + scheduledFormatted + ' schedule'; | ||
} else if (minutesOffSchedule < 0) { | ||
onTimeMsg += 'behind ' + scheduledFormatted + ' schedule'; | ||
} | ||
timelineHeader = u.replaceAt(timelineHeader, scale, header); | ||
@@ -117,3 +130,9 @@ timeline = u.replaceAt(timeline, scale, '|'); | ||
u.log(' #%s arriving %s at %s', a.route, a.date.fromNow(), a.date.format('HH:mm')); | ||
u.log( | ||
' #%s arriving %s at %s (%s)', | ||
a.route, | ||
a.date.fromNow(), | ||
a.date.format('HH:mm'), | ||
onTimeMsg | ||
); | ||
}); | ||
@@ -120,0 +139,0 @@ |
{ | ||
"name": "busseur", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A TriMet CLI tool", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -52,5 +52,7 @@ /*eslint no-underscore-dangle:0 */ | ||
assert.equal(strip(uMock.log.getCall(0).args[0]), 'grrggl refreshed at 16:00'); | ||
assert.equal(strip(uMock.log.getCall(1).args[0]), ' #%s arriving %s at %s'); | ||
assert.equal(strip(uMock.log.getCall(1).args[0]), ' #%s arriving %s at %s (%s)'); | ||
assert.equal(strip(uMock.log.getCall(1).args[1]), '35'); | ||
assert.equal(strip(uMock.log.getCall(1).args[2]), 'in 45 years'); | ||
assert.equal(strip(uMock.log.getCall(1).args[3]), '04:59'); | ||
assert.equal(strip(uMock.log.getCall(1).args[4]), 'on time'); | ||
@@ -64,5 +66,7 @@ observer.dispose(); | ||
assert.equal(strip(uMock.log.getCall(0).args[0]), '6376 refreshed at 16:00'); | ||
assert.equal(strip(uMock.log.getCall(1).args[0]), ' #%s arriving %s at %s'); | ||
assert.equal(strip(uMock.log.getCall(1).args[0]), ' #%s arriving %s at %s (%s)'); | ||
assert.equal(strip(uMock.log.getCall(1).args[1]), '35'); | ||
assert.equal(strip(uMock.log.getCall(1).args[2]), 'in 45 years'); | ||
assert.equal(strip(uMock.log.getCall(1).args[3]), '04:59'); | ||
assert.equal(strip(uMock.log.getCall(1).args[4]), 'on time'); | ||
@@ -69,0 +73,0 @@ observer.dispose(); |
Sorry, the diff of this file is not supported yet
80921
403