From 57084262a2c71f7bb8869e04d870ddf900f60884 Mon Sep 17 00:00:00 2001 From: Benoit Deldicque Date: Mon, 21 Feb 2022 00:52:37 +0100 Subject: [PATCH] =?UTF-8?q?add=20departure.destination=20&=20arrival.origi?= =?UTF-8?q?n=20=E2=9C=85=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #260 fixes #259 Co-Authored-By: Jannis R --- docs/departures.md | 21 +++ parse/arrival-or-departure.js | 12 +- test/e2e/lib/validators.js | 11 ++ test/fixtures/bvg-arrivals.js | 48 ++++++ test/fixtures/db-arrivals.js | 2 + test/fixtures/vbb-departures.js | 252 ++++++++++++++++++++++++++++++++ test/fixtures/vsn-departures.js | 24 +++ 7 files changed, 369 insertions(+), 1 deletion(-) diff --git a/docs/departures.md b/docs/departures.md index c145348c..ca9cd904 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -78,6 +78,27 @@ The response may look like this: tripId: '1|31431|28|86|17122017', trip: 31431, direction: 'S Spandau', + // Depending on the HAFAS endpoint, the destination may be present: + destination: { + type: 'stop', + id: '900000029101', + name: 'S Spandau', + location: { + type: 'location', + id: '900029101', + latitude: 52.534794, + longitude: 13.197477 + }, + products: { + suburban: true, + subway: true, + tram: false, + bus: true, + ferry: false, + express: true, + regional: true, + }, + }, line: { type: 'line', id: '18299', diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 5e590b41..4d847412 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -31,7 +31,17 @@ const createParseArrOrDep = (prefix) => { direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(ctx, d.dirTxt) || null, provenance: prefix === ARRIVAL && d.dirTxt && profile.parseStationName(ctx, d.dirTxt) || null, line: d.line || null, - remarks: [] + remarks: [], + origin: null, + destination: null + } + + if (prefix === DEPARTURE && Array.isArray(d.prodL) && d.prodL[0].tLocX) { + res.destination = profile.parseLocation(ctx, ctx.res.common.locL[d.prodL[0].tLocX]) + } + + if (prefix === ARRIVAL && Array.isArray(d.prodL) && d.prodL[0].fLocX) { + res.origin = profile.parseLocation(ctx, ctx.res.common.locL[d.prodL[0].fLocX]) } if (d.pos) { diff --git a/test/e2e/lib/validators.js b/test/e2e/lib/validators.js index a59f7d1a..e8f3d0e8 100644 --- a/test/e2e/lib/validators.js +++ b/test/e2e/lib/validators.js @@ -388,11 +388,22 @@ const createValidateArrivalOrDeparture = (type, cfg) => { } val.line(val, dep.line, name + '.line') + if (type === 'departure') { const n = name + '.direction' a.strictEqual(typeof dep.direction, 'string', n + ' must be a string') a.ok(dep.direction, n + ' must not be empty') } + + if (dep.destination !== null) { + const lName = name + '.destination' + val.location(val, dep.destination, lName) + } + + if (dep.origin !== null) { + const lName = name + '.origin' + val.location(val, dep.origin, lName) + } } return validateArrivalOrDeparture } diff --git a/test/fixtures/bvg-arrivals.js b/test/fixtures/bvg-arrivals.js index 44870b0b..aaf5fe50 100644 --- a/test/fixtures/bvg-arrivals.js +++ b/test/fixtures/bvg-arrivals.js @@ -371,6 +371,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Clara-Jaschke-Str.', + origin: null, + destination: null, line: { type: 'line', id: 'm5', @@ -410,6 +412,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Ahrensfelde/Stadtgrenze', + origin: null, + destination: null, line: { type: 'line', id: 'm8', @@ -449,6 +453,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Clara-Jaschke-Str.', + origin: null, + destination: null, line: { type: 'line', id: 'm8', @@ -488,6 +494,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Riesaer Str.', + origin: null, + destination: null, line: { type: 'line', id: '56', @@ -527,6 +535,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Grünau', + origin: null, + destination: null, line: { type: 'line', id: 's8', @@ -567,6 +577,8 @@ module.exports = [ plannedPlatform: '1', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's41', @@ -608,6 +620,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -649,6 +663,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'S Hackescher Markt', + origin: null, + destination: null, line: { type: 'line', id: '56', @@ -688,6 +704,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -729,6 +747,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Scharnweberstr./Weichselstr.', + origin: null, + destination: null, line: { type: 'line', id: 'm5', @@ -768,6 +788,8 @@ module.exports = [ plannedPlatform: '1', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's41', @@ -807,6 +829,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -846,6 +870,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Clara-Jaschke-Str.', + origin: null, + destination: null, line: { type: 'line', id: 'm5', @@ -887,6 +913,8 @@ module.exports = [ prognosedPlatform: null, direction: null, provenance: 'S Birkenwerder', + origin: null, + destination: null, line: { type: 'line', id: 's8', @@ -937,6 +965,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Ahrensfelde/Stadtgrenze', + origin: null, + destination: null, line: { type: 'line', id: 'm8', @@ -976,6 +1006,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Clara-Jaschke-Str.', + origin: null, + destination: null, line: { type: 'line', id: 'm8', @@ -1015,6 +1047,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Riesaer Str.', + origin: null, + destination: null, line: { type: 'line', id: '56', @@ -1056,6 +1090,8 @@ module.exports = [ prognosedPlatform: null, direction: null, provenance: 'S Grünau', + origin: null, + destination: null, line: { type: 'line', id: 's85', @@ -1128,6 +1164,8 @@ module.exports = [ plannedPlatform: '1', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's41', @@ -1169,6 +1207,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -1210,6 +1250,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -1251,6 +1293,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -1292,6 +1336,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', @@ -1333,6 +1379,8 @@ module.exports = [ plannedPlatform: '2', direction: null, provenance: 'S Südkreuz', + origin: null, + destination: null, line: { type: 'line', id: 's42', diff --git a/test/fixtures/db-arrivals.js b/test/fixtures/db-arrivals.js index 61f9a9bc..ec18db9a 100644 --- a/test/fixtures/db-arrivals.js +++ b/test/fixtures/db-arrivals.js @@ -249,6 +249,8 @@ module.exports = [ plannedPlatform: null, direction: null, provenance: 'Rathaus Spandau (S+U), Berlin', + origin: null, + destination: null, line: { type: 'line', id: '7-vbbbvu-7', diff --git a/test/fixtures/vbb-departures.js b/test/fixtures/vbb-departures.js index 8dc707c4..2196ce30 100644 --- a/test/fixtures/vbb-departures.js +++ b/test/fixtures/vbb-departures.js @@ -196,6 +196,27 @@ module.exports = [ platform: '3', plannedPlatform: '3', direction: 'S Erkner', + origin: null, + destination: { + type: "stop", + id: "900000310004", + name: "S Erkner", + location: { + type: "location", + id: "900310004", + latitude: 52.428398, + longitude: 13.752246, + }, + products: { + suburban: true, + subway: false, + tram: false, + bus: true, + ferry: false, + express: false, + regional: true, + }, + }, provenance: null, line: { type: 'line', @@ -496,6 +517,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: "stop", + id: "900000005207", + name: "Philharmonie Süd", + location: { + type: "location", + id: "900005207", + latitude: 52.508761, + longitude: 13.370025, + }, + products: { + suburban: false, + subway: false, + tram: false, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.514227, @@ -747,6 +789,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: "stop", + id: "900000079221", + name: "S+U Hermannstr.", + location: { + type: "location", + id: "900079221", + latitude: 52.467339, + longitude: 13.43143, + }, + products: { + suburban: true, + subway: true, + tram: false, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.518982, @@ -998,6 +1061,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000096197', + name: 'S+U Wittenau [U8]', + location: { + type: 'location', + id: '900096197', + latitude: 52.59566, + longitude: 13.334634, + }, + products: { + suburban: true, + subway: true, + tram: false, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.51011, @@ -1249,6 +1333,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000024102', + name: 'S Westkreuz', + location: { + type: 'location', + id: '900024102', + latitude: 52.501148, + longitude: 13.283036, + }, + products: { + suburban: true, + subway: false, + tram: false, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.512052, @@ -1500,6 +1605,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000170004', + name: 'S Ahrensfelde', + location: { + type: 'location', + id: '900170004', + latitude: 52.571335, + longitude: 13.565648, + }, + products: { + suburban: true, + subway: false, + tram: false, + bus: true, + ferry: false, + express: false, + regional: true, + }, + }, currentTripPosition: { type: 'location', latitude: 52.52167, @@ -1751,6 +1877,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000230999', + name: 'S Potsdam Hauptbahnhof', + location: { + type: 'location', + id: '900230999', + latitude: 52.391659, + longitude: 13.066172, + }, + products: { + suburban: true, + subway: false, + tram: true, + bus: true, + ferry: false, + express: true, + regional: true, + }, + }, currentTripPosition: { type: 'location', latitude: 52.507287, @@ -2002,6 +2149,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000320004', + name: 'S Strausberg', + location: { + type: 'location', + id: '900320004', + latitude: 52.532367, + longitude: 13.834794, + }, + products: { + suburban: true, + subway: false, + tram: true, + bus: true, + ferry: false, + express: false, + regional: true, + }, + }, currentTripPosition: { type: 'location', latitude: 52.520528, @@ -2253,6 +2421,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000079221', + name: 'S+U Hermannstr.', + location: { + type: 'location', + id: '900079221', + latitude: 52.467339, + longitude: 13.43143, + }, + products: { + suburban: true, + subway: true, + tram: false, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.534345, @@ -2504,6 +2693,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000085104', + name: 'U Paracelsus-Bad', + location: { + type: 'location', + id: '900085104', + latitude: 52.574428, + longitude: 13.3473, + }, + products: { + suburban: true, + subway: true, + tram: false, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.493516, @@ -2754,6 +2964,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000120004', + name: 'S+U Warschauer Str.', + location: { + type: 'location', + id: '900120004', + latitude: 52.505768, + longitude: 13.449157, + }, + products: { + suburban: true, + subway: true, + tram: true, + bus: true, + ferry: false, + express: false, + regional: false, + }, + }, currentTripPosition: { type: 'location', latitude: 52.516519, @@ -3005,6 +3236,27 @@ module.exports = [ modified: '2021-06-12T07:43:36+02:00' } ], + origin: null, + destination: { + type: 'stop', + id: '900000029101', + name: 'S Spandau', + location: { + type: 'location', + id: '900029101', + latitude: 52.534794, + longitude: 13.197477, + }, + products: { + suburban: true, + subway: true, + tram: false, + bus: true, + ferry: false, + express: true, + regional: true, + }, + }, currentTripPosition: { type: 'location', latitude: 52.498604, diff --git a/test/fixtures/vsn-departures.js b/test/fixtures/vsn-departures.js index a2c0e9d9..beac6496 100644 --- a/test/fixtures/vsn-departures.js +++ b/test/fixtures/vsn-departures.js @@ -56,6 +56,30 @@ module.exports = { plannedPlatform: '8', direction: 'Frankfurt(Main) Hbf', provenance: null, + origin: null, + destination: { + type: 'stop', + id: '8000105', + name: 'Frankfurt(Main) Hbf', + location: { + type: 'location', + id: '8000105', + latitude: 50.107149, + longitude: 8.663785, + }, + products: { + nationalExpress: true, + national: true, + regionalExpress: false, + regional: true, + suburban: true, + bus: true, + ferry: false, + subway: false, + tram: false, + anrufSammelTaxi: false, + }, + }, line: { type: 'line', id: '80-30',