Skip to content
Snippets Groups Projects
Commit cea4b71c authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

history map: skip duplicates earlier

parent 4f2eac9c
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ use DateTime; ...@@ -5,6 +5,7 @@ use DateTime;
use DateTime::Format::Strptime; use DateTime::Format::Strptime;
use List::Util qw(uniq); use List::Util qw(uniq);
use List::UtilsBy qw(uniq_by); use List::UtilsBy qw(uniq_by);
use List::MoreUtils qw(first_index);
use Travel::Status::DE::IRIS::Stations; use Travel::Status::DE::IRIS::Stations;
sub homepage { sub homepage {
...@@ -428,22 +429,35 @@ sub map_history { ...@@ -428,22 +429,35 @@ sub map_history {
grep { exists $location->{$_} } @stations; grep { exists $location->{$_} } @stations;
my @station_pairs; my @station_pairs;
my %seen;
for my $journey (@journeys) { 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 or $to_index == -1 ) {
next;
}
@route = @route[ $from_index .. $to_index ];
my $key = join( '|', @route );
if ( $seen{$key} ) {
next;
}
$seen{$key} = 1;
# direction does not matter at the moment
$seen{ join( '|', reverse @route ) } = 1;
my $prev_station = shift @route; my $prev_station = shift @route;
my $within = 0;
for my $station (@route) { for my $station (@route) {
if ( $prev_station eq $journey->{from_name} ) { push( @station_pairs, [ $prev_station, $station ] );
$within = 1;
}
if ($within) {
push( @station_pairs, [ $prev_station, $station ] );
}
$prev_station = $station; $prev_station = $station;
if ( $station eq $journey->{to_name} ) {
$within = 0;
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment