Unverified Commit 3acb1b37 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

EFA suggestions: go back to a single template

parent b3300e3a
Loading
Loading
Loading
Loading
+15 −21
Original line number Diff line number Diff line
@@ -943,34 +943,28 @@ sub station {
				@results = map { $_->[0] }
				  sort { $b->[1] <=> $a->[1] }
				  map { [ $_, $_->datetime->epoch ] } $status->results;
				$status = {
					station_eva      => $status->stop->id_num,
					station_name     => $status->stop->full_name,
					related_stations => [],
				};
				my $backend_id
				  = $self->stations->get_backend_id( efa => $efa_service );
				my @destinations = $self->journeys->get_connection_targets(
					uid        => $uid,
					backend_id => $backend_id,
					eva        => $status->{station_eva},
					eva        => $status->stop->id_num,
				);
				for my $dep (@results) {
					destination: for my $dest (@destinations) {
						for my $stop ( $dep->route_post ) {
							if ( $stop->full_name eq $dest->{name} ) {
								push( @suggestions,
									[ $dep, $dest, $stop->arr ] );
								next destination;
							}
						}
					}
				}
				@suggestions = $self->efa->grep_suggestions(
					status       => $status,
					destinations => \@destinations
				);
				@suggestions = sort { $a->[0]{sort_ts} <=> $b->[0]{sort_ts} }
				  grep {
					      $_->[0]{sort_ts} >= $now - 300
					  and $_->[0]{sort_ts} <= $now + 1800
				  } @suggestions;

				@suggestions = map { $_->[0] }
				  sort { $a->[1] <=> $b->[1] }
				  grep { $_->[1] >= $now - 300 and $_->[1] <= $now + 1800 }
				  map  { [ $_, $_->[0]->datetime->epoch ] } @suggestions;
				$status = {
					station_eva      => $status->stop->id_num,
					station_name     => $status->stop->full_name,
					related_stations => [],
				};
			}
			elsif ($motis_service) {
				@results = map { $_->[0] }
+51 −42
Original line number Diff line number Diff line
@@ -48,61 +48,70 @@ sub get_departures_p {
	);
}

sub get_connections_p {
sub grep_suggestions {
	my ( $self, %opt ) = @_;
	my $promise      = Mojo::Promise->new;
	my @destinations = @{ $opt{destinations} };
	my $status       = $opt{status};
	my $destinations = $opt{destinations};
	my $max_per_dest = $opt{max_per_dest};

	$self->get_departures_p(
		service    => $opt{service},
		name       => $opt{name},
		timestamp  => $opt{timestamp},
		lookbehind => 0,
		lookahead  => 60,
	)->then(
		sub {
			my ($status) = @_;
	my @suggestions;
	my %via_count;
	for my $dep ( $status->results ) {
				destination: for my $dest (@destinations) {
		destination: for my $dest ( @{$destinations} ) {
			for my $stop ( $dep->route_post ) {
				if ( $stop->full_name eq $dest->{name} ) {
					if ( not $dep->is_cancelled ) {
						$via_count{ $dep->stop_id_num } += 1;
					}
							if ( $via_count{ $dep->stop_id_num } > 2 ) {
					if (    $max_per_dest
						and $via_count{ $dep->stop_id_num } > $max_per_dest )
					{
						next destination;
					}
					my $dep_json = {
						id => $dep->id,
								ts => ( $dep->sched_datetime // $dep->datetime )
								  ->epoch,
						ts => ( $dep->sched_datetime // $dep->datetime )->epoch,
						sort_ts      => $dep->datetime->epoch,
						is_cancelled => $dep->is_cancelled,
						stop_id_num  => $dep->stop_id_num,
								sched_hhmm   =>
								  $dep->sched_datetime->strftime('%H:%M'),
						sched_hhmm   => $dep->sched_datetime->strftime('%H:%M'),
						rt_hhmm      => $dep->datetime->strftime('%H:%M'),
						delay        => $dep->delay,
						platform     => $dep->platform,
						type         => $dep->type,
						line         => $dep->line,
					};
							push(
								@suggestions,
								[
									$dep_json, $dest,
									$stop->arr->strftime('%H:%M')
								]
							);
					push( @suggestions,
						[ $dep_json, $dest, $stop->arr->strftime('%H:%M') ] );
					next destination;
				}
			}
		}
	}
			@suggestions = map { $_->[0] }
			  sort { $a->[1] <=> $b->[1] }
			  map { [ $_, $_->[0]->{ts} ] } @suggestions;
	return @suggestions;
}

sub get_connections_p {
	my ( $self, %opt ) = @_;
	my $promise      = Mojo::Promise->new;
	my $destinations = $opt{destinations};

	$self->get_departures_p(
		service    => $opt{service},
		name       => $opt{name},
		timestamp  => $opt{timestamp},
		lookbehind => 0,
		lookahead  => 60,
	)->then(
		sub {
			my ($status) = @_;
			my @suggestions = $self->grep_suggestions(
				status       => $status,
				destinations => $destinations,
				max_per_dest => 2
			);
			@suggestions
			  = sort { $a->[0]{sort_ts} <=> $b->[0]{sort_ts} } @suggestions;
			$promise->resolve( \@suggestions );
			return;
		}
+0 −56
Original line number Diff line number Diff line
<ul class="collection departures connections">
	% for my $res (@{$suggestions}) {
		% my ($dep, $dest, $via_arr) = @{$res};
		% my $row_class = '';
		% my $link_class = 'action-checkin';
		% if ($dep->is_cancelled) {
			% $row_class = 'cancelled';
			% $link_class = 'action-cancelled-from';
		% }
		% if ($checkin_from) {
			<li class="collection-item <%= $row_class %> <%= $link_class %>"
			data-efa="<%= $efa %>"
			data-station="<%= $dep->stop_id_num %>"
			data-train="<%= $dep->id %>"
			data-ts="<%= ($dep->sched_datetime // $dep->datetime)->epoch %>"
			data-dest="<%= $dest->{name} %>">
		% }
		% else {
			<li class="collection-item <%= $row_class %>">
		% }
			<a class="dep-time" href="#">
				% if ($dep->is_cancelled) {
					%= $dep->sched_datetime->strftime('%H:%M')
				% }
				% else {
					%= $dep->datetime->strftime('%H:%M')
				% }
				% if ($via_arr) {
					→ <%= $via_arr->strftime('%H:%M') %>
				% }
				% if ($dep->delay) {
					%= sprintf('(%+d)', $dep->delay)
				% }
			</a>
			<span class="connect-platform-wrapper">
				% if ($dep->platform) {
					<span>
						% if (($dep->type // q{}) =~ m{ ast | bus | ruf }ix) {
							Steig
						% }
						% else {
							Gleis
						% }
						%= $dep->platform
					</span>
				% }
				<span class="dep-line <%= ($dep->type // q{}) =~ tr{a-zA-Z_-}{}cdr %>">
					%= $dep->line
				</span>
			</span>
			<span class="dep-dest">
				%= $dest->{name}
			</span>
		</li>
	% }
</ul>
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@
				%= include '_suggestions_dbris', suggestions => stash('suggestions'), checkin_from => $eva;
			% }
			% elsif ($efa) {
				%= include '_suggestions_efa', suggestions => stash('suggestions'), checkin_from => $eva;
				%= include '_connections_efa', suggestions => stash('suggestions'), checkin_from => $eva;
			% }
			% else {
				%= include '_suggestions_iris', suggestions => stash('suggestions'), checkin_from => $eva;