diff options
Diffstat (limited to 'lib/DBInfoscreen')
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 27 | ||||
-rw-r--r-- | lib/DBInfoscreen/Helper/Marudor.pm | 29 |
2 files changed, 54 insertions, 2 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 8f868a9..169240d 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -557,11 +557,14 @@ sub render_train { my $wagonorder_req = Mojo::Promise->new; my $utilization_req = Mojo::Promise->new; + my $occupancy_req = Mojo::Promise->new; my $stationinfo_req = Mojo::Promise->new; my $route_req = Mojo::Promise->new; - my @requests - = ( $wagonorder_req, $utilization_req, $stationinfo_req, $route_req ); + my @requests = ( + $wagonorder_req, $utilization_req, $occupancy_req, + $stationinfo_req, $route_req + ); if ( $departure->{wr_link} ) { $self->wagonorder->is_available_p( $result, $departure->{wr_link} ) @@ -606,6 +609,26 @@ sub render_train { $utilization_req->resolve; } + $self->marudor->get_efa_occupancy( + eva => $result->station_uic, + train_no => $result->train_no + )->then( + sub { + my ($occupancy) = @_; + $departure->{occupancy} = $occupancy; + return; + }, + sub { + $departure->{occupancy} = undef; + return; + } + )->finally( + sub { + $occupancy_req->resolve; + return; + } + )->wait; + $self->wagonorder->get_stationinfo_p( $result->station_uic )->then( sub { my ($station_info) = @_; diff --git a/lib/DBInfoscreen/Helper/Marudor.pm b/lib/DBInfoscreen/Helper/Marudor.pm index dad9dc7..dce22cf 100644 --- a/lib/DBInfoscreen/Helper/Marudor.pm +++ b/lib/DBInfoscreen/Helper/Marudor.pm @@ -80,6 +80,35 @@ sub get_json_p { return $promise; } +sub get_efa_occupancy { + my ( $self, %opt ) = @_; + + my $eva = $opt{eva}; + my $train_no = $opt{train_no}; + my $promise = Mojo::Promise->new; + + $self->get_json_p( $self->{realtime_cache}, + "https://vrrf.finalrewind.org/_eva/${eva}.json" )->then( + sub { + my ($utilization_json) = @_; + + if ( $utilization_json->{$train_no}{occupancy} ) { + $promise->resolve( $utilization_json->{$train_no}{occupancy} ); + return; + } + $promise->reject; + return; + } + )->catch( + sub { + $promise->reject; + return; + } + )->wait; + + return $promise; +} + sub get_train_utilization { my ( $self, %opt ) = @_; |