From 2506e4c4951a2c6f510abc9a74970c4d871025f0 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 6 Mar 2018 02:47:05 +0100 Subject: [PATCH 01/17] DB, VBB: proper via tests :white_check_mark: --- test/db.js | 71 ++++++++++++++++++++++++++++++++++++++++++++------- test/vbb.js | 73 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 124 insertions(+), 20 deletions(-) diff --git a/test/db.js b/test/db.js index f38d2ddd..a9a4e770 100644 --- a/test/db.js +++ b/test/db.js @@ -217,18 +217,71 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { t.end() })) -test('Berlin Hbf to München Hbf with stopover at Hannover Hbf', co(function* (t) { - const [journey] = yield client.journeys(berlinHbf, münchenHbf, { - via: hannoverHbf, - results: 1 +test('journeys: via works – changing trains', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without changing + // is currently impossible. We check if the routing engine lets us change + // at Württembergallee if we set it as via. + const westhafen = '008089116' + const wedding = '008089131' + const württembergallee = '731084' + const [journey] = yield client.journeys(westhafen, wedding, { + via: württembergallee, + results: 1, + when }) - const i = journey.legs.findIndex(leg => leg.destination.id === hannoverHbf) - t.ok(i >= 0, 'no leg with Hannover Hbf as destination') + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) + t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const nextLeg = journey.legs[i + 1] - t.ok(nextLeg) - t.equal(nextLeg.origin.id, hannoverHbf) + const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) + t.ok(i2 >= 0, 'no leg with Württembergallee as origin') + t.ok(i2 >= i1) + + t.end() +})) + +test('journeys: via works – *without* changing trains', co(function* (t) { + // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* + // to change trains. We check if the routing engine *does not* require + // one to change at the via station. + const ruhleben = '000731058' + const zoo = '008010406' + const kastanienallee = '730983' + const [journey] = yield client.journeys(ruhleben, zoo, { + via: kastanienallee, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) + t.ok(i1 < 0, 'routing engine changes at Kastanienallee') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + t.ok(l, 'no stopover at Kastanienallee') + + t.end() +})) + +test('journeys: via works – even if on the obvious path', co(function* (t) { + const birkenwerder = '008080190' + const borgsdorf = '8080200' + const lehnitz = '008081722' + const [journey] = yield client.journeys(birkenwerder, lehnitz, { + via: borgsdorf, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) + t.ok(i1 < 0, 'routing engine changes at Borgsdorf') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) + t.ok(l, 'no stopover at Borgsdorf') t.end() })) diff --git a/test/vbb.js b/test/vbb.js index 29b41d63..4b8dd0d0 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -302,20 +302,71 @@ test('journeys – station to POI', co(function* (t) { -test('journeys – with stopover', co(function* (t) { - const halleschesTor = '900000012103' - const leopoldplatz = '900000009102' - const [journey] = yield client.journeys(spichernstr, halleschesTor, { - via: leopoldplatz, - results: 1 +test('journeys: via works – changing trains', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without changing + // is currently impossible. We check if the routing engine lets us change + // at Württembergallee if we set it as via. + const westhafen = '900000001201' + const wedding = '900000009104' + const württembergallee = '900000026153' + const [journey] = yield client.journeys(westhafen, wedding, { + via: württembergallee, + results: 1, + when }) - const i = journey.legs.findIndex(leg => leg.destination.id === leopoldplatz) - t.ok(i >= 0, 'no leg with Leopoldplatz as destination') + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) + t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const nextLeg = journey.legs[i + 1] - t.ok(nextLeg) - t.equal(nextLeg.origin.id, leopoldplatz) + const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) + t.ok(i2 >= 0, 'no leg with Württembergallee as origin') + t.ok(i2 >= i1) + + t.end() +})) + +test('journeys: via works – *without* changing trains', co(function* (t) { + // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* + // to change trains. We check if the routing engine *does not* require + // one to change at the via station. + const ruhleben = '900000025202' + const zoo = '900000023201' + const kastanienallee = '900000020152' + const [journey] = yield client.journeys(ruhleben, zoo, { + via: kastanienallee, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) + t.ok(i1 < 0, 'routing engine changes at Kastanienallee') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + t.ok(l, 'no stopover at Kastanienallee') + + t.end() +})) + +test('journeys: via works – even if on the obvious path', co(function* (t) { + const birkenwerder = '900000200008' + const borgsdorf = '900000200007' + const lehnitz = '900000200006' + const [journey] = yield client.journeys(birkenwerder, lehnitz, { + via: borgsdorf, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) + t.ok(i1 < 0, 'routing engine changes at Borgsdorf') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) + t.ok(l, 'no stopover at Borgsdorf') t.end() })) From cd63078b83fd33ab024acbcaf6ed838e07b6b8fd Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:22:00 +0100 Subject: [PATCH 02/17] =?UTF-8?q?add=20=C3=B6bb=20via=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/oebb.js | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/test/oebb.js b/test/oebb.js index 178c58db..0378d1e8 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -257,19 +257,47 @@ test('Albertina to Salzburg Hbf', co(function* (t) { t.end() })) -test('Wien to Klagenfurt Hbf with stopover at Salzburg Hbf', co(function* (t) { - const [journey] = yield client.journeys(wien, klagenfurtHbf, { - via: salzburgHbf, +test('journeys: via works – with detour', co(function* (t) { + // Going from Stephansplatz to Schottenring via Donauinsel without detour + // is currently impossible + const stephansplatz = '001390167' + const schottenring = '001390163' + const donauinsel = '001392277' + const donauinselPassed = '922001' + const [journey] = yield client.journeys(stephansplatz, schottenring, { + via: donauinsel, results: 1, - when + when, + passedStations: true }) - const i1 = journey.legs.findIndex(leg => leg.destination.id === salzburgHbf) - t.ok(i1 >= 0, 'no leg with Salzburg Hbf as destination') + t.ok(journey) - const i2 = journey.legs.findIndex(leg => leg.origin.id === salzburgHbf) - t.ok(i2 >= 0, 'no leg with Salzburg Hbf as origin') - t.ok(i2 > i1, 'leg with Salzburg Hbf as origin must be after leg to it') + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === donauinselPassed)) + t.ok(l, 'no stopover at Donauinsel') + + t.end() +})) + +test('journeys: via works – without detour', co(function* (t) { + // When going from Karlsplatz to Praterstern via Museumsquartier, there is *no need* + // to change trains / no need for a "detour". + const karlsplatz = '001390461' + const praterstern = '001290201' + const museumsquartier = '001390171' + const museumsquartierPassed = '901014' + + const [journey] = yield client.journeys(karlsplatz, praterstern, { + via: museumsquartier, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === museumsquartierPassed)) + t.ok(l, 'no stopover at Weihburggasse') t.end() })) From 9ce1e836215578724bd3558cf9e1b49b409efe59 Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:30:49 +0100 Subject: [PATCH 03/17] update db,vbb via tests --- test/db.js | 47 ++++++++++------------------------------------- test/vbb.js | 51 ++++++++++----------------------------------------- 2 files changed, 20 insertions(+), 78 deletions(-) diff --git a/test/db.js b/test/db.js index a9a4e770..527d4318 100644 --- a/test/db.js +++ b/test/db.js @@ -217,34 +217,30 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { t.end() })) -test('journeys: via works – changing trains', co(function* (t) { - // Going from Westhafen to Wedding via Württembergalle without changing - // is currently impossible. We check if the routing engine lets us change - // at Württembergallee if we set it as via. +test('journeys: via works – with detour', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without detour + // is currently impossible const westhafen = '008089116' const wedding = '008089131' const württembergallee = '731084' const [journey] = yield client.journeys(westhafen, wedding, { via: württembergallee, results: 1, - when + when, + passedStations: true }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) - t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) - t.ok(i2 >= 0, 'no leg with Württembergallee as origin') - t.ok(i2 >= i1) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) + t.ok(l, 'no stopover at Württembergalle') t.end() })) -test('journeys: via works – *without* changing trains', co(function* (t) { +test('journeys: via works – without detour', co(function* (t) { // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* - // to change trains. We check if the routing engine *does not* require - // one to change at the via station. + // to change trains / no need for a "detour". const ruhleben = '000731058' const zoo = '008010406' const kastanienallee = '730983' @@ -256,36 +252,13 @@ test('journeys: via works – *without* changing trains', co(function* (t) { }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) - t.ok(i1 < 0, 'routing engine changes at Kastanienallee') - const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) t.ok(l, 'no stopover at Kastanienallee') t.end() })) -test('journeys: via works – even if on the obvious path', co(function* (t) { - const birkenwerder = '008080190' - const borgsdorf = '8080200' - const lehnitz = '008081722' - const [journey] = yield client.journeys(birkenwerder, lehnitz, { - via: borgsdorf, - results: 1, - when, - passedStations: true - }) - - t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) - t.ok(i1 < 0, 'routing engine changes at Borgsdorf') - - const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) - t.ok(l, 'no stopover at Borgsdorf') - - t.end() -})) - test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { const model = yield client.journeys(jungfernh, münchenHbf, { results: 3, when diff --git a/test/vbb.js b/test/vbb.js index 4b8dd0d0..6906a5db 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -300,36 +300,30 @@ test('journeys – station to POI', co(function* (t) { t.end() })) - - -test('journeys: via works – changing trains', co(function* (t) { - // Going from Westhafen to Wedding via Württembergalle without changing - // is currently impossible. We check if the routing engine lets us change - // at Württembergallee if we set it as via. +test('journeys: via works – with detour', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without detour + // is currently impossible const westhafen = '900000001201' const wedding = '900000009104' const württembergallee = '900000026153' const [journey] = yield client.journeys(westhafen, wedding, { via: württembergallee, results: 1, - when + when, + passedStations: true }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) - t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) - t.ok(i2 >= 0, 'no leg with Württembergallee as origin') - t.ok(i2 >= i1) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) + t.ok(l, 'no stopover at Württembergalle') t.end() })) -test('journeys: via works – *without* changing trains', co(function* (t) { +test('journeys: via works – without detour', co(function* (t) { // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* - // to change trains. We check if the routing engine *does not* require - // one to change at the via station. + // to change trains / no need for a "detour". const ruhleben = '900000025202' const zoo = '900000023201' const kastanienallee = '900000020152' @@ -341,38 +335,13 @@ test('journeys: via works – *without* changing trains', co(function* (t) { }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) - t.ok(i1 < 0, 'routing engine changes at Kastanienallee') - const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) t.ok(l, 'no stopover at Kastanienallee') t.end() })) -test('journeys: via works – even if on the obvious path', co(function* (t) { - const birkenwerder = '900000200008' - const borgsdorf = '900000200007' - const lehnitz = '900000200006' - const [journey] = yield client.journeys(birkenwerder, lehnitz, { - via: borgsdorf, - results: 1, - when, - passedStations: true - }) - - t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) - t.ok(i1 < 0, 'routing engine changes at Borgsdorf') - - const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) - t.ok(l, 'no stopover at Borgsdorf') - - t.end() -})) - - - test('departures', co(function* (t) { const deps = yield client.departures(spichernstr, {duration: 5, when}) From 9b315ec7194125ba61302aa476de6d69c28a866a Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:34:37 +0100 Subject: [PATCH 04/17] clarify code comments --- test/db.js | 2 +- test/oebb.js | 2 +- test/vbb.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/db.js b/test/db.js index 527d4318..5af0b434 100644 --- a/test/db.js +++ b/test/db.js @@ -219,7 +219,7 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { test('journeys: via works – with detour', co(function* (t) { // Going from Westhafen to Wedding via Württembergalle without detour - // is currently impossible + // is currently impossible. We check if the routing engine computes a detour. const westhafen = '008089116' const wedding = '008089131' const württembergallee = '731084' diff --git a/test/oebb.js b/test/oebb.js index 0378d1e8..84e9be23 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -259,7 +259,7 @@ test('Albertina to Salzburg Hbf', co(function* (t) { test('journeys: via works – with detour', co(function* (t) { // Going from Stephansplatz to Schottenring via Donauinsel without detour - // is currently impossible + // is currently impossible. We check if the routing engine computes a detour. const stephansplatz = '001390167' const schottenring = '001390163' const donauinsel = '001392277' diff --git a/test/vbb.js b/test/vbb.js index 6906a5db..38b83298 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -302,7 +302,7 @@ test('journeys – station to POI', co(function* (t) { test('journeys: via works – with detour', co(function* (t) { // Going from Westhafen to Wedding via Württembergalle without detour - // is currently impossible + // is currently impossible. We check if the routing engine computes a detour. const westhafen = '900000001201' const wedding = '900000009104' const württembergallee = '900000026153' From 51e41ba4e59f91dce2108df0cb5216dd2345ca1e Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:38:08 +0100 Subject: [PATCH 05/17] clarify code comments --- test/db.js | 4 ++-- test/oebb.js | 4 ++-- test/vbb.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/db.js b/test/db.js index 5af0b434..0c623d73 100644 --- a/test/db.js +++ b/test/db.js @@ -233,7 +233,7 @@ test('journeys: via works – with detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) - t.ok(l, 'no stopover at Württembergalle') + t.ok(l, 'Württembergalle is not being passed') t.end() })) @@ -254,7 +254,7 @@ test('journeys: via works – without detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) - t.ok(l, 'no stopover at Kastanienallee') + t.ok(l, 'Kastanienallee is not being passed') t.end() })) diff --git a/test/oebb.js b/test/oebb.js index 84e9be23..62e6412b 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -274,7 +274,7 @@ test('journeys: via works – with detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === donauinselPassed)) - t.ok(l, 'no stopover at Donauinsel') + t.ok(l, 'Donauinsel is not being passed') t.end() })) @@ -297,7 +297,7 @@ test('journeys: via works – without detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === museumsquartierPassed)) - t.ok(l, 'no stopover at Weihburggasse') + t.ok(l, 'Weihburggasse is not being passed') t.end() })) diff --git a/test/vbb.js b/test/vbb.js index 38b83298..778c432b 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -316,7 +316,7 @@ test('journeys: via works – with detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) - t.ok(l, 'no stopover at Württembergalle') + t.ok(l, 'Württembergalle is not being passed') t.end() })) @@ -337,7 +337,7 @@ test('journeys: via works – without detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) - t.ok(l, 'no stopover at Kastanienallee') + t.ok(l, 'Kastanienallee is not being passed') t.end() })) From 848c2a2e6feed321b37d7f94ca3e5b129a9c7f3d Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 6 Mar 2018 02:47:05 +0100 Subject: [PATCH 06/17] DB, VBB: proper via tests :white_check_mark: --- test/db.js | 71 ++++++++++++++++++++++++++++++++++++++++++++------- test/vbb.js | 73 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 124 insertions(+), 20 deletions(-) diff --git a/test/db.js b/test/db.js index ffaca334..0269256b 100644 --- a/test/db.js +++ b/test/db.js @@ -218,18 +218,71 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { t.end() })) -test('Berlin Hbf to München Hbf with stopover at Hannover Hbf', co(function* (t) { - const [journey] = yield client.journeys(berlinHbf, münchenHbf, { - via: hannoverHbf, - results: 1 +test('journeys: via works – changing trains', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without changing + // is currently impossible. We check if the routing engine lets us change + // at Württembergallee if we set it as via. + const westhafen = '008089116' + const wedding = '008089131' + const württembergallee = '731084' + const [journey] = yield client.journeys(westhafen, wedding, { + via: württembergallee, + results: 1, + when }) - const i = journey.legs.findIndex(leg => leg.destination.id === hannoverHbf) - t.ok(i >= 0, 'no leg with Hannover Hbf as destination') + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) + t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const nextLeg = journey.legs[i + 1] - t.ok(nextLeg) - t.equal(nextLeg.origin.id, hannoverHbf) + const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) + t.ok(i2 >= 0, 'no leg with Württembergallee as origin') + t.ok(i2 >= i1) + + t.end() +})) + +test('journeys: via works – *without* changing trains', co(function* (t) { + // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* + // to change trains. We check if the routing engine *does not* require + // one to change at the via station. + const ruhleben = '000731058' + const zoo = '008010406' + const kastanienallee = '730983' + const [journey] = yield client.journeys(ruhleben, zoo, { + via: kastanienallee, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) + t.ok(i1 < 0, 'routing engine changes at Kastanienallee') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + t.ok(l, 'no stopover at Kastanienallee') + + t.end() +})) + +test('journeys: via works – even if on the obvious path', co(function* (t) { + const birkenwerder = '008080190' + const borgsdorf = '8080200' + const lehnitz = '008081722' + const [journey] = yield client.journeys(birkenwerder, lehnitz, { + via: borgsdorf, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) + t.ok(i1 < 0, 'routing engine changes at Borgsdorf') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) + t.ok(l, 'no stopover at Borgsdorf') t.end() })) diff --git a/test/vbb.js b/test/vbb.js index 29b41d63..4b8dd0d0 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -302,20 +302,71 @@ test('journeys – station to POI', co(function* (t) { -test('journeys – with stopover', co(function* (t) { - const halleschesTor = '900000012103' - const leopoldplatz = '900000009102' - const [journey] = yield client.journeys(spichernstr, halleschesTor, { - via: leopoldplatz, - results: 1 +test('journeys: via works – changing trains', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without changing + // is currently impossible. We check if the routing engine lets us change + // at Württembergallee if we set it as via. + const westhafen = '900000001201' + const wedding = '900000009104' + const württembergallee = '900000026153' + const [journey] = yield client.journeys(westhafen, wedding, { + via: württembergallee, + results: 1, + when }) - const i = journey.legs.findIndex(leg => leg.destination.id === leopoldplatz) - t.ok(i >= 0, 'no leg with Leopoldplatz as destination') + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) + t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const nextLeg = journey.legs[i + 1] - t.ok(nextLeg) - t.equal(nextLeg.origin.id, leopoldplatz) + const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) + t.ok(i2 >= 0, 'no leg with Württembergallee as origin') + t.ok(i2 >= i1) + + t.end() +})) + +test('journeys: via works – *without* changing trains', co(function* (t) { + // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* + // to change trains. We check if the routing engine *does not* require + // one to change at the via station. + const ruhleben = '900000025202' + const zoo = '900000023201' + const kastanienallee = '900000020152' + const [journey] = yield client.journeys(ruhleben, zoo, { + via: kastanienallee, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) + t.ok(i1 < 0, 'routing engine changes at Kastanienallee') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + t.ok(l, 'no stopover at Kastanienallee') + + t.end() +})) + +test('journeys: via works – even if on the obvious path', co(function* (t) { + const birkenwerder = '900000200008' + const borgsdorf = '900000200007' + const lehnitz = '900000200006' + const [journey] = yield client.journeys(birkenwerder, lehnitz, { + via: borgsdorf, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) + t.ok(i1 < 0, 'routing engine changes at Borgsdorf') + + const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) + t.ok(l, 'no stopover at Borgsdorf') t.end() })) From 28641cd7111cadee1375ae8a6cf067318fa62364 Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:22:00 +0100 Subject: [PATCH 07/17] =?UTF-8?q?add=20=C3=B6bb=20via=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/oebb.js | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/test/oebb.js b/test/oebb.js index 73d8c685..fd0f7713 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -258,19 +258,47 @@ test('Albertina to Salzburg Hbf', co(function* (t) { t.end() })) -test('Wien to Klagenfurt Hbf with stopover at Salzburg Hbf', co(function* (t) { - const [journey] = yield client.journeys(wien, klagenfurtHbf, { - via: salzburgHbf, +test('journeys: via works – with detour', co(function* (t) { + // Going from Stephansplatz to Schottenring via Donauinsel without detour + // is currently impossible + const stephansplatz = '001390167' + const schottenring = '001390163' + const donauinsel = '001392277' + const donauinselPassed = '922001' + const [journey] = yield client.journeys(stephansplatz, schottenring, { + via: donauinsel, results: 1, - when + when, + passedStations: true }) - const i1 = journey.legs.findIndex(leg => leg.destination.id === salzburgHbf) - t.ok(i1 >= 0, 'no leg with Salzburg Hbf as destination') + t.ok(journey) - const i2 = journey.legs.findIndex(leg => leg.origin.id === salzburgHbf) - t.ok(i2 >= 0, 'no leg with Salzburg Hbf as origin') - t.ok(i2 > i1, 'leg with Salzburg Hbf as origin must be after leg to it') + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === donauinselPassed)) + t.ok(l, 'no stopover at Donauinsel') + + t.end() +})) + +test('journeys: via works – without detour', co(function* (t) { + // When going from Karlsplatz to Praterstern via Museumsquartier, there is *no need* + // to change trains / no need for a "detour". + const karlsplatz = '001390461' + const praterstern = '001290201' + const museumsquartier = '001390171' + const museumsquartierPassed = '901014' + + const [journey] = yield client.journeys(karlsplatz, praterstern, { + via: museumsquartier, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === museumsquartierPassed)) + t.ok(l, 'no stopover at Weihburggasse') t.end() })) From 429d0d1f0cfd99e9fd123f1ea4ee01e321b0df34 Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:30:49 +0100 Subject: [PATCH 08/17] update db,vbb via tests --- test/db.js | 47 ++++++++++------------------------------------- test/vbb.js | 51 ++++++++++----------------------------------------- 2 files changed, 20 insertions(+), 78 deletions(-) diff --git a/test/db.js b/test/db.js index 0269256b..b16b2c19 100644 --- a/test/db.js +++ b/test/db.js @@ -218,34 +218,30 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { t.end() })) -test('journeys: via works – changing trains', co(function* (t) { - // Going from Westhafen to Wedding via Württembergalle without changing - // is currently impossible. We check if the routing engine lets us change - // at Württembergallee if we set it as via. +test('journeys: via works – with detour', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without detour + // is currently impossible const westhafen = '008089116' const wedding = '008089131' const württembergallee = '731084' const [journey] = yield client.journeys(westhafen, wedding, { via: württembergallee, results: 1, - when + when, + passedStations: true }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) - t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) - t.ok(i2 >= 0, 'no leg with Württembergallee as origin') - t.ok(i2 >= i1) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) + t.ok(l, 'no stopover at Württembergalle') t.end() })) -test('journeys: via works – *without* changing trains', co(function* (t) { +test('journeys: via works – without detour', co(function* (t) { // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* - // to change trains. We check if the routing engine *does not* require - // one to change at the via station. + // to change trains / no need for a "detour". const ruhleben = '000731058' const zoo = '008010406' const kastanienallee = '730983' @@ -257,36 +253,13 @@ test('journeys: via works – *without* changing trains', co(function* (t) { }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) - t.ok(i1 < 0, 'routing engine changes at Kastanienallee') - const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) t.ok(l, 'no stopover at Kastanienallee') t.end() })) -test('journeys: via works – even if on the obvious path', co(function* (t) { - const birkenwerder = '008080190' - const borgsdorf = '8080200' - const lehnitz = '008081722' - const [journey] = yield client.journeys(birkenwerder, lehnitz, { - via: borgsdorf, - results: 1, - when, - passedStations: true - }) - - t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) - t.ok(i1 < 0, 'routing engine changes at Borgsdorf') - - const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) - t.ok(l, 'no stopover at Borgsdorf') - - t.end() -})) - test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { const model = yield client.journeys(jungfernh, münchenHbf, { results: 3, when diff --git a/test/vbb.js b/test/vbb.js index 4b8dd0d0..6906a5db 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -300,36 +300,30 @@ test('journeys – station to POI', co(function* (t) { t.end() })) - - -test('journeys: via works – changing trains', co(function* (t) { - // Going from Westhafen to Wedding via Württembergalle without changing - // is currently impossible. We check if the routing engine lets us change - // at Württembergallee if we set it as via. +test('journeys: via works – with detour', co(function* (t) { + // Going from Westhafen to Wedding via Württembergalle without detour + // is currently impossible const westhafen = '900000001201' const wedding = '900000009104' const württembergallee = '900000026153' const [journey] = yield client.journeys(westhafen, wedding, { via: württembergallee, results: 1, - when + when, + passedStations: true }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === württembergallee) - t.ok(i1 >= 0, 'no leg with Württembergallee as destination') - const i2 = journey.legs.findIndex(l => l.origin.id === württembergallee) - t.ok(i2 >= 0, 'no leg with Württembergallee as origin') - t.ok(i2 >= i1) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) + t.ok(l, 'no stopover at Württembergalle') t.end() })) -test('journeys: via works – *without* changing trains', co(function* (t) { +test('journeys: via works – without detour', co(function* (t) { // When going from Ruhleben to Zoo via Kastanienallee, there is *no need* - // to change trains. We check if the routing engine *does not* require - // one to change at the via station. + // to change trains / no need for a "detour". const ruhleben = '900000025202' const zoo = '900000023201' const kastanienallee = '900000020152' @@ -341,38 +335,13 @@ test('journeys: via works – *without* changing trains', co(function* (t) { }) t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === kastanienallee) - t.ok(i1 < 0, 'routing engine changes at Kastanienallee') - const l = journey.legs.some(l => l.passed.some(p => p.station.id === kastanienallee)) + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) t.ok(l, 'no stopover at Kastanienallee') t.end() })) -test('journeys: via works – even if on the obvious path', co(function* (t) { - const birkenwerder = '900000200008' - const borgsdorf = '900000200007' - const lehnitz = '900000200006' - const [journey] = yield client.journeys(birkenwerder, lehnitz, { - via: borgsdorf, - results: 1, - when, - passedStations: true - }) - - t.ok(journey) - const i1 = journey.legs.findIndex(l => l.destination.id === borgsdorf) - t.ok(i1 < 0, 'routing engine changes at Borgsdorf') - - const l = journey.legs.some(l => l.passed.some(p => p.station.id === borgsdorf)) - t.ok(l, 'no stopover at Borgsdorf') - - t.end() -})) - - - test('departures', co(function* (t) { const deps = yield client.departures(spichernstr, {duration: 5, when}) From 803b4573c1c999907d3b40882224b61c7dfeeb78 Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:34:37 +0100 Subject: [PATCH 09/17] clarify code comments --- test/db.js | 2 +- test/oebb.js | 2 +- test/vbb.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/db.js b/test/db.js index b16b2c19..27242e4a 100644 --- a/test/db.js +++ b/test/db.js @@ -220,7 +220,7 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { test('journeys: via works – with detour', co(function* (t) { // Going from Westhafen to Wedding via Württembergalle without detour - // is currently impossible + // is currently impossible. We check if the routing engine computes a detour. const westhafen = '008089116' const wedding = '008089131' const württembergallee = '731084' diff --git a/test/oebb.js b/test/oebb.js index fd0f7713..a7f5d473 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -260,7 +260,7 @@ test('Albertina to Salzburg Hbf', co(function* (t) { test('journeys: via works – with detour', co(function* (t) { // Going from Stephansplatz to Schottenring via Donauinsel without detour - // is currently impossible + // is currently impossible. We check if the routing engine computes a detour. const stephansplatz = '001390167' const schottenring = '001390163' const donauinsel = '001392277' diff --git a/test/vbb.js b/test/vbb.js index 6906a5db..38b83298 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -302,7 +302,7 @@ test('journeys – station to POI', co(function* (t) { test('journeys: via works – with detour', co(function* (t) { // Going from Westhafen to Wedding via Württembergalle without detour - // is currently impossible + // is currently impossible. We check if the routing engine computes a detour. const westhafen = '900000001201' const wedding = '900000009104' const württembergallee = '900000026153' From 361758c5781a165d348475225bc99a1b2239d6be Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 14:38:08 +0100 Subject: [PATCH 10/17] clarify code comments --- test/db.js | 4 ++-- test/oebb.js | 4 ++-- test/vbb.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/db.js b/test/db.js index 27242e4a..62f39074 100644 --- a/test/db.js +++ b/test/db.js @@ -234,7 +234,7 @@ test('journeys: via works – with detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) - t.ok(l, 'no stopover at Württembergalle') + t.ok(l, 'Württembergalle is not being passed') t.end() })) @@ -255,7 +255,7 @@ test('journeys: via works – without detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) - t.ok(l, 'no stopover at Kastanienallee') + t.ok(l, 'Kastanienallee is not being passed') t.end() })) diff --git a/test/oebb.js b/test/oebb.js index a7f5d473..7427b6db 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -275,7 +275,7 @@ test('journeys: via works – with detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === donauinselPassed)) - t.ok(l, 'no stopover at Donauinsel') + t.ok(l, 'Donauinsel is not being passed') t.end() })) @@ -298,7 +298,7 @@ test('journeys: via works – without detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === museumsquartierPassed)) - t.ok(l, 'no stopover at Weihburggasse') + t.ok(l, 'Weihburggasse is not being passed') t.end() })) diff --git a/test/vbb.js b/test/vbb.js index 38b83298..778c432b 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -316,7 +316,7 @@ test('journeys: via works – with detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee)) - t.ok(l, 'no stopover at Württembergalle') + t.ok(l, 'Württembergalle is not being passed') t.end() })) @@ -337,7 +337,7 @@ test('journeys: via works – without detour', co(function* (t) { t.ok(journey) const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee)) - t.ok(l, 'no stopover at Kastanienallee') + t.ok(l, 'Kastanienallee is not being passed') t.end() })) From 06cc37b45f4c2ad439812b10c694c676997bdc99 Mon Sep 17 00:00:00 2001 From: Julius Tens Date: Fri, 16 Mar 2018 15:32:19 +0100 Subject: [PATCH 11/17] update insa via tests --- test/insa.js | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/test/insa.js b/test/insa.js index f22581d6..28679120 100644 --- a/test/insa.js +++ b/test/insa.js @@ -189,22 +189,47 @@ test('Kloster Unser Lieben Frauen to Magdeburg Hbf', co(function*(t) { t.end() })) -test('Magdeburg-Buckau to Magdeburg-Neustadt with stopover at Magdeburg Hbf', co(function*(t) { - const magdeburgBuckau = '8013456' - const magdeburgNeustadt = '8010226' - const magdeburgHbf = '8010224' - const [journey] = yield client.journeys(magdeburgBuckau, magdeburgNeustadt, { - via: magdeburgHbf, +test('journeys: via works – with detour', co(function* (t) { + // Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal via Dessau without detour + // is currently impossible. We check if the routing engine computes a detour. + const hasselbachplatzSternstrasse = '000006545' + const stendal = '008010334' + const dessau = '008010077' + const dessauPassed = '8010077' + const [journey] = yield client.journeys(hasselbachplatzSternstrasse, stendal, { + via: dessau, results: 1, - when + when, + passedStations: true }) - const i1 = journey.legs.findIndex(leg => leg.destination.id === magdeburgHbf) - t.ok(i1 >= 0, 'no leg with Magdeburg Hbf as destination') + t.ok(journey) - const i2 = journey.legs.findIndex(leg => leg.origin.id === magdeburgHbf) - t.ok(i2 >= 0, 'no leg with Magdeburg Hbf as origin') - t.ok(i2 > i1, 'leg with Magdeburg Hbf as origin must be after leg to it') + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === dessauPassed)) + t.ok(l, 'Dessau is not being passed') + + t.end() +})) + +test('journeys: via works – without detour', co(function* (t) { + // When going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Magdeburg, Universität via Magdeburg, Breiter Weg, there is *no need* + // to change trains / no need for a "detour". + const hasselbachplatzSternstrasse = '000006545' + const universitaet = '000019686' + const breiterWeg = '000013519' + const breiterWegPassed = '13519' + + const [journey] = yield client.journeys(hasselbachplatzSternstrasse, universitaet, { + via: breiterWeg, + results: 1, + when, + passedStations: true + }) + + t.ok(journey) + + const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === breiterWegPassed)) + t.ok(l, 'Magdeburg, Breiter Weg is not being passed') t.end() })) From f96131423fe19b4bd33d60962946714f6c48c6ec Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 16 Mar 2018 17:13:19 +0100 Subject: [PATCH 12/17] luxon@0.5.8, query-string@6, tape-promise@3 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4d704a6a..86e84a15 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,10 @@ "capture-stack-trace": "^1.0.0", "fetch-ponyfill": "^6.0.0", "lodash": "^4.17.5", - "luxon": "^0.5.6", + "luxon": "^0.5.8", "p-throttle": "^1.1.0", "pinkie-promise": "^2.0.1", - "query-string": "^5.1.0", + "query-string": "^6.0.0", "slugg": "^1.2.0", "vbb-parse-line": "^0.3.1", "vbb-parse-ticket": "^0.2.1", @@ -52,7 +52,7 @@ "is-roughly-equal": "^0.1.0", "tap-spec": "^4.1.1", "tape": "^4.8.0", - "tape-promise": "^2.0.1", + "tape-promise": "^3.0.0", "validate-fptf": "^1.2.1", "vbb-stations-autocomplete": "^3.1.0" }, From 6ba617b1bcde034b11f2a6f877c6447cd7427519 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 17 Mar 2018 16:41:57 +0100 Subject: [PATCH 13/17] let parseMovement use parseStopover :bug: --- p/vbb/index.js | 4 ++-- parse/journey-leg.js | 2 +- parse/movement.js | 29 ++--------------------------- parse/stopover.js | 6 +++--- 4 files changed, 8 insertions(+), 33 deletions(-) diff --git a/p/vbb/index.js b/p/vbb/index.js index 3f9f9ecd..af4b86fd 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -99,8 +99,8 @@ const createParseJourney = (profile, stations, lines, remarks) => { return parseJourneyWithTickets } -const createParseStopover = (profile, stations, lines, remarks, connection) => { - const parseStopover = _createParseStopover(profile, stations, lines, remarks, connection) +const createParseStopover = (profile, stations, lines, remarks, date) => { + const parseStopover = _createParseStopover(profile, stations, lines, remarks, date) const parseStopoverWithShorten = (st) => { const res = parseStopover(st) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 3c0651bc..c226da83 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -47,7 +47,7 @@ const createParseJourneyLeg = (profile, stations, lines, remarks) => { if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS if (passed && pt.jny.stopL) { - const parse = profile.parseStopover(profile, stations, lines, remarks, j) + const parse = profile.parseStopover(profile, stations, lines, remarks, j.date) const passedStations = pt.jny.stopL.map(parse) // filter stations the train passes without stopping, as this doesn't comply with fptf (yet) res.passed = passedStations.filter((x) => !x.passBy) diff --git a/parse/movement.js b/parse/movement.js index e03a3821..4a006026 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -9,32 +9,7 @@ const createParseMovement = (profile, locations, lines, remarks) => { // todo: what is m.ani.proc[n]? wut? // todo: how does m.ani.poly work? const parseMovement = (m) => { - const parseNextStop = (s) => { - const dep = s.dTimeR || s.dTimeS - ? profile.parseDateTime(profile, m.date, s.dTimeR || s.dTimeS) - : null - const arr = s.aTimeR || s.aTimeS - ? profile.parseDateTime(profile, m.date, s.aTimeR || s.aTimeS) - : null - - const res = { - station: locations[s.locX], - departure: dep ? dep.toISO() : null, - arrival: arr ? arr.toISO() : null - } - - if (m.dTimeR && m.dTimeS) { - const plannedDep = profile.parseDateTime(profile, m.date, s.dTimeS) - res.departureDelay = Math.round((dep - plannedDep) / 1000) - } else res.departureDelay = null - - if (m.aTimeR && m.aTimeS) { - const plannedArr = profile.parseDateTime(profile, m.date, s.aTimeS) - res.arrivalDelay = Math.round((arr - plannedArr) / 1000) - } else res.arrivalDelay = null - - return res - } + const pStopover = profile.parseStopover(profile, locations, lines, remarks, m.date) const res = { direction: profile.parseStationName(m.dirTxt), @@ -45,7 +20,7 @@ const createParseMovement = (profile, locations, lines, remarks) => { latitude: m.pos.y / 1000000, longitude: m.pos.x / 1000000 } : null, - nextStops: m.stopL.map(parseNextStop), + nextStops: m.stopL.map(pStopover), frames: [] } diff --git a/parse/stopover.js b/parse/stopover.js index e17e1be3..0140ff57 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -2,17 +2,17 @@ // todo: arrivalDelay, departureDelay or only delay ? // todo: arrivalPlatform, departurePlatform -const createParseStopover = (profile, stations, lines, remarks, connection) => { +const createParseStopover = (profile, stations, lines, remarks, date) => { const parseStopover = (st) => { const res = { station: stations[parseInt(st.locX)] || null } if (st.aTimeR || st.aTimeS) { - const arr = profile.parseDateTime(profile, connection.date, st.aTimeR || st.aTimeS) + const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS) res.arrival = arr.toISO() } if (st.dTimeR || st.dTimeS) { - const dep = profile.parseDateTime(profile, connection.date, st.dTimeR || st.dTimeS) + const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS) res.departure = dep.toISO() } From 787b00228ee161ec674bfcfbcb32096244bae3e4 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 17 Mar 2018 16:47:18 +0100 Subject: [PATCH 14/17] let parseStopover use parseStationName :bug: --- p/vbb/index.js | 16 ---------------- parse/location.js | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/p/vbb/index.js b/p/vbb/index.js index af4b86fd..f7ff4643 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -9,7 +9,6 @@ const getStations = require('vbb-stations') const _createParseLine = require('../../parse/line') const _parseLocation = require('../../parse/location') const _createParseJourney = require('../../parse/journey') -const _createParseStopover = require('../../parse/stopover') const _createParseDeparture = require('../../parse/departure') const _formatStation = require('../../format/station') const createParseBitmask = require('../../parse/products-bitmask') @@ -99,20 +98,6 @@ const createParseJourney = (profile, stations, lines, remarks) => { return parseJourneyWithTickets } -const createParseStopover = (profile, stations, lines, remarks, date) => { - const parseStopover = _createParseStopover(profile, stations, lines, remarks, date) - - const parseStopoverWithShorten = (st) => { - const res = parseStopover(st) - if (res.station && res.station.name) { - res.station.name = shorten(res.station.name) - } - return res - } - - return parseStopoverWithShorten -} - const createParseDeparture = (profile, stations, lines, remarks) => { const parseDeparture = _createParseDeparture(profile, stations, lines, remarks) @@ -184,7 +169,6 @@ const vbbProfile = { parseProducts: createParseBitmask(modes.allProducts, defaultProducts), parseJourney: createParseJourney, parseDeparture: createParseDeparture, - parseStopover: createParseStopover, formatStation, formatProducts, diff --git a/parse/location.js b/parse/location.js index e6689e6b..1659ea92 100644 --- a/parse/location.js +++ b/parse/location.js @@ -19,7 +19,7 @@ const parseLocation = (profile, l, lines) => { const station = { type: 'station', id: l.extId, - name: l.name, + name: profile.parseStationName(l.name), location: 'number' === typeof res.latitude ? res : null } From 287883eda9e9e761a7cb059cf99786f53a39d5cf Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 17 Mar 2018 16:58:21 +0100 Subject: [PATCH 15/17] 2.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 86e84a15..c4f041f0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hafas-client", "description": "JavaScript client for HAFAS public transport APIs.", - "version": "2.4.0", + "version": "2.4.1", "main": "index.js", "files": [ "index.js", From bdad9c6ef6b05c77847b2a9dfbc9720b39ac319b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 17 Mar 2018 17:14:47 +0100 Subject: [PATCH 16/17] parseStopover: cancelled arrival & departure :bug: also clean up parseMovement and add DRY todos --- parse/departure.js | 4 ++-- parse/journey-leg.js | 26 +++++++++++++------------- parse/stopover.js | 22 ++++++++++++++-------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/parse/departure.js b/parse/departure.js index b074b426..3868c988 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -22,14 +22,14 @@ const createParseDeparture = (profile, stations, lines, remarks) => { } // todo: res.trip from rawLine.prodCtx.num? + // todo: DRY with parseStopover + // todo: DRY with parseJourneyLeg if (d.stbStop.dTimeR && d.stbStop.dTimeS) { const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR) const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS) res.delay = Math.round((realtime - planned) / 1000) } else res.delay = null - // todo: follow public-transport/friendly-public-transport-format#27 here - // see also derhuerst/vbb-rest#19 if (d.stbStop.aCncl || d.stbStop.dCncl) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index c226da83..30477270 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -71,21 +71,21 @@ const createParseJourneyLeg = (profile, stations, lines, remarks) => { } } - // todo: follow public-transport/friendly-public-transport-format#27 here - // see also derhuerst/vbb-rest#19 - if (pt.arr.aCncl) { + // todo: DRY with parseDeparture + // todo: DRY with parseStopover + if (pt.arr.aCncl || pt.dep.dCncl) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) - res.arrival = res.arrivalPlatform = res.arrivalDelay = null - const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) - res.formerScheduledArrival = arr.toISO() - } - if (pt.dep.dCncl) { - res.cancelled = true - Object.defineProperty(res, 'canceled', {value: true}) - res.departure = res.departurePlatform = res.departureDelay = null - const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) - res.formerScheduledDeparture = dep.toISO() + if (pt.arr.aCncl) { + res.arrival = res.arrivalPlatform = res.arrivalDelay = null + const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) + res.formerScheduledArrival = arr.toISO() + } + if (pt.dep.dCncl) { + res.departure = res.departurePlatform = res.departureDelay = null + const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) + res.formerScheduledDeparture = dep.toISO() + } } return res diff --git a/parse/stopover.js b/parse/stopover.js index 0140ff57..2a445bd6 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -19,15 +19,21 @@ const createParseStopover = (profile, stations, lines, remarks, date) => { // mark stations the train passes without stopping if(st.dInS === false && st.aOutS === false) res.passBy = true - // todo: follow public-transport/friendly-public-transport-format#27 here - // see also derhuerst/vbb-rest#19 - if (st.aCncl) { + // todo: DRY with parseDeparture + // todo: DRY with parseJourneyLeg + if (st.aCncl || st.dCncl) { res.cancelled = true - res.arrival = null - } - if (st.dCncl) { - res.cancelled = true - res.departure = null + Object.defineProperty(res, 'canceled', {value: true}) + if (st.aCncl) { + res.arrival = res.arrivalDelay = null + const arr = profile.parseDateTime(profile, d.date, st.aTimeS) + res.formerScheduledArrival = arr.toISO() + } + if (st.dCncl) { + res.departure = res.departureDelay = null + const arr = profile.parseDateTime(profile, d.date, st.dTimeS) + res.formerScheduledDeparture = arr.toISO() + } } return res From a36afa25a30bc5570c931e67144fb657eb112abe Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 17 Mar 2018 17:16:22 +0100 Subject: [PATCH 17/17] 2.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4f041f0..248c7325 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hafas-client", "description": "JavaScript client for HAFAS public transport APIs.", - "version": "2.4.1", + "version": "2.4.2", "main": "index.js", "files": [ "index.js",