From 4f0fee7783d3919110287ee9edd0c3a86e961814 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 25 Nov 2019 21:18:57 +0100 Subject: show cancelled trains in connections list --- lib/Travelynx.pm | 51 ++++++++++++++++++++++++++++++++++-------- templates/_connections.html.ep | 49 ++++++++++++++++++++++++++++++---------- 2 files changed, 79 insertions(+), 21 deletions(-) diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index a07d851..1c5b449 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -2276,6 +2276,7 @@ sub startup { map { [ $_, $_->departure ? $_->departure->epoch : 0 ] } @{ $stationboard->{results} }; my @results; + my @cancellations; my %via_count = map { $_ => 0 } @destinations; for my $train ( @{ $stationboard->{results} } ) { if ( not $train->departure ) { @@ -2291,14 +2292,43 @@ sub startup { { next; } - my @via = ( $train->route_post, $train->route_end ); - for my $dest (@destinations) { - if ( $via_count{$dest} < 2 - and List::Util::any { $_ eq $dest } @via ) - { - push( @results, [ $train, $dest ] ); - $via_count{$dest}++; - next; + + # In general, this function is meant to return feasible + # connections. However, cancelled connections may also be of + # interest and are also useful for logging cancellations. + # To satisfy both demands with (hopefully) little confusion and + # UI clutter, this function returns two concatenated arrays: + # actual connections (ordered by actual departure time) followed + # by cancelled connections (ordered by scheduled departure time). + # This is easiest to achieve in two separate loops. + # + # Note that a cancelled train may still have a matching destination + # in its route_post, e.g. if it leaves out $ds100 due to + # unscheduled route changes but continues on schedule afterwards + # -- so it is only cancelled at $ds100, not on the remainder of + # the route. Also note that this specific case is not yet handled + # properly by the cancellation logic etc. + + if ( $train->departure_is_cancelled ) { + my @via + = ( $train->sched_route_post, $train->sched_route_end ); + for my $dest (@destinations) { + if ( List::Util::any { $_ eq $dest } @via ) { + push( @cancellations, [ $train, $dest ] ); + next; + } + } + } + else { + my @via = ( $train->route_post, $train->route_end ); + for my $dest (@destinations) { + if ( $via_count{$dest} < 2 + and List::Util::any { $_ eq $dest } @via ) + { + push( @results, [ $train, $dest ] ); + $via_count{$dest}++; + next; + } } } } @@ -2311,8 +2341,11 @@ sub startup { $_->[0]->departure->epoch // $_->[0]->sched_departure->epoch ] } @results; + @cancellations = map { $_->[0] } + sort { $a->[1] <=> $b->[1] } + map { [ $_, $_->[0]->sched_departure->epoch ] } @cancellations; - return @results; + return ( @results, @cancellations ); } ); diff --git a/templates/_connections.html.ep b/templates/_connections.html.ep index f1d8c2b..a30e896 100644 --- a/templates/_connections.html.ep +++ b/templates/_connections.html.ep @@ -1,28 +1,42 @@
% for my $res (@{$connections}) { % my ($train, $via) = @{$res}; + % my $td_class = ''; + % my $link_class = 'action-checkin'; + % if ($train->is_cancelled) { + % $td_class = 'cancelled'; + % $link_class = 'action-cancelled-from'; + % } - - - + % else { + %= $train->departure->strftime('%H:%M') + % if ($train->departure_delay) { + %= sprintf('(%+d)', $train->departure_delay) + % } +
Gleis <%= $train->platform || '?' %> + % } + % }
+ % if ($checkin_from) { - <%= $train->line %> + <%= $train->line %> % } % else { %= $train->line % } + % if ($checkin_from) { - <%= $via %> + <%= $via %> % } % else { %= $via % } <%= $train->departure->strftime('%H:%M') %> - % if ($train->departure_delay) { - %= sprintf('(%+d)', $train->departure_delay) + + % if ($train->departure_is_cancelled) { + %= $train->sched_departure->strftime('%H:%M') + ⊖ % } -
Gleis <%= $train->platform || '?' %>
@@ -52,11 +66,22 @@ %= $via % } - <%= $train->departure->strftime('%H:%M') %> - % if ($train->departure_delay) { - %= sprintf('(%+d)', $train->departure_delay) + + % if ($train->departure_is_cancelled) { + %= $train->sched_departure->strftime('%H:%M') + (fällt aus) + % } + % else { + %= $train->departure->strftime('%H:%M') + % if ($train->departure_delay) { + %= sprintf('(%+d)', $train->departure_delay) + % } % } - Gleis <%= $train->platform || '?' %> + + % if (not $train->departure_is_cancelled) { + Gleis <%= $train->platform || '?' %> + % } + % } -- cgit v1.2.3