From ea6d13144c105e7ae04fb2baed0189b8ecda9bdb Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 5 Dec 2020 16:28:51 +0100 Subject: train details: show expected utilization (via marudor.de) --- lib/DBInfoscreen.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'lib/DBInfoscreen.pm') 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; @@ -113,6 +115,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) = @_; @@ -315,6 +331,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 ) = @_; -- cgit v1.2.3