|
6 | 6 | getRoutingParams, |
7 | 7 | planParamsToQueryAsync |
8 | 8 | } from '@opentripplanner/core-utils/lib/query' |
9 | | -import { isTransit } from '@opentripplanner/core-utils/lib/itinerary' |
| 9 | +import { isTransitLeg } from '@opentripplanner/core-utils/lib/itinerary' |
10 | 10 | import { |
11 | 11 | OTP_API_DATE_FORMAT, |
12 | 12 | OTP_API_TIME_FORMAT |
@@ -395,36 +395,34 @@ function makeSaveFieldTripItinerariesData(request, outbound, state) { |
395 | 395 | } |
396 | 396 |
|
397 | 397 | const gtfsTripsForItinerary = [] |
398 | | - itinerary.legs |
399 | | - .filter((leg) => isTransit(leg.mode)) |
400 | | - .forEach((leg) => { |
401 | | - let routeName = leg.routeShortName ? `(${leg.routeShortName}) ` : '' |
402 | | - routeName = `${routeName}${leg.routeLongName}` |
403 | | - const gtfsTrip = { |
404 | | - agencyAndId: leg.tripId, |
405 | | - // 'arrive' must be expressed in the agency's timezone |
406 | | - arrive: formatInTz(new Date(leg.endTime), FIELD_TRIP_TIME_FORMAT, { |
407 | | - timeZone: homeTimezone |
408 | | - }), |
409 | | - capacity: getFieldTripGroupCapacityForMode( |
410 | | - fieldTripModuleConfig, |
411 | | - leg.mode |
412 | | - ), |
413 | | - // 'depart' must be expressed in the agency's timezone |
414 | | - depart: formatInTz(new Date(leg.startTime), FIELD_TRIP_TIME_FORMAT, { |
415 | | - timeZone: homeTimezone |
416 | | - }), |
417 | | - fromStopIndex: leg.from.stopIndex, |
418 | | - fromStopName: leg.from.name, |
419 | | - headsign: leg.headsign, |
420 | | - routeName, |
421 | | - toStopIndex: leg.to.stopIndex, |
422 | | - toStopName: leg.to.name, |
423 | | - tripHash: tripHashLookup[leg.tripId] |
424 | | - } |
425 | | - if (leg.tripBlockId) gtfsTrip.blockId = leg.tripBlockId |
426 | | - gtfsTripsForItinerary.push(gtfsTrip) |
427 | | - }) |
| 398 | + itinerary.legs.filter(isTransitLeg).forEach((leg) => { |
| 399 | + let routeName = leg.routeShortName ? `(${leg.routeShortName}) ` : '' |
| 400 | + routeName = `${routeName}${leg.routeLongName}` |
| 401 | + const gtfsTrip = { |
| 402 | + agencyAndId: leg.tripId, |
| 403 | + // 'arrive' must be expressed in the agency's timezone |
| 404 | + arrive: formatInTz(new Date(leg.endTime), FIELD_TRIP_TIME_FORMAT, { |
| 405 | + timeZone: homeTimezone |
| 406 | + }), |
| 407 | + capacity: getFieldTripGroupCapacityForMode( |
| 408 | + fieldTripModuleConfig, |
| 409 | + leg.mode |
| 410 | + ), |
| 411 | + // 'depart' must be expressed in the agency's timezone |
| 412 | + depart: formatInTz(new Date(leg.startTime), FIELD_TRIP_TIME_FORMAT, { |
| 413 | + timeZone: homeTimezone |
| 414 | + }), |
| 415 | + fromStopIndex: leg.from.stopIndex, |
| 416 | + fromStopName: leg.from.name, |
| 417 | + headsign: leg.headsign, |
| 418 | + routeName, |
| 419 | + toStopIndex: leg.to.stopIndex, |
| 420 | + toStopName: leg.to.name, |
| 421 | + tripHash: tripHashLookup[leg.tripId] |
| 422 | + } |
| 423 | + if (leg.tripBlockId) gtfsTrip.blockId = leg.tripBlockId |
| 424 | + gtfsTripsForItinerary.push(gtfsTrip) |
| 425 | + }) |
428 | 426 |
|
429 | 427 | data.itins.push(itineraryDataToSave) |
430 | 428 | data.gtfsTrips.push(gtfsTripsForItinerary) |
@@ -616,7 +614,6 @@ function getMissingTripHashesForActiveItineraries() { |
616 | 614 | }) |
617 | 615 | ) |
618 | 616 | } |
619 | | - return true |
620 | 617 | } |
621 | 618 |
|
622 | 619 | /** |
@@ -712,52 +709,50 @@ function checkValidityAndCapacity(state, request) { |
712 | 709 |
|
713 | 710 | // check each individual trip to see if there aren't any trips in this |
714 | 711 | // itinerary that are already in use by another field trip |
715 | | - itinerary.legs |
716 | | - .filter((leg) => isTransit(leg.mode)) |
717 | | - .forEach((leg) => { |
718 | | - const tripId = leg?.trip?.gtfsId |
719 | | - |
720 | | - // this variable is used to track how many other field trips are using a |
721 | | - // particular trip |
722 | | - let capacityInUse = 0 |
723 | | - |
724 | | - // iterate over trips that are already being used by other field trips |
725 | | - // NOTE: In the use case of re-planning trips, there is currently no way |
726 | | - // to discern whether a tripInUse belongs to the current direction of |
727 | | - // the field trip being planned. Therefore, this will result in the |
728 | | - // re-planning of trips avoiding it's own previously planned trips |
729 | | - // that it currently has saved |
730 | | - travelDateTripsInUse.forEach((tripInUse) => { |
731 | | - if (!tripsOverlap(leg, tripHashLookup, tripId, tripInUse)) return |
732 | | - |
733 | | - // ranges overlap! Add number of passengers on this other field trip |
734 | | - // to total capacity in use |
735 | | - capacityInUse += tripInUse.passengers |
736 | | - }) |
| 712 | + itinerary.legs.filter(isTransitLeg).forEach((leg) => { |
| 713 | + const tripId = leg?.trip?.gtfsId |
| 714 | + |
| 715 | + // this variable is used to track how many other field trips are using a |
| 716 | + // particular trip |
| 717 | + let capacityInUse = 0 |
| 718 | + |
| 719 | + // iterate over trips that are already being used by other field trips |
| 720 | + // NOTE: In the use case of re-planning trips, there is currently no way |
| 721 | + // to discern whether a tripInUse belongs to the current direction of |
| 722 | + // the field trip being planned. Therefore, this will result in the |
| 723 | + // re-planning of trips avoiding it's own previously planned trips |
| 724 | + // that it currently has saved |
| 725 | + travelDateTripsInUse.forEach((tripInUse) => { |
| 726 | + if (!tripsOverlap(leg, tripHashLookup, tripId, tripInUse)) return |
| 727 | + |
| 728 | + // ranges overlap! Add number of passengers on this other field trip |
| 729 | + // to total capacity in use |
| 730 | + capacityInUse += tripInUse.passengers |
| 731 | + }) |
737 | 732 |
|
738 | | - // check if the remaining capacity on this trip is enough to allow more |
739 | | - // field trip passengers on board |
740 | | - const legModeCapacity = getFieldTripGroupCapacityForMode( |
741 | | - fieldTripModuleConfig, |
742 | | - leg.mode |
743 | | - ) |
744 | | - let remainingTripCapacity = legModeCapacity - capacityInUse |
745 | | - if (remainingTripCapacity < minimumAllowableRemainingCapacity) { |
746 | | - // This trip is already too "full" to allow any addition field trips |
747 | | - // on board. Ban this trip in future searches and don't use this |
748 | | - // itinerary in final results (set trip and itinerary capacity to 0). |
749 | | - remainingTripCapacity = 0 |
750 | | - } |
| 733 | + // check if the remaining capacity on this trip is enough to allow more |
| 734 | + // field trip passengers on board |
| 735 | + const legModeCapacity = getFieldTripGroupCapacityForMode( |
| 736 | + fieldTripModuleConfig, |
| 737 | + leg.mode |
| 738 | + ) |
| 739 | + let remainingTripCapacity = legModeCapacity - capacityInUse |
| 740 | + if (remainingTripCapacity < minimumAllowableRemainingCapacity) { |
| 741 | + // This trip is already too "full" to allow any addition field trips |
| 742 | + // on board. Ban this trip in future searches and don't use this |
| 743 | + // itinerary in final results (set trip and itinerary capacity to 0). |
| 744 | + remainingTripCapacity = 0 |
| 745 | + } |
751 | 746 |
|
752 | | - // always ban trips found in itineraries so that subsequent searches |
753 | | - // don't encounter them. |
754 | | - // TODO: a more advanced way of doing things might be to ban trip |
755 | | - // sequences to not find the same exact sequence, but also |
756 | | - // individual trips that are too full. |
757 | | - tripsToBanInSubsequentSearches.push(tripId) |
| 747 | + // always ban trips found in itineraries so that subsequent searches |
| 748 | + // don't encounter them. |
| 749 | + // TODO: a more advanced way of doing things might be to ban trip |
| 750 | + // sequences to not find the same exact sequence, but also |
| 751 | + // individual trips that are too full. |
| 752 | + tripsToBanInSubsequentSearches.push(tripId) |
758 | 753 |
|
759 | | - itineraryCapacity = Math.min(itineraryCapacity, remainingTripCapacity) |
760 | | - }) |
| 754 | + itineraryCapacity = Math.min(itineraryCapacity, remainingTripCapacity) |
| 755 | + }) |
761 | 756 |
|
762 | 757 | if (itineraryCapacity > 0) { |
763 | 758 | // itinerary has capacity, add to list and update remaining group size. |
|
0 commit comments