summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-03-27 13:27:15 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-03-27 13:27:15 +0100
commitaa9e55128f287b2e264df22997ec282b13f16fbe (patch)
treec7900bae91466f01fc280bf4f577460f8e281df9 /lib
parent67c7349906ce6c9c93cc45f23046853f3ad07fbc (diff)
request EFA occupancy data (works for some VRR trains)
Diffstat (limited to 'lib')
-rw-r--r--lib/DBInfoscreen.pm22
-rw-r--r--lib/DBInfoscreen/Controller/Stationboard.pm27
-rw-r--r--lib/DBInfoscreen/Helper/Marudor.pm29
3 files changed, 76 insertions, 2 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm
index 4445d7f..70b4b5e 100644
--- a/lib/DBInfoscreen.pm
+++ b/lib/DBInfoscreen.pm
@@ -295,6 +295,28 @@ sub startup {
);
$self->helper(
+ 'occupancy_icon' => sub {
+ my ( $self, $occupancy ) = @_;
+
+ my @symbols
+ = (qw(help_outline person_outline people priority_high));
+ my $text = 'Auslastung unbekannt';
+
+ if ( $occupancy > 2 ) {
+ $text = 'Sehr hohe Auslastung';
+ }
+ elsif ( $occupancy > 1 ) {
+ $text = 'Hohe Auslastung';
+ }
+ elsif ( $occupancy > 0 ) {
+ $text = 'Geringe Auslastung';
+ }
+
+ return ( $text, $symbols[$occupancy] );
+ }
+ );
+
+ $self->helper(
'utilization_icon' => sub {
my ( $self, $utilization ) = @_;
my ( $first, $second ) = @{ $utilization // [ 0, 0 ] };
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 ) = @_;