Skip to content

Commit 2067202

Browse files
Merge pull request #1469 from opentripplanner/remove-otp1-fields
Remove most unused OTP1 fields
2 parents 0dbc5e0 + 56b439c commit 2067202

File tree

7 files changed

+837
-164
lines changed

7 files changed

+837
-164
lines changed

__tests__/util/itinerary.ts

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,34 @@ describe('util > itinerary', () => {
2424
}
2525
const rentalCarLeg = {
2626
mode: 'CAR_RENT',
27-
rentedCar: true
27+
// Note: OTP2 sets rentedBike to true for all rented vehicles, including rented cars.
28+
rentedBike: true
2829
}
2930
const rentalMicromobilityLeg = {
3031
mode: 'MICROMOBILITY_RENT',
31-
rentedVehicle: true
32+
// Note: OTP2 sets rentedBike to true for all rented vehicles, including rented scooters.
33+
rentedBike: true
3234
}
3335
const rideHailLeg = {
34-
hailedCar: true,
35-
mode: 'CAR_HAIL'
36+
mode: 'CAR_HAIL',
37+
rideHailingEstimate: {
38+
arrival: 'PT4M',
39+
maxPrice: {
40+
amount: 19,
41+
currency: {
42+
code: 'USD'
43+
}
44+
},
45+
minPrice: {
46+
amount: 17,
47+
currency: {
48+
code: 'USD'
49+
}
50+
},
51+
provider: {
52+
id: 'ride-hail-platform'
53+
}
54+
}
3655
}
3756

3857
const testCases = [
@@ -66,7 +85,7 @@ describe('util > itinerary', () => {
6685
legs: [walkLeg, rentalBikeLeg]
6786
},
6887
title:
69-
'should be true for an itinerary without transit and without rentals.'
88+
'should be false for an itinerary without transit and with a rented bike.'
7089
},
7190
{
7291
expected: false,
@@ -116,73 +135,34 @@ describe('util > itinerary', () => {
116135
})
117136
})
118137
describe('getItineraryDefaultMonitoredDays', () => {
119-
const transitLegWeekday = {
120-
mode: 'BUS',
121-
serviceDate: '20210609', // Wednesday
122-
transitLeg: true
123-
}
124-
const transitLegSaturday = {
125-
mode: 'BUS',
126-
serviceDate: '20210612', // Saturday
127-
transitLeg: true
128-
}
129-
const transitLegSunday = {
130-
mode: 'BUS',
131-
serviceDate: '20210613', // Sunday
132-
transitLeg: true
133-
}
138+
const THURSDAY_20210610_1218_EDT = 1623341891000
139+
const SATURDAY_20210612_1218_EDT = 1623514691000
140+
const SUNDAY_20210613_1218_EDT = 1623601091000
134141

135142
const testCases = [
136143
{
137144
expected: WEEKDAYS,
138145
itinerary: {
139-
legs: [walkLeg, transitLegWeekday]
146+
startTime: THURSDAY_20210610_1218_EDT
140147
},
141148
title:
142149
"should be ['monday' thru 'friday'] for an itinerary starting on a weekday."
143150
},
144151
{
145152
expected: WEEKEND_DAYS,
146153
itinerary: {
147-
legs: [walkLeg, transitLegSaturday]
154+
startTime: SATURDAY_20210612_1218_EDT
148155
},
149156
title:
150157
"should be ['saturday', 'sunday'] for an itinerary starting on a Saturday."
151158
},
152159
{
153160
expected: WEEKEND_DAYS,
154161
itinerary: {
155-
legs: [walkLeg, transitLegSunday]
162+
startTime: SUNDAY_20210613_1218_EDT
156163
},
157164
title:
158165
"should be ['saturday', 'sunday'] for an itinerary starting on a Sunday."
159-
},
160-
{
161-
expected: WEEKDAYS,
162-
itinerary: {
163-
legs: [walkLeg],
164-
startTime: 1623341891000 // Thursday 2021-06-10 12:18 pm EDT
165-
},
166-
title:
167-
"should be ['monday' thru 'friday'] for an itinerary without transit starting on a weekday (fallback case)."
168-
},
169-
{
170-
expected: WEEKEND_DAYS,
171-
itinerary: {
172-
legs: [walkLeg],
173-
startTime: 1623514691000 // Saturday 2021-06-12 12:18 pm EDT
174-
},
175-
title:
176-
"should be ['saturday', 'sunday'] for an itinerary without transit starting on a Saturday (fallback case)."
177-
},
178-
{
179-
expected: WEEKEND_DAYS,
180-
itinerary: {
181-
legs: [walkLeg],
182-
startTime: 1623601091000 // Sunday 2021-06-13 12:18 pm EDT
183-
},
184-
title:
185-
"should be ['saturday', 'sunday'] for an itinerary without transit starting on a Sunday (fallback case)."
186166
}
187167
]
188168

a11y/mocks/plan.json

Lines changed: 787 additions & 1 deletion
Large diffs are not rendered by default.

lib/actions/plan.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import { toDate, utcToZonedTime } from 'date-fns-tz'
77

88
import { getActiveItineraries, getActiveItinerary } from '../util/state'
9-
import { getFirstStopId } from '../util/itinerary'
109
import { getServiceStart, SERVICE_BREAK } from '../util/api'
1110

1211
import { routingQuery } from './api'
@@ -41,20 +40,12 @@ function getActiveItineraryOrFirstFound(state) {
4140
* Shifts the planning start/end date/time to the specified values.
4241
*/
4342
function shiftPlan(departArrive, zonedDate, time, itinerary) {
44-
return function (dispatch, getState) {
45-
const state = getState()
46-
const { api } = state.otp.config
43+
return function (dispatch) {
4744
const params = {
4845
date: format(zonedDate, OTP_API_DATE_FORMAT),
4946
departArrive,
5047
time
5148
}
52-
if (!api?.v2) {
53-
if (!itinerary) {
54-
itinerary = getActiveItineraryOrFirstFound(state)
55-
}
56-
params.startTransitStopId = getFirstStopId(itinerary)
57-
}
5849
dispatch(updateParamsAndPlan(params))
5950
}
6051
}

lib/components/narrative/save-trip-button.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Ban } from '@styled-icons/fa-solid/Ban'
22
import { connect } from 'react-redux'
33
import { FormattedMessage, useIntl } from 'react-intl'
4+
import { Itinerary } from '@opentripplanner/types'
45
import { Lock } from '@styled-icons/fa-solid/Lock'
56
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
67
import { PlusCircle } from '@styled-icons/fa-solid/PlusCircle'
@@ -10,16 +11,13 @@ import { AppReduxState } from '../../util/state-types'
1011
import { CREATE_TRIP_PATH } from '../../util/constants'
1112
import { getActiveItinerary } from '../../util/state'
1213
import { IconWithText } from '../util/styledIcon'
13-
import {
14-
itineraryCanBeMonitored,
15-
ItineraryWithOtp1HailedCar
16-
} from '../../util/itinerary'
14+
import { itineraryCanBeMonitored } from '../../util/itinerary'
1715
import { PersistenceConfig } from '../../util/config-types'
1816
import { UnstyledLink } from '../user/styled'
1917
import { User } from '../user/types'
2018

2119
interface Props {
22-
itinerary?: ItineraryWithOtp1HailedCar
20+
itinerary?: Itinerary
2321
loggedInUser?: User
2422
persistence?: PersistenceConfig
2523
}
@@ -106,7 +104,7 @@ const SaveTripButton = ({
106104
const mapStateToProps = (state: AppReduxState) => {
107105
const { persistence } = state.otp.config
108106
return {
109-
itinerary: getActiveItinerary(state) as ItineraryWithOtp1HailedCar,
107+
itinerary: getActiveItinerary(state) as Itinerary,
110108
loggedInUser: state.user.loggedInUser,
111109
persistence
112110
}

lib/util/itinerary.tsx

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Place
77
} from '@opentripplanner/types'
88
import { isTransitLeg } from '@opentripplanner/core-utils/lib/itinerary'
9-
import { toDate, utcToZonedTime } from 'date-fns-tz'
9+
import { utcToZonedTime } from 'date-fns-tz'
1010
import coreUtils from '@opentripplanner/core-utils'
1111
import hash from 'object-hash'
1212
import memoize from 'lodash.memoize'
@@ -21,15 +21,6 @@ export interface ItineraryStartTime {
2121
realtime: boolean
2222
}
2323

24-
// FIXME: replace with OTP2 logic.
25-
interface LegWithOtp1HailedCar extends Leg {
26-
hailedCar?: boolean
27-
}
28-
29-
export interface ItineraryWithOtp1HailedCar extends Itinerary {
30-
legs: LegWithOtp1HailedCar[]
31-
}
32-
3324
interface OtpResponse {
3425
plan: {
3526
itineraries: Itinerary[]
@@ -69,14 +60,11 @@ interface RelaxedFareProductSelector {
6960
* @returns true if an itinerary has no rental or ride hail leg (e.g. CAR_RENT, CAR_HAIL, BICYCLE_RENT, etc.).
7061
* (We use the corresponding fields returned by OTP to get transit legs and rental/ride hail legs.)
7162
*/
72-
export function itineraryCanBeMonitored(
73-
itinerary?: ItineraryWithOtp1HailedCar
74-
): boolean {
63+
export function itineraryCanBeMonitored(itinerary?: Itinerary): boolean {
7564
return (
7665
!!itinerary?.legs &&
7766
!itinerary.legs.some(
78-
(leg: LegWithOtp1HailedCar) =>
79-
leg.rentedBike || leg.rentedCar || leg.rentedVehicle || leg.hailedCar
67+
(leg: Leg) => leg.rentedBike || !!leg.rideHailingEstimate
8068
)
8169
)
8270
}
@@ -85,43 +73,19 @@ export function getMinutesUntilItineraryStart(itinerary: Itinerary): number {
8573
return differenceInMinutes(new Date(itinerary.startTime), new Date())
8674
}
8775

88-
/**
89-
* Gets the first transit leg of the given itinerary, or null if none found.
90-
*/
91-
function getFirstTransitLeg(itinerary: Itinerary) {
92-
return itinerary?.legs?.find(isTransitLeg)
93-
}
94-
95-
/**
96-
* Get the first stop ID from the itinerary in the underscore format required by
97-
* the startTransitStopId query param (e.g., TRIMET_12345 instead of TRIMET:12345).
98-
*/
99-
export function getFirstStopId(itinerary: Itinerary): string | undefined {
100-
return getFirstTransitLeg(itinerary)?.from.stopId?.replace(':', '_')
101-
}
102-
10376
/**
10477
* Returns the set of monitored days that will be initially shown to the user
10578
* for the given itinerary.
10679
* @param itinerary The itinerary from which the default monitored days are extracted.
107-
* @returns ['monday' thru 'friday'] if itinerary happens on a weekday(*),
108-
* ['saturday', 'sunday'] if itinerary happens on a saturday/sunday(*).
109-
* (*) For transit itineraries, the first transit leg is used to make
110-
* the determination. Otherwise, the itinerary startTime is used.
80+
* @returns ['monday' thru 'friday'] if itinerary happens on a weekday,
81+
* ['saturday', 'sunday'] if itinerary happens on a saturday/sunday,
82+
* based on the itinerary startTime.
11183
*/
11284
export function getItineraryDefaultMonitoredDays(
11385
itinerary: Itinerary,
11486
timeZone = coreUtils.time.getUserTimezone()
11587
): string[] {
116-
const firstTransitLeg = getFirstTransitLeg(itinerary)
117-
// firstTransitLeg should be non-null because only transit trips can be monitored at this time.
118-
// - using serviceDate covers legs that start past midnight.
119-
// - The format of serviceDate can either be 'yyyyMMdd' (OTP v1) or 'yyyy-MM-dd' (OTP v2)
120-
// and both formats are correctly handled by toDate from date-fns-tz.
121-
const startDate = firstTransitLeg
122-
? toDate(firstTransitLeg.serviceDate || '', { timeZone })
123-
: utcToZonedTime(new Date(itinerary.startTime), timeZone)
124-
88+
const startDate = utcToZonedTime(new Date(itinerary.startTime), timeZone)
12589
const dayOfWeek = startDate.getDay()
12690
return dayOfWeek === 0 || dayOfWeek === 6 ? WEEKEND_DAYS : WEEKDAYS
12791
}
@@ -172,14 +136,10 @@ export function sortStartTimes(
172136
}
173137

174138
// Ignore certain keys that could add significant calculation time to hashing.
175-
// The alerts are irrelevant, but the intermediateStops, interStopGeometry and
139+
// The alerts are irrelevant, but the intermediateStops, legGeometry and
176140
// steps could have the legGeometry substitute as an equivalent hash value
177-
const blackListedKeys = [
178-
'alerts',
179-
'intermediateStops',
180-
'interStopGeometry',
181-
'steps'
182-
]
141+
const blackListedKeys = ['alerts', 'intermediateStops', 'legGeometry', 'steps']
142+
183143
// make blackListedKeys into an object due to superior lookup performance
184144
const blackListedKeyLookup: Record<string, boolean> = {}
185145
blackListedKeys.forEach((key) => {

0 commit comments

Comments
 (0)