diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2019-11-16 00:01:50 +0100 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2019-11-16 00:01:50 +0100 | 
| commit | 0bfb71d78d1a7996fe0fb32af063ccfdc6ceea15 (patch) | |
| tree | 32e597a4dbb1a92fe06d704b8738c2cb6beed099 /lib/Travelynx | |
| parent | 35e9dae3499a4234836a2f858797e7b05f5d12c6 (diff) | |
add map view of past journeys. unfinished and unreferenced.
Diffstat (limited to 'lib/Travelynx')
| -rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 62 | 
1 files changed, 62 insertions, 0 deletions
| 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) = @_; | 
