summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-08-06 20:21:57 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-08-06 20:21:57 +0200
commitc9592e3f765911a04e03c4ef5da1cdc7a93f2551 (patch)
tree9a9a8d1d4bf909ee87ed5825bbe3541ea910eb07
parent0439aa8b0247bbbd5590526bb679f749940bb6df (diff)
show boarding countdown in departure overview
-rwxr-xr-xlib/Travelynx.pm39
-rw-r--r--templates/_checked_in.html.ep9
2 files changed, 40 insertions, 8 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index f508a4c..ef927ea 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -2364,6 +2364,7 @@ sub startup {
my @route = @{ $in_transit->{route} // [] };
my @route_after;
+ my $dep_info;
my $stop_before_dest;
my $is_after = 0;
for my $station (@route) {
@@ -2379,6 +2380,11 @@ sub startup {
}
if ( $station->[0] eq $in_transit->{dep_name} ) {
$is_after = 1;
+ $self->app->log->debug("is_after");
+ if ( @{$station} > 1 ) {
+ $self->app->log->debug("set dep_info");
+ $dep_info = $station->[1];
+ }
}
}
my $stop_after_dep = $route_after[0][0];
@@ -2388,14 +2394,15 @@ sub startup {
my $action_time = epoch_to_dt($ts);
my $ret = {
- checked_in => !$in_transit->{cancelled},
- cancelled => $in_transit->{cancelled},
- timestamp => $action_time,
- timestamp_delta => $now->epoch - $action_time->epoch,
- train_type => $in_transit->{train_type},
- train_line => $in_transit->{train_line},
- train_no => $in_transit->{train_no},
- train_id => $in_transit->{train_id},
+ checked_in => !$in_transit->{cancelled},
+ cancelled => $in_transit->{cancelled},
+ timestamp => $action_time,
+ timestamp_delta => $now->epoch - $action_time->epoch,
+ train_type => $in_transit->{train_type},
+ train_line => $in_transit->{train_line},
+ train_no => $in_transit->{train_no},
+ train_id => $in_transit->{train_id},
+ boarding_countdown => -1,
sched_departure =>
epoch_to_dt( $in_transit->{sched_dep_ts} ),
real_departure => epoch_to_dt( $in_transit->{real_dep_ts} ),
@@ -2426,6 +2433,22 @@ sub startup {
}
$ret->{extra_data}{qos_msg} = [@parsed_messages];
+ if ( $dep_info and $dep_info->{sched_arr} ) {
+ $self->app->log->debug(
+ "dep_info has sched_arr. set countdown.");
+ $dep_info->{sched_arr}
+ = epoch_to_dt( $dep_info->{sched_arr} );
+ $dep_info->{rt_arr} = $dep_info->{sched_arr}->clone;
+ if ( $dep_info->{adelay}
+ and $dep_info->{adelay} =~ m{^\d+$} )
+ {
+ $dep_info->{rt_arr}
+ ->add( minutes => $dep_info->{adelay} );
+ }
+ $dep_info->{rt_arr_countdown} = $ret->{boarding_countdown}
+ = $dep_info->{rt_arr}->epoch - $epoch;
+ }
+
for my $station (@route_after) {
if ( @{$station} > 1 ) {
my $times = $station->[1];
diff --git a/templates/_checked_in.html.ep b/templates/_checked_in.html.ep
index 4e056da..3070ed9 100644
--- a/templates/_checked_in.html.ep
+++ b/templates/_checked_in.html.ep
@@ -6,6 +6,15 @@
<div class="center-align countdown"
data-duration="<%= $journey->{journey_duration} // 0 %>"
data-arrival="<%= $journey->{real_arrival}->epoch %>">
+ % if ($journey->{boarding_countdown} > 120) {
+ Einfahrt in <%= sprintf('%.f', $journey->{boarding_countdown} / 60) %> Minuten<br/>
+ % }
+ % elsif ($journey->{boarding_countdown} > 60) {
+ Einfahrt in einer Minute<br/>
+ % }
+ % elsif ($journey->{boarding_countdown} > 0) {
+ Zug fährt ein<br/>
+ % }
% if ($journey->{departure_countdown} > 120) {
Abfahrt in <%= sprintf('%.f', $journey->{departure_countdown} / 60) %> Minuten
% }