Skip to content

Commit d2c7ca3

Browse files
authored
Merge pull request #5712 from HSLdevcom/AB#44-next
AB#238 - Add least transfer filtering for flex
2 parents f1ce885 + 76f0bc8 commit d2c7ca3

19 files changed

Lines changed: 132 additions & 67 deletions

app/component/itinerary/CallAgencyLeg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const CallAgencyLeg = (
3535
withBar
3636
isTransitLeg
3737
text={leg.route && leg.route.shortName}
38-
appendClass={isLocalCallAgency(leg.route, config) ? 'call-local' : ''}
38+
appendClass={isLocalCallAgency(leg, config) ? 'call-local' : ''}
3939
/>
4040
);
4141
return (

app/component/itinerary/Itinerary.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function RouteLeg(
127127
occupancyStatus={getOccupancyStatus()}
128128
duration={Math.floor(leg.duration / 60)}
129129
shortenLongText={shortenLabels}
130-
appendClass={isLocalCallAgency(leg.route, config) ? 'call-local' : ''}
130+
appendClass={isLocalCallAgency(leg, config) ? 'call-local' : ''}
131131
/>
132132
);
133133
return (
@@ -195,7 +195,7 @@ export const ModeLeg = (
195195
vertical
196196
withBar
197197
icon={networkIcon || icon}
198-
appendClass={isLocalCallAgency(leg.route, config) ? 'call-local' : ''}
198+
appendClass={isLocalCallAgency(leg, config) ? 'call-local' : ''}
199199
{...getLegBadgeProps(leg, config)}
200200
/>
201201
);
@@ -631,9 +631,7 @@ const Itinerary = (
631631
const iconLegsInPixels = (24 * onlyIconLegs) / normalLegs;
632632
// the leftover percentage from only showing icons added to each 'normal' leg
633633
const iconLegsInPercents = onlyIconLegsLength / normalLegs;
634-
const hasCallAgencyLeg = itinerary.legs.some(leg =>
635-
isCallAgencyLeg(leg.route),
636-
);
634+
const hasCallAgencyLeg = itinerary.legs.some(leg => isCallAgencyLeg(leg));
637635
let firstDeparture;
638636
if (hasCallAgencyLeg) {
639637
firstLegStartTime = (
@@ -820,7 +818,6 @@ const Itinerary = (
820818
</div>
821819
);
822820
}
823-
824821
const co2summary = (
825822
<div className="sr-only">
826823
<FormattedMessage

app/component/itinerary/ItineraryDetails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function ItineraryDetails(
200200
callAgencyInfo &&
201201
itinerary.legs.some(
202202
leg =>
203-
isCallAgencyLeg(leg.route) &&
203+
isCallAgencyLeg(leg) &&
204204
!config.flex.internalAgencies.includes(leg.route.agency.gtfsId),
205205
)
206206
) {

app/component/itinerary/ItineraryPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ export default function ItineraryPage(props, context) {
13051305
: props.mapLayerOptions;
13061306

13071307
const flexLeg = planEdges?.[activeIndex]?.node.legs.find(leg =>
1308-
isCallAgencyLeg(leg.route),
1308+
isCallAgencyLeg(leg),
13091309
);
13101310
const updatedMapLayers = { ...props.mapLayers };
13111311
const flexRouteGtfsId = flexLeg?.route?.gtfsId.split(':')[0];

app/component/itinerary/ItineraryPageUtils.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
import { PlannerMessageType, ExtendedRouteTypes } from '../../constants';
1212
import { addAnalyticsEvent } from '../../util/analyticsUtils';
1313
import { boundWithMinimumArea } from '../../util/geo-utils';
14-
import { compressLegs, getTotalBikingDistance } from '../../util/legUtils';
14+
import {
15+
compressLegs,
16+
getTotalBikingDistance,
17+
getTotalTransitLegsInExternalFlexTransitItinerary,
18+
getTotalTransitLegsInInternalFlexTransitItinerary,
19+
} from '../../util/legUtils';
1520
import { getMapLayerOptions } from '../../util/mapLayerUtils';
1621
import { getDefaultSettings, getSettings } from '../../util/planParamUtil';
1722
import { getStartTimeWithColon } from '../../util/timeUtils';
@@ -373,6 +378,7 @@ export function scooterEdges(edges, allowDirectScooterJourneys) {
373378

374379
return filteredEdges;
375380
}
381+
376382
/** Filters away itineraries that are not flex */
377383
export function flexEdges(edges) {
378384
if (!edges) {
@@ -409,9 +415,6 @@ export function filterItineraries(edges, modes) {
409415
);
410416
}
411417

412-
/**
413-
* Filters itineraries that are not the right route type
414-
*/
415418
export function filterItinerariesByRouteType(
416419
edges,
417420
types,
@@ -429,6 +432,28 @@ export function filterItinerariesByRouteType(
429432
);
430433
}
431434

435+
/**
436+
* This function filters away itineraries that have a greater count than the
437+
* itinerary with the lowest count. The count is determined by the countFunction.
438+
*/
439+
export function filterItinerariesKeepOnlyLeastCount(edges, countFunction) {
440+
if (!edges || edges.length === 0) {
441+
return [];
442+
}
443+
444+
let leastAmountOfTransitLegs = countFunction(edges[0].node);
445+
edges.forEach(edge => {
446+
const amountOfTransitLegs = countFunction(edge.node);
447+
if (leastAmountOfTransitLegs > amountOfTransitLegs) {
448+
leastAmountOfTransitLegs = amountOfTransitLegs;
449+
}
450+
});
451+
452+
return edges.filter(
453+
edge => countFunction(edge.node) === leastAmountOfTransitLegs,
454+
);
455+
}
456+
432457
/**
433458
* Pick combination of itineraries for bike and transit
434459
*/
@@ -564,10 +589,13 @@ export function mergeExternalTransitPlan(
564589
allowedExternalFlexRouteTypes,
565590
includeTaxiSuggestions,
566591
) {
567-
const externalTransitEdges = filterItinerariesByRouteType(
568-
externalPlan.edges,
569-
allowedExternalFlexRouteTypes,
570-
includeTaxiSuggestions,
592+
const externalTransitEdges = filterItinerariesKeepOnlyLeastCount(
593+
filterItinerariesByRouteType(
594+
externalPlan.edges,
595+
allowedExternalFlexRouteTypes,
596+
includeTaxiSuggestions,
597+
),
598+
getTotalTransitLegsInExternalFlexTransitItinerary,
571599
);
572600
return sortAndMergePlans(externalTransitEdges, transitPlan, arriveBy);
573601
}
@@ -595,7 +623,10 @@ export function mergeFlexPlan(
595623
arriveBy,
596624
maxAdditionalEdges = 1,
597625
) {
598-
const edges = flexEdges(flexPlan.edges);
626+
const edges = filterItinerariesKeepOnlyLeastCount(
627+
flexEdges(flexPlan.edges),
628+
getTotalTransitLegsInInternalFlexTransitItinerary,
629+
);
599630
return sortAndMergePlans(edges, plan, arriveBy, maxAdditionalEdges);
600631
}
601632

app/component/itinerary/LegInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function LegInfo(
6262
withBar
6363
fadeLong
6464
isTransitLeg={isTransitLeg}
65-
appendClass={isLocalCallAgency(leg.route, config) ? 'call-local' : ''}
65+
appendClass={isLocalCallAgency(leg, config) ? 'call-local' : ''}
6666
/>
6767
</span>
6868
);

app/component/itinerary/TransitLeg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class TransitLeg extends React.Component {
505505
}
506506
viaType={leg.from.viaLocationType}
507507
isStop={!!leg.from.stop}
508-
appendClass={isLocalCallAgency(leg.route, config) ? 'call-local' : ''}
508+
appendClass={isLocalCallAgency(leg, config) ? 'call-local' : ''}
509509
/>
510510
<div
511511
style={{

app/component/itinerary/WalkLeg.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { displayDistance } from '../../util/geo-utils';
2727
import { durationToString } from '../../util/timeUtils';
2828
import { splitStringToAddressAndPlace } from '../../util/otpStrings';
2929
import VehicleRentalLeg from './VehicleRentalLeg';
30+
import { useConfigContext } from '../../configurations/ConfigContext';
3031
import IndoorInfo from './IndoorInfo';
3132
import {
3233
subwayTransferUsesSameStation,
@@ -38,7 +39,6 @@ import {
3839
} from '../../util/indoorUtils';
3940
import IndoorStep from './IndoorStep';
4041
import { IndoorLegType } from '../../constants';
41-
import { useConfigContext } from '../../configurations/ConfigContext';
4242

4343
function WalkLeg(
4444
{
@@ -54,13 +54,13 @@ function WalkLeg(
5454
},
5555
{ intl },
5656
) {
57+
const config = useConfigContext();
58+
const { colors, emphasizeDistance } = config;
5759
// If there is only one indoor routing step, always show it.
5860
const [showIntermediateSteps, setShowIntermediateSteps] = useState(
5961
getIndoorStepsWithVerticalTransportation(previousLeg, leg, nextLeg)
6062
.length === 1,
6163
);
62-
const config = useConfigContext();
63-
const { colors, emphasizeDistance } = config;
6464
const distance = displayDistance(
6565
parseInt(leg.mode !== 'WALK' ? 0 : leg.distance, 10),
6666
config,
@@ -154,7 +154,7 @@ function WalkLeg(
154154
/>
155155
</span>
156156
<div className="small-2 columns itinerary-time-column" aria-hidden="true">
157-
{previousLeg && isCallAgencyLeg(previousLeg.route) && (
157+
{previousLeg && isCallAgencyLeg(previousLeg) && (
158158
<FormattedMessage id="estimate" />
159159
)}
160160
<div className="itinerary-time-column-time">

app/component/itinerary/navigator/NaviCardExtension.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ const NaviCardExtension = (
4545
const { code, platformCode, zoneId, vehicleMode } = stop || {};
4646
const [place, address] = name?.split(/, (.+)/) || [];
4747

48-
const isLocalCall = isLocalCallAgency(nextLeg?.route, config);
48+
const isLocalCall = isLocalCallAgency(nextLeg, config);
4949
const appendClass = isLocalCall ? 'call-local' : '';
5050
const callAgencyDestination =
51-
nextLeg && (isLocalCall || isCallAgencyLeg(nextLeg.route));
51+
nextLeg && (isLocalCall || isCallAgencyLeg(nextLeg));
5252

5353
let destination = {};
5454
if (stop && !callAgencyDestination) {

app/component/itinerary/navigator/NaviInstructions.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export default function NaviInstructions(
5555
time,
5656
config,
5757
);
58-
const appendClass = isLocalCallAgency(nextLeg?.route, config)
59-
? 'call-local'
60-
: '';
58+
const appendClass = isLocalCallAgency(nextLeg, config) ? 'call-local' : '';
6159
if (legType === LEGTYPE.MOVE) {
6260
return (
6361
<>

0 commit comments

Comments
 (0)