summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DBInfoscreen.pm')
-rw-r--r--lib/DBInfoscreen.pm138
1 files changed, 84 insertions, 54 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm
index 9dcc2d0..18a2c87 100644
--- a/lib/DBInfoscreen.pm
+++ b/lib/DBInfoscreen.pm
@@ -7,8 +7,10 @@ package DBInfoscreen;
use Mojo::Base 'Mojolicious';
use Cache::File;
+use DBInfoscreen::Helper::DBRIS;
use DBInfoscreen::Helper::EFA;
use DBInfoscreen::Helper::HAFAS;
+use DBInfoscreen::Helper::MOTIS;
use DBInfoscreen::Helper::Wagonorder;
use File::Slurp qw(read_file);
use JSON;
@@ -38,12 +40,6 @@ sub startup {
chomp $self->config->{version};
$self->defaults( version => $self->config->{version} // 'UNKNOWN' );
- $self->plugin(
- I18N => {
- default => 'de',
- },
- );
-
# Generally, the reverse proxy handles compression.
# Also, Mojolicious compression breaks legacy callback-based JSON endpoints
# for some clients.
@@ -62,18 +58,6 @@ sub startup {
if ( $cookie->name eq 'theme' ) {
$self->session( theme => $cookie->value );
}
- elsif ( $cookie->name eq 'lang' ) {
- my $l = $cookie->value;
- if ( $l eq 'de' or $l eq 'en' ) {
- $self->languages($l);
- }
- }
- }
-
- if ( my $l = $self->param('lang') ) {
- if ( $l eq 'de' or $l eq 'en' ) {
- $self->languages($l);
- }
}
}
);
@@ -103,39 +87,37 @@ sub startup {
);
$self->attr(
- ice_type_map => sub {
- if ( -r 'share/zugbildungsplan.json' ) {
- my $ice_type_map = JSON->new->utf8->decode(
- scalar read_file('share/zugbildungsplan.json') );
- my $ret = {};
- while ( my ( $k, $v ) = each %{ $ice_type_map->{train} } ) {
- if ( $v->{type} ) {
- $ret->{$k} = [
- $v->{type}, $v->{shortType},
- exists $v->{wagons} ? 1 : 0
- ];
- }
- }
- return $ret;
- }
- return {};
+ dbdb_wagon => sub {
+ return JSON->new->utf8->decode(
+ scalar read_file('share/dbdb_wagen.json') );
}
);
- $self->attr(
- train_details_db => sub {
- if ( -r 'share/zugbildungsplan.json' ) {
- return JSON->new->utf8->decode(
- scalar read_file('share/zugbildungsplan.json') )->{train};
- }
- return {};
+ $self->helper(
+ dbris => sub {
+ my ($self) = @_;
+ state $efa = DBInfoscreen::Helper::DBRIS->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 => $self->config->{version},
+ );
}
);
- $self->attr(
- dbdb_wagon => sub {
- return JSON->new->utf8->decode(
- scalar read_file('share/dbdb_wagen.json') );
+ $self->helper(
+ motis => sub {
+ my ($self) = @_;
+ state $motis = DBInfoscreen::Helper::MOTIS->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 => $self->config->{version},
+ );
}
);
@@ -226,6 +208,11 @@ sub startup {
{
return 1;
}
+ if ( ( $self->param('hafas') or $self->param('efa') )
+ and $stop =~ m{ [Bb]ahnhof | Bf }x )
+ {
+ return 1;
+ }
return;
}
);
@@ -235,9 +222,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';
}
@@ -303,6 +308,25 @@ sub startup {
}
);
+ $self->helper(
+ 'get_rt_time_class' => sub {
+ my ( $self, $train ) = @_;
+ if ( $train->{has_realtime}
+ and not $train->{is_bit_delayed}
+ and not $train->{is_delayed} )
+ {
+ return 'on-time';
+ }
+ if ( $train->{is_bit_delayed} ) {
+ return 'a-bit-delayed';
+ }
+ if ( $train->{is_delayed} ) {
+ return 'delayed';
+ }
+ return q{};
+ }
+ );
+
my $r = $self->routes;
$r->get('/_redirect')->to('stationboard#redirect_to_station');
@@ -312,6 +336,8 @@ sub startup {
$r->get('/_autostop')->to('static#geostop');
+ $r->get('/_backend')->to('stationboard#backend_list');
+
$r->get('/_datenschutz')->to('static#privacy');
$r->post('/_geolocation')->to('stationboard#stations_by_coordinates');
@@ -322,21 +348,25 @@ sub startup {
$r->get('/dyn/:av/autocomplete.js')->to('stationboard#autocomplete');
- $r->get('/_wr/:train/:departure')->to('wagenreihung#wagenreihung');
- $r->get('/wr/:train')->to('wagenreihung#zugbildung_db');
+ $r->get('/carriage-formation')->to('wagenreihung#wagenreihung');
$r->get('/w/*wagon')->to('wagenreihung#wagen');
$r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route');
$r->get('/map/:tripid/:lineno')->to('map#route');
- $r->get( '/z/:train/*station' => 'train_at_station' )
- ->to('stationboard#station_train_details');
- $r->get( '/z/:train' => 'train' )->to('stationboard#train_details');
+ $r->get('/coverage/:backend/:service')->to('map#coverage');
+ $r->get( '/z/:train/*station' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#station_train_details', format => undef )
+ ->name('train_at_station');
+ $r->get( '/z/:train' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#train_details', format => undef )
+ ->name('train');
$self->defaults( layout => 'app' );
- $r->get('/')->to('stationboard#handle_request');
- $r->get('/multi/*station')->to('stationboard#handle_request');
- $r->get('/*station')->to('stationboard#handle_request');
+ $r->get('/')->to('stationboard#handle_board_request');
+ $r->get('/multi/*station')->to('stationboard#handle_board_request');
+ $r->get( '/*station' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#handle_board_request', format => undef );
$self->types->type( json => 'application/json; charset=utf-8' );