@opentripplanner/core-utils 11.4.3 → 11.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/__tests__/__mocks__/bike-rental-itinerary.json +863 -0
- package/esm/__tests__/__mocks__/config.json +54 -0
- package/esm/__tests__/__mocks__/fare-products-itinerary.json +1299 -0
- package/esm/__tests__/__mocks__/routes.json +107 -0
- package/esm/__tests__/__mocks__/tnc-itinerary.json +1726 -0
- package/esm/bike-rental-itinerary.json +863 -0
- package/esm/config.json +54 -0
- package/esm/fare-products-itinerary.json +1299 -0
- package/esm/itinerary.js +23 -9
- package/esm/itinerary.js.map +1 -1
- package/esm/otpSchema.json +13373 -0
- package/esm/planQuery.graphql +281 -0
- package/esm/routes.json +107 -0
- package/esm/tnc-itinerary.json +1726 -0
- package/lib/__tests__/__mocks__/bike-rental-itinerary.json +863 -0
- package/lib/__tests__/__mocks__/config.json +54 -0
- package/lib/__tests__/__mocks__/fare-products-itinerary.json +1299 -0
- package/lib/__tests__/__mocks__/routes.json +107 -0
- package/lib/__tests__/__mocks__/tnc-itinerary.json +1726 -0
- package/lib/itinerary.d.ts +6 -2
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +32 -10
- package/lib/itinerary.js.map +1 -1
- package/lib/otpSchema.json +13373 -0
- package/lib/planQuery.graphql +281 -0
- package/package.json +3 -3
- package/src/__tests__/itinerary.ts +16 -0
- package/src/itinerary.ts +31 -11
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
query Plan(
|
|
2
|
+
$arriveBy: Boolean
|
|
3
|
+
$banned: InputBanned
|
|
4
|
+
$bikeReluctance: Float
|
|
5
|
+
$carReluctance: Float
|
|
6
|
+
$date: String
|
|
7
|
+
$fromPlace: String!
|
|
8
|
+
$modes: [TransportMode]
|
|
9
|
+
$numItineraries: Int
|
|
10
|
+
$preferred: InputPreferred
|
|
11
|
+
$time: String
|
|
12
|
+
$toPlace: String!
|
|
13
|
+
$unpreferred: InputUnpreferred
|
|
14
|
+
$walkReluctance: Float
|
|
15
|
+
$walkSpeed: Float
|
|
16
|
+
$wheelchair: Boolean
|
|
17
|
+
) {
|
|
18
|
+
plan(
|
|
19
|
+
arriveBy: $arriveBy
|
|
20
|
+
banned: $banned
|
|
21
|
+
bikeReluctance: $bikeReluctance
|
|
22
|
+
carReluctance: $carReluctance
|
|
23
|
+
date: $date
|
|
24
|
+
fromPlace: $fromPlace
|
|
25
|
+
# Currently only supporting EN locale, used for times and text
|
|
26
|
+
locale: "en"
|
|
27
|
+
numItineraries: $numItineraries
|
|
28
|
+
preferred: $preferred
|
|
29
|
+
time: $time
|
|
30
|
+
toPlace: $toPlace
|
|
31
|
+
transportModes: $modes
|
|
32
|
+
unpreferred: $unpreferred
|
|
33
|
+
walkReluctance: $walkReluctance
|
|
34
|
+
walkSpeed: $walkSpeed
|
|
35
|
+
wheelchair: $wheelchair
|
|
36
|
+
) {
|
|
37
|
+
itineraries {
|
|
38
|
+
accessibilityScore
|
|
39
|
+
duration
|
|
40
|
+
endTime
|
|
41
|
+
legs {
|
|
42
|
+
accessibilityScore
|
|
43
|
+
agency {
|
|
44
|
+
alerts {
|
|
45
|
+
alertDescriptionText
|
|
46
|
+
alertHeaderText
|
|
47
|
+
alertUrl
|
|
48
|
+
effectiveStartDate
|
|
49
|
+
id
|
|
50
|
+
}
|
|
51
|
+
gtfsId
|
|
52
|
+
id: gtfsId
|
|
53
|
+
name
|
|
54
|
+
timezone
|
|
55
|
+
url
|
|
56
|
+
}
|
|
57
|
+
alerts {
|
|
58
|
+
alertDescriptionText
|
|
59
|
+
alertHeaderText
|
|
60
|
+
alertUrl
|
|
61
|
+
effectiveStartDate
|
|
62
|
+
id
|
|
63
|
+
}
|
|
64
|
+
arrivalDelay
|
|
65
|
+
departureDelay
|
|
66
|
+
distance
|
|
67
|
+
dropOffBookingInfo {
|
|
68
|
+
contactInfo {
|
|
69
|
+
bookingUrl
|
|
70
|
+
infoUrl
|
|
71
|
+
phoneNumber
|
|
72
|
+
}
|
|
73
|
+
earliestBookingTime {
|
|
74
|
+
daysPrior
|
|
75
|
+
time
|
|
76
|
+
}
|
|
77
|
+
latestBookingTime {
|
|
78
|
+
daysPrior
|
|
79
|
+
time
|
|
80
|
+
}
|
|
81
|
+
message
|
|
82
|
+
}
|
|
83
|
+
dropoffType
|
|
84
|
+
duration
|
|
85
|
+
endTime
|
|
86
|
+
fareProducts {
|
|
87
|
+
id
|
|
88
|
+
product {
|
|
89
|
+
__typename
|
|
90
|
+
id
|
|
91
|
+
medium {
|
|
92
|
+
id
|
|
93
|
+
name
|
|
94
|
+
}
|
|
95
|
+
name
|
|
96
|
+
riderCategory {
|
|
97
|
+
id
|
|
98
|
+
name
|
|
99
|
+
}
|
|
100
|
+
... on DefaultFareProduct {
|
|
101
|
+
price {
|
|
102
|
+
amount
|
|
103
|
+
currency {
|
|
104
|
+
code
|
|
105
|
+
digits
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
from {
|
|
112
|
+
lat
|
|
113
|
+
lon
|
|
114
|
+
name
|
|
115
|
+
rentalVehicle {
|
|
116
|
+
id
|
|
117
|
+
network
|
|
118
|
+
}
|
|
119
|
+
stop {
|
|
120
|
+
alerts {
|
|
121
|
+
alertDescriptionText
|
|
122
|
+
alertHeaderText
|
|
123
|
+
alertUrl
|
|
124
|
+
effectiveStartDate
|
|
125
|
+
id
|
|
126
|
+
}
|
|
127
|
+
code
|
|
128
|
+
gtfsId
|
|
129
|
+
id
|
|
130
|
+
lat
|
|
131
|
+
lon
|
|
132
|
+
}
|
|
133
|
+
vertexType
|
|
134
|
+
}
|
|
135
|
+
headsign
|
|
136
|
+
interlineWithPreviousLeg
|
|
137
|
+
intermediateStops {
|
|
138
|
+
lat
|
|
139
|
+
locationType
|
|
140
|
+
lon
|
|
141
|
+
name
|
|
142
|
+
stopCode: code
|
|
143
|
+
stopId: id
|
|
144
|
+
}
|
|
145
|
+
legGeometry {
|
|
146
|
+
length
|
|
147
|
+
points
|
|
148
|
+
}
|
|
149
|
+
mode
|
|
150
|
+
pickupBookingInfo {
|
|
151
|
+
contactInfo {
|
|
152
|
+
bookingUrl
|
|
153
|
+
infoUrl
|
|
154
|
+
phoneNumber
|
|
155
|
+
}
|
|
156
|
+
earliestBookingTime {
|
|
157
|
+
daysPrior
|
|
158
|
+
time
|
|
159
|
+
}
|
|
160
|
+
latestBookingTime {
|
|
161
|
+
daysPrior
|
|
162
|
+
time
|
|
163
|
+
}
|
|
164
|
+
message
|
|
165
|
+
}
|
|
166
|
+
pickupType
|
|
167
|
+
realTime
|
|
168
|
+
realtimeState
|
|
169
|
+
rentedBike
|
|
170
|
+
rideHailingEstimate {
|
|
171
|
+
arrival
|
|
172
|
+
maxPrice {
|
|
173
|
+
amount
|
|
174
|
+
currency {
|
|
175
|
+
code
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
minPrice {
|
|
179
|
+
amount
|
|
180
|
+
currency {
|
|
181
|
+
code
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
provider {
|
|
185
|
+
id
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
route {
|
|
189
|
+
alerts {
|
|
190
|
+
alertDescriptionText
|
|
191
|
+
alertHeaderText
|
|
192
|
+
alertUrl
|
|
193
|
+
effectiveStartDate
|
|
194
|
+
id
|
|
195
|
+
}
|
|
196
|
+
color
|
|
197
|
+
gtfsId
|
|
198
|
+
id: gtfsId
|
|
199
|
+
longName
|
|
200
|
+
shortName
|
|
201
|
+
textColor
|
|
202
|
+
type
|
|
203
|
+
}
|
|
204
|
+
startTime
|
|
205
|
+
steps {
|
|
206
|
+
absoluteDirection
|
|
207
|
+
alerts {
|
|
208
|
+
alertDescriptionText
|
|
209
|
+
alertHeaderText
|
|
210
|
+
alertUrl
|
|
211
|
+
effectiveStartDate
|
|
212
|
+
id
|
|
213
|
+
}
|
|
214
|
+
area
|
|
215
|
+
distance
|
|
216
|
+
elevationProfile {
|
|
217
|
+
distance
|
|
218
|
+
elevation
|
|
219
|
+
}
|
|
220
|
+
lat
|
|
221
|
+
lon
|
|
222
|
+
relativeDirection
|
|
223
|
+
stayOn
|
|
224
|
+
streetName
|
|
225
|
+
}
|
|
226
|
+
to {
|
|
227
|
+
lat
|
|
228
|
+
lon
|
|
229
|
+
name
|
|
230
|
+
rentalVehicle {
|
|
231
|
+
id
|
|
232
|
+
network
|
|
233
|
+
}
|
|
234
|
+
stop {
|
|
235
|
+
alerts {
|
|
236
|
+
alertDescriptionText
|
|
237
|
+
alertHeaderText
|
|
238
|
+
alertUrl
|
|
239
|
+
effectiveStartDate
|
|
240
|
+
id
|
|
241
|
+
}
|
|
242
|
+
code
|
|
243
|
+
gtfsId
|
|
244
|
+
id
|
|
245
|
+
lat
|
|
246
|
+
lon
|
|
247
|
+
}
|
|
248
|
+
vertexType
|
|
249
|
+
}
|
|
250
|
+
transitLeg
|
|
251
|
+
trip {
|
|
252
|
+
arrivalStoptime {
|
|
253
|
+
stop {
|
|
254
|
+
gtfsId
|
|
255
|
+
id
|
|
256
|
+
}
|
|
257
|
+
stopPosition
|
|
258
|
+
}
|
|
259
|
+
departureStoptime {
|
|
260
|
+
stop {
|
|
261
|
+
gtfsId
|
|
262
|
+
id
|
|
263
|
+
}
|
|
264
|
+
stopPosition
|
|
265
|
+
}
|
|
266
|
+
gtfsId
|
|
267
|
+
id
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
startTime
|
|
271
|
+
transfers: numberOfTransfers
|
|
272
|
+
waitingTime
|
|
273
|
+
walkTime
|
|
274
|
+
}
|
|
275
|
+
routingErrors {
|
|
276
|
+
code
|
|
277
|
+
description
|
|
278
|
+
inputField
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/core-utils",
|
|
3
|
-
"version": "11.4.
|
|
3
|
+
"version": "11.4.5",
|
|
4
4
|
"description": "Core functionality that is shared among numerous UI components",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=13"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@conveyal/lonlat": "^1.4.1",
|
|
16
16
|
"@mapbox/polyline": "^1.1.0",
|
|
17
|
-
"@opentripplanner/geocoder": "^3.0.
|
|
17
|
+
"@opentripplanner/geocoder": "^3.0.2",
|
|
18
18
|
"@styled-icons/foundation": "^10.34.0",
|
|
19
19
|
"@turf/along": "^6.0.1",
|
|
20
20
|
"chroma-js": "^2.4.2",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsc": "tsc"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@opentripplanner/types": "^6.5.
|
|
33
|
+
"@opentripplanner/types": "^6.5.2",
|
|
34
34
|
"@types/chroma-js": "^2.1.4"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
getLegRouteLongName,
|
|
10
10
|
getLegRouteName,
|
|
11
11
|
getLegRouteShortName,
|
|
12
|
+
isFlex,
|
|
12
13
|
isTransit,
|
|
13
14
|
mapOldElevationComponentToNew
|
|
14
15
|
} from "../itinerary";
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
const bikeRentalItinerary = require("./__mocks__/bike-rental-itinerary.json");
|
|
17
18
|
const tncItinerary = require("./__mocks__/tnc-itinerary.json");
|
|
18
19
|
const fareProductItinerary = require("./__mocks__/fare-products-itinerary.json");
|
|
20
|
+
const flexItinerary = require("../../../itinerary-body/src/__mocks__/itineraries/flex-itinerary.json");
|
|
19
21
|
|
|
20
22
|
const basePlace = {
|
|
21
23
|
lat: 0,
|
|
@@ -40,6 +42,20 @@ describe("util > itinerary", () => {
|
|
|
40
42
|
});
|
|
41
43
|
});
|
|
42
44
|
|
|
45
|
+
describe("isFlex", () => {
|
|
46
|
+
it("should detect flex if present", () => {
|
|
47
|
+
fareProductItinerary.legs.forEach(leg => expect(isFlex(leg)).toBe(false));
|
|
48
|
+
tncItinerary.legs.forEach(leg => expect(isFlex(leg)).toBe(false));
|
|
49
|
+
expect(isFlex(flexItinerary.legs[0])).toBe(false);
|
|
50
|
+
expect(isFlex(flexItinerary.legs[1])).toBe(false);
|
|
51
|
+
expect(isFlex(flexItinerary.legs[2])).toBe(false);
|
|
52
|
+
expect(isFlex(flexItinerary.legs[3])).toBe(false);
|
|
53
|
+
expect(isFlex(flexItinerary.legs[4])).toBe(false);
|
|
54
|
+
expect(isFlex(flexItinerary.legs[5])).toBe(true);
|
|
55
|
+
expect(isFlex(flexItinerary.legs[6])).toBe(false); // Does not exist
|
|
56
|
+
expect(isFlex(flexItinerary.legs[7])).toBe(false); // Does not exist
|
|
57
|
+
});
|
|
58
|
+
});
|
|
43
59
|
describe("isTransit", () => {
|
|
44
60
|
it("should work", () => {
|
|
45
61
|
expect(isTransit("CAR")).toBeFalsy();
|
package/src/itinerary.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function isTransit(mode: string): boolean {
|
|
|
52
52
|
* property which encodes this info.
|
|
53
53
|
*/
|
|
54
54
|
export function isReservationRequired(leg: Leg): boolean {
|
|
55
|
-
return leg
|
|
55
|
+
return leg?.boardRule === "mustPhone" || leg?.alightRule === "mustPhone";
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Returns true if a user must ask the driver to let the user off
|
|
@@ -61,25 +61,45 @@ export function isReservationRequired(leg: Leg): boolean {
|
|
|
61
61
|
*/
|
|
62
62
|
export function isCoordinationRequired(leg: Leg): boolean {
|
|
63
63
|
return (
|
|
64
|
-
leg
|
|
65
|
-
leg
|
|
64
|
+
leg?.boardRule === "coordinateWithDriver" ||
|
|
65
|
+
leg?.alightRule === "coordinateWithDriver"
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
69
|
-
* The two rules checked by the above two functions are the only values
|
|
70
|
-
* returned by OTP when a leg is a flex leg.
|
|
71
|
-
*/
|
|
72
|
-
export function isFlex(leg: Leg): boolean {
|
|
73
|
-
return isReservationRequired(leg) || isCoordinationRequired(leg);
|
|
74
|
-
}
|
|
75
68
|
|
|
69
|
+
export function containsGeometry(place: Place): boolean {
|
|
70
|
+
return (
|
|
71
|
+
place?.stop?.geometries !== null && place?.stop?.geometries !== undefined
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
export function endsWithGeometry(leg: Leg): boolean {
|
|
75
|
+
return containsGeometry(leg?.to);
|
|
76
|
+
}
|
|
77
|
+
export function startsWithGeometry(leg: Leg): boolean {
|
|
78
|
+
return containsGeometry(leg?.from);
|
|
79
|
+
}
|
|
80
|
+
export function legContainsGeometry(leg: Leg): boolean {
|
|
81
|
+
return endsWithGeometry(leg) || startsWithGeometry(leg);
|
|
82
|
+
}
|
|
76
83
|
export function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {
|
|
77
84
|
return info?.latestBookingTime?.daysPrior > 0;
|
|
78
85
|
}
|
|
79
86
|
export function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {
|
|
80
|
-
return isAdvanceBookingRequired(leg
|
|
87
|
+
return isAdvanceBookingRequired(leg?.dropOffBookingInfo);
|
|
81
88
|
}
|
|
82
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The two rules checked by the above two functions are the only values
|
|
92
|
+
* returned by OTP when a leg is a flex leg.
|
|
93
|
+
*/
|
|
94
|
+
export function isFlex(leg: Leg): boolean {
|
|
95
|
+
return (
|
|
96
|
+
isReservationRequired(leg) ||
|
|
97
|
+
isCoordinationRequired(leg) ||
|
|
98
|
+
legDropoffRequiresAdvanceBooking(leg) ||
|
|
99
|
+
isAdvanceBookingRequired(leg?.pickupBookingInfo) ||
|
|
100
|
+
legContainsGeometry(leg)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
83
103
|
export function isRideshareLeg(leg: Leg): boolean {
|
|
84
104
|
return !!leg.rideHailingEstimate?.provider?.id;
|
|
85
105
|
}
|