diff options
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/Travelynx.pm | 1 | ||||
| -rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 62 | 
2 files changed, 63 insertions, 0 deletions
| diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index d7508dc..d2ee821 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -3000,6 +3000,7 @@ sub startup {  	$authed_r->get('/export.json')->to('account#json_export');  	$authed_r->get('/history.json')->to('traveling#json_history');  	$authed_r->get('/history')->to('traveling#history'); +	$authed_r->get('/history/map')->to('traveling#map_history');  	$authed_r->get('/history/:year')->to('traveling#yearly_history');  	$authed_r->get('/history/:year/:month')->to('traveling#monthly_history');  	$authed_r->get('/journey/add')->to('traveling#add_journey_form'); 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) = @_; | 
