diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-01-25 15:46:42 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-01-25 15:46:42 +0100 |
commit | 3e9807b393d8e1acc6b6f839aacc720c8908322b (patch) | |
tree | fe28e90aa7a65050772c7b187bd85dc801716666 /lib | |
parent | 1028e47a35a472fc4835f324f3ad195970b45b17 (diff) |
map, journey view: handle renamed stations1.13.8
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Travelynx.pm | 17 | ||||
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 16 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 97c9384..96b45be 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -197,8 +197,7 @@ sub startup { $self->attr( coordinates_by_station => sub { - my $legacy_names = JSON->new->utf8->decode( - scalar read_file('share/old_station_names.json') ); + my $legacy_names = $self->app->renamed_station; my %location; for my $station ( Travel::Status::DE::IRIS::Stations::get_stations() ) @@ -226,6 +225,14 @@ sub startup { ); $self->attr( + renamed_station => sub { + my $legacy_to_new = JSON->new->utf8->decode( + scalar read_file('share/old_station_names.json') ); + return $legacy_to_new; + } + ); + + $self->attr( station_by_eva => sub { my %map; for @@ -2710,6 +2717,12 @@ sub startup { } if ( $opt{verbose} ) { + my $rename = $self->app->renamed_station; + for my $stop ( @{ $ref->{route} } ) { + if ( $rename->{ $stop->[0] } ) { + $stop->[0] = $rename->{ $stop->[0] }; + } + } $ref->{cancelled} = $entry->{cancelled}; my @parsed_messages; for my $message ( @{ $ref->{messages} // [] } ) { diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 421032f..8d1a901 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -470,10 +470,24 @@ sub map_history { for my $journey (@journeys) { - my @route = map { $_->[0] } @{ $journey->{route} }; + my @route = map { $_->[0] } @{ $journey->{route} }; + my $from_index = first_index { $_ eq $journey->{from_name} } @route; my $to_index = first_index { $_ eq $journey->{to_name} } @route; + if ( $from_index == -1 ) { + my $rename = $self->app->renamed_station; + $from_index + = first_index { ( $rename->{$_} // $_ ) eq $journey->{from_name} } + @route; + } + if ( $to_index == -1 ) { + my $rename = $self->app->renamed_station; + $to_index + = first_index { ( $rename->{$_} // $_ ) eq $journey->{to_name} } + @route; + } + if ( $from_index == -1 or $to_index == -1 ) { |