From c9592e3f765911a04e03c4ef5da1cdc7a93f2551 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 6 Aug 2019 20:21:57 +0200 Subject: show boarding countdown in departure overview --- lib/Travelynx.pm | 39 +++++++++++++++++++++++++++++++-------- templates/_checked_in.html.ep | 9 +++++++++ 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 @@
+ % if ($journey->{boarding_countdown} > 120) { + Einfahrt in <%= sprintf('%.f', $journey->{boarding_countdown} / 60) %> Minuten
+ % } + % elsif ($journey->{boarding_countdown} > 60) { + Einfahrt in einer Minute
+ % } + % elsif ($journey->{boarding_countdown} > 0) { + Zug fährt ein
+ % } % if ($journey->{departure_countdown} > 120) { Abfahrt in <%= sprintf('%.f', $journey->{departure_countdown} / 60) %> Minuten % } -- cgit v1.2.3