diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/DBInfoscreen.pm | 20 | ||||
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 184 | ||||
-rw-r--r-- | lib/DBInfoscreen/Helper/EFA.pm | 1 | ||||
-rw-r--r-- | lib/DBInfoscreen/Helper/HAFAS.pm | 1 |
4 files changed, 196 insertions, 10 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index c784e96..1fd3674 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -187,9 +187,27 @@ sub startup { my ( $self, $occupancy ) = @_; my @symbols - = (qw(help_outline person_outline people priority_high)); + = ( + qw(help_outline person_outline people priority_high not_interested) + ); my $text = 'Auslastung unbekannt'; + if ( $occupancy eq 'MANY_SEATS' ) { + $occupancy = 1; + } + elsif ( $occupancy eq 'FEW_SEATS' ) { + $occupancy = 2; + } + elsif ( $occupancy eq 'STANDING_ONLY' ) { + $occupancy = 3; + } + elsif ( $occupancy eq 'FULL' ) { + $occupancy = 4; + } + + if ( $occupancy > 3 ) { + $text = 'Voraussichtlich überfüllt'; + } if ( $occupancy > 2 ) { $text = 'Sehr hohe Auslastung erwartet'; } diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index b566efa..93388fa 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -17,6 +17,7 @@ use Mojo::JSON qw(decode_json encode_json); use Mojo::Promise; use Mojo::UserAgent; use Travel::Status::DE::DBWagenreihung; +use Travel::Status::DE::EFA; use Travel::Status::DE::HAFAS; use Travel::Status::DE::IRIS; use Travel::Status::DE::IRIS::Stations; @@ -44,11 +45,20 @@ sub class_to_product { } sub handle_no_results { - my ( $self, $station, $data, $hafas ) = @_; + my ( $self, $station, $data, $hafas, $efa ) = @_; my $errstr = $data->{errstr}; - if ($hafas) { + if ($efa) { + $self->render( + 'landingpage', + error => ( $errstr // "Keine Abfahrten an '$station'" ), + hide_opts => 0, + status => $data->{status} // 404, + ); + return; + } + elsif ($hafas) { $self->render_later; my $service = 'DB'; if ( $hafas ne '1' and Travel::Status::DE::HAFAS::get_service($hafas) ) @@ -343,6 +353,24 @@ sub get_results_p { my ( $self, $station, %opt ) = @_; my $data; + if ( $opt{efa} ) { + my $service = 'VRR'; + if ( $opt{efa} ne '1' + and Travel::Status::DE::EFA::get_service( $opt{efa} ) ) + { + $service = $opt{efa}; + } + return Travel::Status::DE::EFA->new_p( + service => $service, + name => $station, + lwp_options => { + timeout => 10, + agent => 'dbf.finalrewind.org/2' + }, + promise => 'Mojo::Promise', + user_agent => Mojo::UserAgent->new, + ); + } if ( $opt{hafas} ) { my $service = 'DB'; if ( $opt{hafas} ne '1' @@ -412,12 +440,14 @@ sub handle_request { my $station = $self->stash('station'); my $template = $self->param('mode') // 'app'; + my $efa = $self->param('efa'); my $hafas = $self->param('hafas'); my $with_related = !$self->param('no_related'); my %opt = ( cache_iris_main => $self->app->cache_iris_main, cache_iris_rt => $self->app->cache_iris_rt, lookahead => $self->config->{lookahead}, + efa => $efa, hafas => $hafas, ); @@ -507,6 +537,10 @@ sub handle_request { $self->get_results_p( $station, %opt )->then( sub { my ($status) = @_; + if ($efa) { + $self->handle_efa( $station, $status ); + return; + } my $data = { results => [ $status->results ], hafas => $hafas ? $status : undef, @@ -553,7 +587,7 @@ sub handle_request { errstr => $err, status => ( $err =~ m{Ambiguous|LOCATION} ? 300 : 500 ), }, - $hafas + $hafas, $efa ); return; } @@ -749,8 +783,55 @@ sub render_train { from_json => $wr_json ); $departure->{wr} = $wr; $departure->{wr_text} = join( q{ • }, - map { $_->{short} } - grep { $_->{short} } $wr->train_descriptions ); + map { $_->desc_short } + grep { $_->desc_short } $wr->groups ); + my $first = 0; + for my $group ( $wr->groups ) { + my $had_entry = 0; + for my $wagon ( $group->wagons ) { + if ( + not( $wagon->is_locomotive + or $wagon->is_powercar ) + ) + { + my $class; + if ($first) { + push( + @{ $departure->{wr_preview} }, + [ '•', 'meta' ] + ); + $first = 0; + } + my $entry; + if ( $wagon->is_closed ) { + $entry = 'X'; + $class = 'closed'; + } + else { + $entry = $wagon->number + || ( + $wagon->type =~ m{AB} ? '½' + : $wagon->type =~ m{A} ? '1.' + : $wagon->type =~ m{B} ? '2.' + : $wagon->type + ); + } + if ( + $group->train_no ne $departure->{train_no} ) + { + $class = 'otherno'; + } + push( + @{ $departure->{wr_preview} }, + [ $entry, $class ] + ); + $had_entry = 1; + } + } + if ($had_entry) { + $first = 1; + } + } }; $departure->{wr_text} ||= 'Wagen'; return; @@ -826,10 +907,11 @@ sub render_train { } if ($direction) { - $departure->{direction} = $direction; + $departure->{wr_direction} = $direction; + $departure->{wr_direction_num} = $direction eq 'l' ? 0 : 100; } elsif ( $platform_info->{direction} ) { - $departure->{direction} = 'a' . $platform_info->{direction}; + $departure->{wr_direction} = 'a' . $platform_info->{direction}; } return; @@ -1379,6 +1461,93 @@ sub train_details { )->wait; } +sub handle_efa { + my ( $self, $station_name, $efa ) = @_; + my $template = $self->param('mode') // 'app'; + my $hide_low_delay = $self->param('hidelowdelay') // 0; + my $hide_opts = $self->param('hide_opts') // 0; + my $show_realtime = $self->param('rt') // $self->param('show_realtime') + // 0; + + my @departures; + + if ( $self->param('ajax') ) { + delete $self->stash->{layout}; + } + + for my $result ( $efa->results ) { + my $time; + + if ( $show_realtime and $result->rt_datetime ) { + $time = $result->rt_datetime->strftime('%H:%M'); + } + else { + $time = $result->sched_datetime->strftime('%H:%M'); + } + + my $linetype = $result->mot_name // 'bahn'; + if ( $linetype eq 's-bahn' ) { + $linetype = 'sbahn'; + } + elsif ( $linetype eq 'u-bahn' ) { + $linetype = 'ubahn'; + } + elsif ( $linetype =~ m{bus} ) { + $linetype = 'bus'; + } + elsif ( $linetype eq 'zug' ) { + $linetype = 'bahn'; + } + elsif ( $linetype eq 'sonstige' ) { + $linetype = 'ext'; + } + push( + @departures, + { + time => $time, + sched_departure => $result->sched_datetime->strftime('%H:%M'), + departure => $result->rt_datetime + ? $result->rt_datetime->strftime('%H:%M') + : undef, + train => $result->line, + train_type => q{}, + train_line => $result->line, + train_no => $result->train_no, + via => [], + destination => $result->destination, + platform => $result->platform, + is_cancelled => $result->is_cancelled, + linetype => $linetype, + delay => $result->delay, + occupancy => $result->occupancy, + replaced_by => [], + replacement_for => [], + route_pre => [], + route_post => [], + wr_link => undef, + } + ); + } + + $self->render( + $template, + description => "Abfahrtstafel $station_name", + departures => \@departures, + station => $station_name, + version => $self->config->{version}, + title => $station_name, + refresh_interval => $template eq 'app' ? 0 : 120, + hide_opts => $hide_opts, + hide_low_delay => $hide_low_delay, + show_realtime => $show_realtime, + load_marquee => ( + $template eq 'single' + or $template eq 'multi' + ), + force_mobile => ( $template eq 'app' ), + ); +} + sub handle_result { my ( $self, $data ) = @_; @@ -1762,6 +1931,7 @@ sub handle_result { origin => $result->route_end =~ s{,\Q$city\E}{}r, platform => $result->platform, scheduled_platform => $result->sched_platform, + load => $result->load // {}, info => $info, is_cancelled => $result->is_cancelled, linetype => $linetype, diff --git a/lib/DBInfoscreen/Helper/EFA.pm b/lib/DBInfoscreen/Helper/EFA.pm index 2a7416e..4e81bc3 100644 --- a/lib/DBInfoscreen/Helper/EFA.pm +++ b/lib/DBInfoscreen/Helper/EFA.pm @@ -13,7 +13,6 @@ use Encode qw(decode encode); use Mojo::JSON qw(decode_json); use Mojo::Promise; use Mojo::Util qw(url_escape); -use XML::LibXML; sub new { my ( $class, %opt ) = @_; diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index cdb84f0..a55f03f 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -13,7 +13,6 @@ use Encode qw(decode encode); use Travel::Status::DE::HAFAS; use Mojo::JSON qw(decode_json); use Mojo::Promise; -use XML::LibXML; sub new { my ( $class, %opt ) = @_; |