Skip to content
This repository was archived by the owner on Aug 16, 2019. It is now read-only.

Commit a71994a

Browse files
author
Matt Conway
committed
Transfers are working. Oddly enough, it didn't take much effort. Still need to do thru-routes so they are rendered correctly. #43 #44.
1 parent 4aba9b1 commit a71994a

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

tbdhotel.js

+44-27
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ com.transitboard.hotel.prototype.showDestination = function (iteration) {
321321
// set up the narrative
322322
var time = 0;
323323
var narr = '';
324+
var isFirstTransitLeg = true; // only the first transit leg should show real-time arrivals
324325
$.each(dest.itinerary.legs, function (ind, leg) {
325326
if (leg.type == 'walk') {
326327
// capitalize first
@@ -334,19 +335,26 @@ com.transitboard.hotel.prototype.showDestination = function (iteration) {
334335
else if (leg.type == 'transit') {
335336
if (ind == 0) var lett = 'B';
336337
else var lett = 'b';
338+
339+
if (isFirstTransitLeg) {
340+
var arrivals = ' <span class="rtarrivals">(next: ' +
341+
// agency is hard-wired for now
342+
instance.formatArrivals(
343+
instance.getRealTimeArrivals(
344+
'TriMet:' + leg.startId,
345+
leg.routeId,
346+
leg.headsign
347+
)
348+
) +
349+
')</span>,';
350+
isFirstTransitLeg = false;
351+
}
352+
// leave them out, just put a comma for grammatical correctness
353+
else var arrivals = ',';
354+
337355
narr += '<span id="narrative-leg-' + ind +
338356
'" class="narrative-leg">' +
339-
lett + 'oard ' + leg.headsign +
340-
' <span class="rtarrivals">(next: ' +
341-
// agency is hard-wired for now
342-
instance.formatArrivals(
343-
instance.getRealTimeArrivals(
344-
'TriMet:' + leg.startId,
345-
leg.routeId,
346-
leg.headsign
347-
)
348-
) +
349-
')</span>,' +
357+
lett + 'oard ' + leg.headsign + arrivals +
350358
' offboard at ' + leg.toPlace +
351359
' (' + leg.noStops + ' stops)' +
352360
'</span>, ';
@@ -786,20 +794,23 @@ com.transitboard.hotel.prototype.getTripPlanOnly = function (dest) {
786794
// loop through the itineraries, find the lowest-cost one
787795
data.find('itinerary').each(function(ind, itin) {
788796
itin = $(itin);
789-
// make sure it fits hard requirements (0 transfers,
790-
// allowed stop), frequent service
791-
// TODO: allowed stop
797+
// make sure it fits hard requirements: allowed stop, frequent service, &c.
798+
799+
/*
792800
if (itin.find('numberOfTransfers').text() != '0') {
793801
console.log('Trip has transfers!');
794802
return true;
795803
}
796-
804+
*/
797805

798806
// We don't handle throughroutes yet (issue 43)
807+
/*
799808
if (Number(itin.find('numberOfTripLegs').text()) > 3) {
800809
console.log('Too many trip legs, probably issue 43!');
801810
return true;
802811
}
812+
*/
813+
// TODO: handle throughroutes when formulating narrative
803814

804815
// route 90 is an alternate number for MAX
805816
// 90: MAX Red Line
@@ -811,15 +822,22 @@ com.transitboard.hotel.prototype.getTripPlanOnly = function (dest) {
811822
'15', '33', '54', '56', '57',
812823
'72', '75', '90', '100', '190', '193',
813824
'200'];
814-
if ($.inArray(itin.find('leg route internalNumber')
815-
.first().text(),
816-
freqService) == -1) {
817-
console.log('route ' +
818-
itin.find('leg route internalNumber')
819-
.first().text() +
820-
' is not Frequent Service');
821-
return true;
822-
}
825+
var isFreqService = true;
826+
itin.find('leg route internalNumber').each(function () {
827+
if ($.inArray($(this).text(), freqService) == -1) {
828+
console.log('route ' +
829+
itin.find('leg route internalNumber')
830+
.first().text() +
831+
' is not Frequent Service');
832+
isFreqService = false;
833+
834+
// no need to check any more
835+
return false;
836+
}
837+
});
838+
839+
// proceed to the next itinerary
840+
if (!isFreqService) return true;
823841

824842
// these two tests are both transfer safe, b/c we only care about restrictions on the first legs
825843
// stop id of this itin
@@ -831,8 +849,7 @@ com.transitboard.hotel.prototype.getTripPlanOnly = function (dest) {
831849
}
832850

833851
// check for allowed route
834-
// it should either be explicitly stated or included with *. We assume that all routes
835-
// TP suggests are also in the real time feed.
852+
// it should either be explicitly stated or included with * in the appliance def
836853
var rid = itin.find('leg route internalNumber').first().text();
837854
if (instance.realTimeArrivals.stopsConfig.TriMet[sid][rid] == undefined &
838855
instance.realTimeArrivals.stopsConfig.TriMet[sid]['*'] == undefined) {
@@ -1188,7 +1205,7 @@ com.transitboard.hotel.prototype.getRealTimeArrivals = function (stopId,
11881205
}
11891206
catch (err) {
11901207
// return an empty arrivalsQueue
1191-
console.log('no arrivals found');
1208+
console.log('no arrivals found for stopId: ' + stopId + ', route ' + route + ', headsign ' + headsign);
11921209
return new arrivalsQueue();
11931210
}
11941211
// in case the headsign does not match

0 commit comments

Comments
 (0)