@opentripplanner/core-utils 9.0.0-alpha.8 → 9.0.0

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.
@@ -1,146 +1,236 @@
1
- query PlanQuery(
2
- $fromPlace: String!,
3
- $toPlace: String!,
4
- $modes: [TransportMode],
5
- $time: String,
6
- $date: String,
7
- $wheelchair: Boolean,
8
- $bikeReluctance: Float,
9
- $carReluctance: Float,
10
- $walkReluctance: Float,
11
- $arriveBy: Boolean,
12
- $intermediatePlaces: [InputCoordinates],
13
- $preferred: InputPreferred,
14
- $unpreferred: InputUnpreferred,
15
- $banned: InputBanned,
1
+ query Plan(
2
+ $fromPlace: String!
3
+ $toPlace: String!
4
+ $modes: [TransportMode]
5
+ $time: String
6
+ $date: String
7
+ $wheelchair: Boolean
8
+ $bikeReluctance: Float
9
+ $carReluctance: Float
10
+ $walkReluctance: Float
11
+ $arriveBy: Boolean
12
+ $preferred: InputPreferred
13
+ $unpreferred: InputUnpreferred
14
+ $banned: InputBanned
15
+ $numItineraries: Int
16
16
  ) {
17
- plan(
18
- fromPlace: $fromPlace
19
- toPlace: $toPlace
20
- transportModes: $modes
21
- # Currently only supporting EN locale, used for times and text
22
- locale: "en",
23
- time: $time,
24
- date: $date,
25
- wheelchair: $wheelchair,
26
- bikeReluctance: $bikeReluctance,
27
- carReluctance: $carReluctance,
28
- walkReluctance: $walkReluctance,
29
- arriveBy: $arriveBy,
30
- intermediatePlaces: $intermediatePlaces,
31
- preferred: $preferred,
32
- unpreferred: $unpreferred,
33
- banned: $banned,
34
- ) {
35
- itineraries {
36
- duration
37
- endTime
38
- startTime
39
- waitingTime
40
- walkTime
41
- legs {
42
- distance
43
- duration
44
- endTime
45
- mode
46
- realTime
47
- realtimeState
48
- startTime
49
- transitLeg
50
- trip {
51
- id
52
- gtfsId
53
- }
54
- agency {
55
- name
56
- id
57
- timezone
58
- url
59
- alerts {
60
- alertHeaderText
17
+ plan(
18
+ arriveBy: $arriveBy
19
+ banned: $banned
20
+ bikeReluctance: $bikeReluctance
21
+ carReluctance: $carReluctance
22
+ date: $date
23
+ fromPlace: $fromPlace
24
+ # Currently only supporting EN locale, used for times and text
25
+ locale: "en"
26
+ numItineraries: $numItineraries
27
+ preferred: $preferred
28
+ time: $time
29
+ toPlace: $toPlace
30
+ transportModes: $modes
31
+ unpreferred: $unpreferred
32
+ walkReluctance: $walkReluctance
33
+ wheelchair: $wheelchair
34
+ ) {
35
+ itineraries {
36
+ accessibilityScore
37
+ duration
38
+ endTime
39
+ legs {
40
+ accessibilityScore
41
+ agency {
42
+ alerts {
61
43
  alertDescriptionText
44
+ alertHeaderText
62
45
  alertUrl
63
46
  effectiveStartDate
47
+ id
64
48
  }
65
- }
66
- legGeometry {
67
- length
68
- points
69
- }
70
- intermediateStops {
71
- lat
72
- lon
73
- name
74
- stopCode: code
75
- stopId: id
76
- locationType
77
- }
78
- route {
79
- shortName
80
- color
81
- textColor
82
- id
83
- type
84
- alerts {
85
- alertHeaderText
49
+ id
50
+ name
51
+ timezone
52
+ url
53
+ }
54
+ arrivalDelay
55
+ departureDelay
56
+ distance
57
+ dropoffType
58
+ duration
59
+ endTime
60
+ fareProducts {
61
+ id
62
+ product {
63
+ id
64
+ medium {
65
+ id
66
+ name
67
+ }
68
+ name
69
+ price {
70
+ amount
71
+ currency {
72
+ code
73
+ digits
74
+ }
75
+ }
76
+ riderCategory {
77
+ id
78
+ name
79
+ }
80
+ }
81
+ }
82
+ from {
83
+ lat
84
+ lon
85
+ name
86
+ rentalVehicle {
87
+ id
88
+ network
89
+ }
90
+ stop {
91
+ alerts {
92
+ alertDescriptionText
93
+ alertHeaderText
94
+ alertUrl
95
+ effectiveStartDate
96
+ id
97
+ }
98
+ code
99
+ gtfsId
100
+ id
101
+ }
102
+ vertexType
103
+ }
104
+ interlineWithPreviousLeg
105
+ intermediateStops {
106
+ lat
107
+ locationType
108
+ lon
109
+ name
110
+ stopCode: code
111
+ stopId: id
112
+ }
113
+ legGeometry {
114
+ length
115
+ points
116
+ }
117
+ mode
118
+ pickupBookingInfo {
119
+ earliestBookingTime {
120
+ daysPrior
121
+ }
122
+ }
123
+ pickupType
124
+ realTime
125
+ realtimeState
126
+ rentedBike
127
+ rideHailingEstimate {
128
+ arrival
129
+ maxPrice {
130
+ amount
131
+ currency {
132
+ code
133
+ }
134
+ }
135
+ minPrice {
136
+ amount
137
+ currency {
138
+ code
139
+ }
140
+ }
141
+ provider {
142
+ id
143
+ }
144
+ }
145
+ route {
146
+ alerts {
86
147
  alertDescriptionText
148
+ alertHeaderText
87
149
  alertUrl
88
150
  effectiveStartDate
151
+ id
89
152
  }
90
- }
91
- from {
92
- lat
93
- lon
94
- name
95
- vertexType
96
- stop {
97
- id
98
- code
99
- alerts {
100
- alertHeaderText
101
- alertDescriptionText
102
- alertUrl
103
- effectiveStartDate
104
- }
105
- }
106
- }
107
- to {
108
- lat
109
- lon
110
- name
111
- vertexType
112
- stop {
113
- id
114
- code
115
- alerts {
116
- alertHeaderText
117
- alertDescriptionText
118
- alertUrl
119
- effectiveStartDate
120
- }
121
- }
122
- }
123
- steps {
124
- distance
125
- lat
126
- lon
127
- relativeDirection
153
+ color
154
+ id
155
+ longName
156
+ shortName
157
+ textColor
158
+ type
159
+ }
160
+ startTime
161
+ steps {
128
162
  absoluteDirection
129
- stayOn
130
- streetName
131
- area
132
- alerts{
133
- alertHeaderText
163
+ alerts {
134
164
  alertDescriptionText
165
+ alertHeaderText
135
166
  alertUrl
136
167
  effectiveStartDate
168
+ id
169
+ }
170
+ area
171
+ distance
172
+ elevationProfile {
173
+ distance
174
+ elevation
175
+ }
176
+ lat
177
+ lon
178
+ relativeDirection
179
+ stayOn
180
+ streetName
181
+ }
182
+ to {
183
+ lat
184
+ lon
185
+ name
186
+ rentalVehicle {
187
+ id
188
+ network
189
+ }
190
+ stop {
191
+ alerts {
192
+ alertDescriptionText
193
+ alertHeaderText
194
+ alertUrl
195
+ effectiveStartDate
196
+ id
197
+ }
198
+ code
199
+ gtfsId
200
+ id
201
+ }
202
+ vertexType
203
+ }
204
+ transitLeg
205
+ trip {
206
+ arrivalStoptime {
207
+ stop {
208
+ gtfsId
209
+ id
210
+ }
211
+ stopPosition
212
+ }
213
+ departureStoptime {
214
+ stop {
215
+ gtfsId
216
+ id
217
+ }
218
+ stopPosition
137
219
  }
138
- elevationProfile {
139
- distance
140
- elevation
141
- }
142
- }
143
- }
144
- }
145
- }
146
- }
220
+
221
+ gtfsId
222
+ id
223
+ tripHeadsign
224
+ }
225
+ }
226
+ startTime
227
+ waitingTime
228
+ walkTime
229
+ }
230
+ routingErrors {
231
+ code
232
+ description
233
+ inputField
234
+ }
235
+ }
236
+ }
package/src/query-gen.ts CHANGED
@@ -6,16 +6,33 @@ import {
6
6
  TransportMode
7
7
  } from "@opentripplanner/types";
8
8
 
9
- import PlanQuery from "./planQuery.graphql";
9
+ import DefaultPlanQuery from "./planQuery.graphql";
10
+
11
+ type InputBanned = {
12
+ routes?: string;
13
+ agencies?: string;
14
+ trips?: string;
15
+ stops?: string;
16
+ stopsHard?: string;
17
+ };
18
+
19
+ type InputPreferred = {
20
+ routes?: string;
21
+ agencies?: string;
22
+ unpreferredCost?: string;
23
+ };
10
24
 
11
25
  type OTPQueryParams = {
12
26
  arriveBy: boolean;
13
- date: string;
27
+ date?: string;
14
28
  from: LonLatOutput & { name?: string };
15
29
  modes: TransportMode[];
16
30
  modeSettings: ModeSetting[];
17
- time: string;
31
+ time?: string;
32
+ numItineraries?: number;
18
33
  to: LonLatOutput & { name?: string };
34
+ banned?: InputBanned;
35
+ preferred?: InputPreferred;
19
36
  };
20
37
 
21
38
  type GraphQLQuery = {
@@ -41,7 +58,11 @@ export function extractAdditionalModes(
41
58
  }
42
59
 
43
60
  // In checkboxes, mode must be enabled and have a transport mode in it
44
- if (cur.type === "CHECKBOX" && cur.addTransportMode && cur.value) {
61
+ if (
62
+ (cur.type === "CHECKBOX" || cur.type === "SUBMODE") &&
63
+ cur.addTransportMode &&
64
+ cur.value
65
+ ) {
45
66
  return [...prev, cur.addTransportMode];
46
67
  }
47
68
  if (cur.type === "DROPDOWN") {
@@ -106,7 +127,7 @@ const VALID_COMBOS = [
106
127
  ["TRANSIT", "CAR"]
107
128
  ];
108
129
 
109
- const BANNED_TOGETHER = ["SCOOTER", "BICYCLE"];
130
+ const BANNED_TOGETHER = ["SCOOTER", "BICYCLE", "CAR"];
110
131
 
111
132
  export const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(
112
133
  mode => SIMPLIFICATIONS[mode] === "TRANSIT" && mode !== "TRANSIT"
@@ -147,7 +168,9 @@ function isCombinationValid(
147
168
  }
148
169
 
149
170
  // OTP doesn't support multiple non-walk modes
150
- if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m))) return false;
171
+ if (BANNED_TOGETHER.filter(m => combo.find(c => c.mode === m)).length > 1) {
172
+ return false;
173
+ }
151
174
 
152
175
  return !!VALID_COMBOS.find(
153
176
  vc =>
@@ -178,17 +201,32 @@ export function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {
178
201
  .map(combo => ({ ...params, modes: combo }));
179
202
  }
180
203
 
181
- export function generateOtp2Query({
182
- arriveBy,
183
- date,
184
- from,
185
- modes,
186
- modeSettings,
187
- time,
188
- to
189
- }: OTPQueryParams): GraphQLQuery {
204
+ /**
205
+ * Generates a query for OTP GraphQL API based on parameters.
206
+ * @param param0 OTP2 Parameters for the query
207
+ * @param planQuery Override the default query for OTP
208
+ * @returns A fully formed query+variables ready to be sent to GraphQL backend
209
+ */
210
+ export function generateOtp2Query(
211
+ {
212
+ arriveBy,
213
+ banned,
214
+ date,
215
+ from,
216
+ modes,
217
+ modeSettings,
218
+ numItineraries,
219
+ preferred,
220
+ time,
221
+ to
222
+ }: OTPQueryParams,
223
+ planQuery = DefaultPlanQuery
224
+ ): GraphQLQuery {
190
225
  // This extracts the values from the mode settings to key value pairs
191
226
  const modeSettingValues = modeSettings.reduce((prev, cur) => {
227
+ if (cur.type === "SLIDER" && cur.inverseKey) {
228
+ prev[cur.inverseKey] = cur.high - cur.value + cur.low;
229
+ }
192
230
  prev[cur.key] = cur.value;
193
231
  return prev;
194
232
  }, {}) as ModeSettingValues;
@@ -201,14 +239,17 @@ export function generateOtp2Query({
201
239
  } = modeSettingValues;
202
240
 
203
241
  return {
204
- query: print(PlanQuery),
242
+ query: print(planQuery),
205
243
  variables: {
206
244
  arriveBy,
245
+ banned,
207
246
  bikeReluctance,
208
247
  carReluctance,
209
248
  date,
210
249
  fromPlace: `${from.name}::${from.lat},${from.lon}}`,
211
250
  modes,
251
+ numItineraries,
252
+ preferred,
212
253
  time,
213
254
  toPlace: `${to.name}::${to.lat},${to.lon}}`,
214
255
  walkReluctance,