summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller/Traveling.pm
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-10-01 10:49:36 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-10-01 10:49:36 +0200
commitcbc433f76c13c1eaa2ed5f7b4dddc51e421153ec (patch)
tree094f2275f6be80be503f8a9eebc3d9773908cbb3 /lib/Travelynx/Controller/Traveling.pm
parent4a2897c1f812d3deb3b799b8c10b67dd2d1f11f6 (diff)
suggested connections: avoid fetching IRIS trains via HAFAS
Diffstat (limited to 'lib/Travelynx/Controller/Traveling.pm')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index 12bfd0f..a665758 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -65,8 +65,10 @@ sub get_connecting_trains_p {
return $promise->reject;
}
- my @destinations
- = uniq_by { $_->{name} } $self->journeys->get_connection_targets(%opt);
+ my ( $dest_ids, $destinations )
+ = $self->journeys->get_connection_targets(%opt);
+
+ my @destinations = uniq_by { $_->{name} } @{$destinations};
if ($exclude_via) {
@destinations = grep { $_->{name} ne $exclude_via } @destinations;
@@ -76,6 +78,12 @@ sub get_connecting_trains_p {
return $promise->reject;
}
+ my $iris_eva = $eva;
+ if ( $eva < 8000000 ) {
+ $iris_eva = ( List::Util::first { $_ >= 8000000 } @{$dest_ids} )
+ // $eva;
+ }
+
my $can_check_in = not $arr_epoch || ( $arr_countdown // 1 ) < 0;
my $lookahead
= $can_check_in ? 40 : ( ( ${arr_countdown} // 0 ) / 60 + 40 );
@@ -83,11 +91,11 @@ sub get_connecting_trains_p {
my $iris_promise = Mojo::Promise->new;
my %via_count = map { $_->{name} => 0 } @destinations;
- if ( $eva >= 8000000
+ if ( $iris_eva >= 8000000
and List::Util::any { $_->{eva} >= 8000000 } @destinations )
{
$self->iris->get_departures_p(
- station => $eva,
+ station => $iris_eva,
lookbehind => 10,
lookahead => $lookahead,
with_related => 1
@@ -323,6 +331,12 @@ sub get_connecting_trains_p {
if ( $hafas_train->{iris_seen} ) {
next;
}
+ if ( $iris_eva != $eva
+ and $hafas_train->station_eva == $iris_eva )
+ {
+ # better safe than sorry, for now
+ next;
+ }
for my $stop ( $hafas_train->route ) {
for my $dest (@destinations) {
if ( $stop->{name}