summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/Travelynx.pm51
-rw-r--r--templates/_connections.html.ep49
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 @@
<div class="hide-on-med-and-up"><table class="striped"><tbody>
% 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';
+ % }
<tr>
- <td>
+ <td class="<%= $td_class %>">
% if ($checkin_from) {
- <a class="action-checkin" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $train->line %></a>
+ <a class="<%= $link_class %>" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $train->line %></a>
% }
% else {
%= $train->line
% }
</td>
- <td>
+ <td class="<%= $td_class %>">
% if ($checkin_from) {
- <a class="action-checkin" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $via %></a>
+ <a class="<%= $link_class %>" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $via %></a>
% }
% else {
%= $via
% }
</td>
- <td><%= $train->departure->strftime('%H:%M') %>
- % if ($train->departure_delay) {
- %= sprintf('(%+d)', $train->departure_delay)
+ <td>
+ % if ($train->departure_is_cancelled) {
+ %= $train->sched_departure->strftime('%H:%M')
+ ⊖
% }
- <br/>Gleis <%= $train->platform || '?' %></td>
+ % else {
+ %= $train->departure->strftime('%H:%M')
+ % if ($train->departure_delay) {
+ %= sprintf('(%+d)', $train->departure_delay)
+ % }
+ <br/>Gleis <%= $train->platform || '?' %>
+ % }
+ </td>
</tr>
% }
</tbody></table></div>
@@ -52,11 +66,22 @@
%= $via
% }
</td>
- <td><%= $train->departure->strftime('%H:%M') %>
- % if ($train->departure_delay) {
- %= sprintf('(%+d)', $train->departure_delay)
+ <td>
+ % 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)
+ % }
% }
- </td><td>Gleis <%= $train->platform || '?' %></td>
+ </td><td>
+ % if (not $train->departure_is_cancelled) {
+ Gleis <%= $train->platform || '?' %>
+ % }
+ </td>
</tr>
% }
</tbody></table></div>