From 0bfb71d78d1a7996fe0fb32af063ccfdc6ceea15 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 16 Nov 2019 00:01:50 +0100 Subject: add map view of past journeys. unfinished and unreferenced. --- lib/Travelynx/Controller/Traveling.pm | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'lib/Travelynx/Controller') diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 3fea24b..a3d5e67 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -3,6 +3,7 @@ use Mojo::Base 'Mojolicious::Controller'; use DateTime; use DateTime::Format::Strptime; +use List::Util qw(uniq); use List::UtilsBy qw(uniq_by); use Travel::Status::DE::IRIS::Stations; @@ -412,6 +413,67 @@ sub history { $self->render( template => 'history' ); } +sub map_history { + my ($self) = @_; + + my %location; + + for my $station ( Travel::Status::DE::IRIS::Stations::get_stations() ) { + if ( $station->[3] ) { + $location{ $station->[1] } = [ $station->[4], $station->[3] ]; + } + } + +# TODO create map-specific get_user_travels function returning EVA/DS100 station codes? + my @journeys = $self->get_user_travels; + + my @stations = uniq map { $_->{to_name} } @journeys; + push( @stations, uniq map { $_->{from_name} } @journeys ); + @stations = uniq @stations; + my @station_coordinates + = map { $location{$_} } grep { exists $location{$_} } @stations; + + my @uniq_by_route = uniq_by { + join( '|', map { $_->[0] } @{ $_->{route} } ) + } + @journeys; + my @station_pairs; + + for my $journey (@uniq_by_route) { + my @route = map { $_->[0] } @{ $journey->{route} }; + my $prev_station = shift @route; + my $within = 0; + for my $station (@route) { + if ( $prev_station eq $journey->{from_name} ) { + $within = 1; + } + if ($within) { + push( @station_pairs, [ $prev_station, $station ] ); + } + $prev_station = $station; + if ( $station eq $journey->{to_name} ) { + $within = 0; + } + } + } + + @station_pairs = uniq_by { $_->[0] . '|' . $_->[1] } @station_pairs; + @station_pairs + = grep { exists $location{ $_->[0] } and exists $location{ $_->[1] } } + @station_pairs; + @station_pairs + = map { [ $location{ $_->[0] }, $location{ $_->[1] } ] } @station_pairs; + + my @routes; + + $self->render( + template => 'map', + with_map => 1, + station_coordinates => \@station_coordinates, + station_pairs => \@station_pairs + ); +} + sub json_history { my ($self) = @_; -- cgit v1.2.3