diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-09-05 21:06:05 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-09-05 21:06:05 +0200 |
commit | ffeeb11e5a2142824accde644391c28ee3425127 (patch) | |
tree | 4ac0ec1cb604ca068fc029cd51fbb66cc3a6d897 /lib | |
parent | 0a7188d2e2b1c7caa173fbd58174af1a48dedccd (diff) |
get_connecting_trains_p: remove trains with identical routes to current one
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 007b725..a8a14ec 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -99,6 +99,7 @@ sub get_connecting_trains_p { @{ $stationboard->{results} }; my @results; my @cancellations; + my $excluded_train; my %via_count = map { $_ => 0 } @destinations; for my $train ( @{ $stationboard->{results} } ) { if ( not $train->departure ) { @@ -113,6 +114,7 @@ sub get_connecting_trains_p { if ( $exclude_train_id and $train->train_id eq $exclude_train_id ) { + $excluded_train = $train; next; } @@ -167,13 +169,27 @@ sub get_connecting_trains_p { map { [ $_, - $_->[0]->departure->epoch // $_->[0]->sched_departure->epoch + $_->[0]->departure->epoch + // $_->[0]->sched_departure->epoch ] } @results; @cancellations = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, $_->[0]->sched_departure->epoch ] } @cancellations; + # remove trains whose route matches the excluded one's + if ($excluded_train) { + my $route_pre = join( '|', reverse $excluded_train->route_pre ); + @results + = grep { join( '|', $_->[0]->route_post ) ne $route_pre } + @results; + my $route_post = join( '|', $excluded_train->route_post ); + @results + = grep { join( '|', $_->[0]->route_post ) ne $route_post } + @results; + } + + # add message IDs and 'transfer short' hints for my $result (@results) { my $train = $result->[0]; my @message_ids |