@opentripplanner/core-utils 9.0.0-alpha.9 → 9.0.1

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,148 +1,239 @@
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
- tripHeadsign
54
- }
55
- agency {
56
- name
57
- id
58
- timezone
59
- url
60
- alerts {
61
- 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 {
62
43
  alertDescriptionText
44
+ alertHeaderText
63
45
  alertUrl
64
46
  effectiveStartDate
47
+ id
65
48
  }
66
- }
67
- legGeometry {
68
- length
69
- points
70
- }
71
- intermediateStops {
72
- lat
73
- lon
74
- name
75
- stopCode: code
76
- stopId: id
77
- locationType
78
- }
79
- route {
80
- shortName
81
- longName
82
- color
83
- textColor
84
- id
85
- type
86
- alerts {
87
- 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
+ __typename
64
+ id
65
+ medium {
66
+ id
67
+ name
68
+ }
69
+ name
70
+ riderCategory {
71
+ id
72
+ name
73
+ }
74
+ ... on DefaultFareProduct {
75
+ price {
76
+ amount
77
+ currency {
78
+ code
79
+ digits
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ from {
86
+ lat
87
+ lon
88
+ name
89
+ rentalVehicle {
90
+ id
91
+ network
92
+ }
93
+ stop {
94
+ alerts {
95
+ alertDescriptionText
96
+ alertHeaderText
97
+ alertUrl
98
+ effectiveStartDate
99
+ id
100
+ }
101
+ code
102
+ gtfsId
103
+ id
104
+ }
105
+ vertexType
106
+ }
107
+ interlineWithPreviousLeg
108
+ intermediateStops {
109
+ lat
110
+ locationType
111
+ lon
112
+ name
113
+ stopCode: code
114
+ stopId: id
115
+ }
116
+ legGeometry {
117
+ length
118
+ points
119
+ }
120
+ mode
121
+ pickupBookingInfo {
122
+ earliestBookingTime {
123
+ daysPrior
124
+ }
125
+ }
126
+ pickupType
127
+ realTime
128
+ realtimeState
129
+ rentedBike
130
+ rideHailingEstimate {
131
+ arrival
132
+ maxPrice {
133
+ amount
134
+ currency {
135
+ code
136
+ }
137
+ }
138
+ minPrice {
139
+ amount
140
+ currency {
141
+ code
142
+ }
143
+ }
144
+ provider {
145
+ id
146
+ }
147
+ }
148
+ route {
149
+ alerts {
88
150
  alertDescriptionText
151
+ alertHeaderText
89
152
  alertUrl
90
153
  effectiveStartDate
154
+ id
91
155
  }
92
- }
93
- from {
94
- lat
95
- lon
96
- name
97
- vertexType
98
- stop {
99
- id
100
- code
101
- alerts {
102
- alertHeaderText
103
- alertDescriptionText
104
- alertUrl
105
- effectiveStartDate
106
- }
107
- }
108
- }
109
- to {
110
- lat
111
- lon
112
- name
113
- vertexType
114
- stop {
115
- id
116
- code
117
- alerts {
118
- alertHeaderText
119
- alertDescriptionText
120
- alertUrl
121
- effectiveStartDate
122
- }
123
- }
124
- }
125
- steps {
126
- distance
127
- lat
128
- lon
129
- relativeDirection
156
+ color
157
+ id
158
+ longName
159
+ shortName
160
+ textColor
161
+ type
162
+ }
163
+ startTime
164
+ steps {
130
165
  absoluteDirection
131
- stayOn
132
- streetName
133
- area
134
- alerts{
135
- alertHeaderText
166
+ alerts {
136
167
  alertDescriptionText
168
+ alertHeaderText
137
169
  alertUrl
138
170
  effectiveStartDate
171
+ id
172
+ }
173
+ area
174
+ distance
175
+ elevationProfile {
176
+ distance
177
+ elevation
178
+ }
179
+ lat
180
+ lon
181
+ relativeDirection
182
+ stayOn
183
+ streetName
184
+ }
185
+ to {
186
+ lat
187
+ lon
188
+ name
189
+ rentalVehicle {
190
+ id
191
+ network
192
+ }
193
+ stop {
194
+ alerts {
195
+ alertDescriptionText
196
+ alertHeaderText
197
+ alertUrl
198
+ effectiveStartDate
199
+ id
200
+ }
201
+ code
202
+ gtfsId
203
+ id
204
+ }
205
+ vertexType
206
+ }
207
+ transitLeg
208
+ trip {
209
+ arrivalStoptime {
210
+ stop {
211
+ gtfsId
212
+ id
213
+ }
214
+ stopPosition
215
+ }
216
+ departureStoptime {
217
+ stop {
218
+ gtfsId
219
+ id
220
+ }
221
+ stopPosition
139
222
  }
140
- elevationProfile {
141
- distance
142
- elevation
143
- }
144
- }
145
- }
146
- }
147
- }
223
+
224
+ gtfsId
225
+ id
226
+ tripHeadsign
227
+ }
228
+ }
229
+ startTime
230
+ waitingTime
231
+ walkTime
232
+ }
233
+ routingErrors {
234
+ code
235
+ description
236
+ inputField
237
+ }
238
+ }
148
239
  }
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,