From c1ee557cf8820bed0c4587c79b5dbbba8d494b26 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 12 Oct 2021 17:50:05 +0200 Subject: [PATCH] =?UTF-8?q?parseArrOrDep:=20export=20currentTripLocation?= =?UTF-8?q?=20=E2=9C=85=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/departures.md | 15 ++++++ parse/arrival-or-departure.js | 8 ++++ test/fixtures/vbb-departures.js | 84 ++++++++++++++++++++++++++++----- 3 files changed, 95 insertions(+), 12 deletions(-) diff --git a/docs/departures.md b/docs/departures.md index 85dc6e5d..c145348c 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -97,6 +97,11 @@ The response may look like this: name: 'S-Bahn Berlin GmbH' } }, + currentTripPosition: { + type: 'location', + latitude: 52.500851, + longitude: 13.283755, + }, stop: { type: 'station', @@ -143,6 +148,11 @@ The response may look like this: night: false, operator: { /* … */ } }, + currentTripPosition: { + type: 'location', + latitude: 52.505004, + longitude: 13.322391, + }, stop: { /* … */ }, @@ -171,6 +181,11 @@ The response may look like this: night: false, operator: { /* … */ } }, + currentTripPosition: { + type: 'location', + latitude: 52.49864, + longitude: 13.307622, + }, stop: { /* … */ }, diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 945ffb01..6b807294 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -34,6 +34,14 @@ const createParseArrOrDep = (prefix) => { remarks: [] } + if (d.pos) { + res.currentTripPosition = { + type: 'location', + latitude: d.pos.y / 1000000, + longitude: d.pos.x / 1000000, + } + } + if (cancelled) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) diff --git a/test/fixtures/vbb-departures.js b/test/fixtures/vbb-departures.js index 6fc99254..8dc707c4 100644 --- a/test/fixtures/vbb-departures.js +++ b/test/fixtures/vbb-departures.js @@ -245,7 +245,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.514218, + longitude: 13.419502, + }, }, { tripId: '1|12106|15|86|12102021', @@ -490,7 +495,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.514227, + longitude: 13.422495, + }, }, { tripId: '1|23076|26|86|12102021', @@ -736,7 +746,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.518982, + longitude: 13.415097, + }, }, { tripId: '1|23117|2|86|12102021', @@ -982,7 +997,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.51011, + longitude: 13.415834, + }, }, { tripId: '1|25978|5|86|12102021', @@ -1228,7 +1248,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.512052, + longitude: 13.427682, + }, }, { tripId: '1|26593|10|86|12102021', @@ -1474,7 +1499,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.52167, + longitude: 13.410989, + }, }, { tripId: '1|26662|10|86|12102021', @@ -1720,7 +1750,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.507287, + longitude: 13.445238, + }, }, { tripId: '1|26077|2|86|12102021', @@ -1966,7 +2001,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.520528, + longitude: 13.39373, + }, }, { tripId: '1|23049|34|86|12102021', @@ -2212,7 +2252,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.534345, + longitude: 13.398197, + }, }, { tripId: '1|23111|31|86|12102021', @@ -2458,7 +2503,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.493516, + longitude: 13.421839, + }, }, { tripId: '1|12062|15|86|12102021', @@ -2703,7 +2753,12 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.516519, + longitude: 13.40956, + }, }, { tripId: '1|27181|9|86|12102021', @@ -2949,6 +3004,11 @@ module.exports = [ validUntil: '2022-12-31T00:00:00+01:00', modified: '2021-06-12T07:43:36+02:00' } - ] + ], + currentTripPosition: { + type: 'location', + latitude: 52.498604, + longitude: 13.467252, + }, } ]