summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-05 16:28:51 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-05 16:28:51 +0100
commitea6d13144c105e7ae04fb2baed0189b8ecda9bdb (patch)
tree7ac176f0a11c47a9a9bd6c64e813681068d24a06 /lib/DBInfoscreen.pm
parente7efe6de232445e3ef7816db4661670f7839ba7a (diff)
train details: show expected utilization (via marudor.de)
Diffstat (limited to 'lib/DBInfoscreen.pm')
-rw-r--r--lib/DBInfoscreen.pm45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm
index ed81638..b04fb03 100644
--- a/lib/DBInfoscreen.pm
+++ b/lib/DBInfoscreen.pm
@@ -1,4 +1,5 @@
package DBInfoscreen;
+
# Copyright (C) 2011-2020 Daniel Friesel
#
# SPDX-License-Identifier: BSD-2-Clause
@@ -7,6 +8,7 @@ use Mojo::Base 'Mojolicious';
use Cache::File;
use DBInfoscreen::Helper::HAFAS;
+use DBInfoscreen::Helper::Marudor;
use DBInfoscreen::Helper::Wagonorder;
use File::Slurp qw(read_file);
use JSON;
@@ -114,6 +116,20 @@ sub startup {
);
$self->helper(
+ marudor => sub {
+ my ($self) = @_;
+ state $hafas = DBInfoscreen::Helper::Marudor->new(
+ log => $self->app->log,
+ main_cache => $self->app->cache_iris_main,
+ realtime_cache => $self->app->cache_iris_rt,
+ root_url => $self->url_for('/')->to_abs,
+ user_agent => $self->ua,
+ version => $VERSION,
+ );
+ }
+ );
+
+ $self->helper(
wagonorder => sub {
my ($self) = @_;
state $hafas = DBInfoscreen::Helper::Wagonorder->new(
@@ -316,6 +332,35 @@ sub startup {
);
$self->helper(
+ 'utilization_icon' => sub {
+ my ( $self, $utilization ) = @_;
+ my ( $first, $second ) = @{ $utilization // [ 0, 0 ] };
+ my $sum = ( $first + $second ) / 2;
+
+ my @symbols
+ = (
+ qw(hourglass_empty person_outline people priority_high not_interested)
+ );
+ my $text = 'Auslastung unbekannt';
+
+ if ( $sum > 3.5 ) {
+ $text = 'Zug ist ausgebucht';
+ }
+ elsif ( $sum >= 2.5 ) {
+ $text = 'Sehr hohe Auslastung';
+ }
+ elsif ( $sum >= 1.5 ) {
+ $text = 'Hohe Auslastung';
+ }
+ elsif ( $sum >= 1 ) {
+ $text = 'Geringe Auslastung';
+ }
+
+ return ( $text, $symbols[$first], $symbols[$second] );
+ }
+ );
+
+ $self->helper(
'numeric_platform_part' => sub {
my ( $self, $platform ) = @_;