Commit 0bfb71d7 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add map view of past journeys. unfinished and unreferenced.

parent 35e9dae3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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');
+62 −0
Original line number Diff line number Diff line
@@ -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) = @_;

+1.23 KiB
Loading image diff...
+696 B
Loading image diff...
+2.41 KiB
Loading image diff...
Loading