Loading cpanfile +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ requires 'Mojo::Pg'; requires 'Text::CSV'; requires 'Text::Markdown'; requires 'Travel::Status::DE::DBWagenreihung', '== 0.18'; requires 'Travel::Status::DE::EFA'; requires 'Travel::Status::DE::HAFAS', '>= 5.03'; requires 'Travel::Status::DE::IRIS'; requires 'UUID::Tiny'; Loading lib/Travelynx.pm +21 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ use List::UtilsBy qw(uniq_by); use List::MoreUtils qw(first_index); use Travel::Status::DE::DBWagenreihung; use Travelynx::Helper::DBDB; use Travelynx::Helper::EFA; use Travelynx::Helper::HAFAS; use Travelynx::Helper::IRIS; use Travelynx::Helper::Sendmail; Loading Loading @@ -157,11 +158,12 @@ sub startup { cache_iris_main => sub { my ($self) = @_; return Cache::File->new( state $cache = Cache::File->new( cache_root => $self->app->config->{cache}->{schedule}, default_expires => '6 hours', lock_level => Cache::File::LOCK_LOCAL(), ); return $cache; } ); Loading @@ -169,11 +171,12 @@ sub startup { cache_iris_rt => sub { my ($self) = @_; return Cache::File->new( state $cache = Cache::File->new( cache_root => $self->app->config->{cache}->{realtime}, default_expires => '70 seconds', lock_level => Cache::File::LOCK_LOCAL(), ); return $cache; } ); Loading @@ -191,7 +194,7 @@ sub startup { $self->attr( renamed_station => sub { my $legacy_to_new = JSON->new->utf8->decode( state $legacy_to_new = JSON->new->utf8->decode( scalar read_file('share/old_station_names.json') ); return $legacy_to_new; } Loading @@ -216,6 +219,21 @@ sub startup { } ); $self->helper( efa => sub { my ($self) = @_; state $efa = Travelynx::Helper::EFA->new( log => $self->app->log, main_cache => $self->app->cache_iris_main, realtime_cache => $self->app->cache_iris_rt, root_url => $self->base_url_for('/')->to_abs, user_agent => $self->ua, version => $self->app->config->{version}, ); } ); $self->helper( hafas => sub { my ($self) = @_; Loading lib/Travelynx/Command/database.pm +57 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use DateTime; use File::Slurp qw(read_file); use List::Util qw(); use JSON; use Travel::Status::DE::EFA; use Travel::Status::DE::HAFAS; use Travel::Status::DE::IRIS::Stations; Loading Loading @@ -2689,6 +2690,19 @@ qq{select distinct checkout_station_id from in_transit where backend_id = 0;} } ); }, # v58 -> v59 # Add EFA backend support sub { my ($db) = @_; $db->query( qq{ alter table schema_version add column efa varchar(12); update schema_version set version = 59; update schema_version set efa = '0'; } ); }, ); sub sync_stations { Loading Loading @@ -2879,7 +2893,37 @@ sub sync_stations { } } sub sync_backends { sub sync_efa { my ($db) = @_; for my $service ( Travel::Status::DE::EFA::get_services() ) { my $present = $db->select( 'backends', 'count(*) as count', { efa => 1, name => $service->{shortname} } )->hash->{count}; if ( not $present ) { $db->insert( 'backends', { iris => 0, hafas => 0, efa => 1, ris => 0, name => $service->{shortname}, }, { on_conflict => undef } ); } } $db->update( 'schema_version', { efa => $Travel::Status::DE::EFA::VERSION } ); } sub sync_hafas { my ($db) = @_; for my $service ( Travel::Status::DE::HAFAS::get_services() ) { my $present = $db->select( Loading Loading @@ -2996,6 +3040,17 @@ sub migrate_db { } } my $efa_version = get_schema_version( $db, 'efa' ); say "Found backend table for EFA v${efa_version}"; if ( $efa_version eq $Travel::Status::DE::EFA::VERSION ) { say 'Backend table is up-to-date'; } else { say "Synchronizing with Travel::Status::DE::EFA $Travel::Status::DE::EFA::VERSION"; sync_efa($db); } my $hafas_version = get_schema_version( $db, 'hafas' ); say "Found backend table for HAFAS v${hafas_version}"; if ( $hafas_version eq $Travel::Status::DE::HAFAS::VERSION ) { Loading @@ -3004,7 +3059,7 @@ sub migrate_db { else { say "Synchronizing with Travel::Status::DE::HAFAS $Travel::Status::DE::HAFAS::VERSION"; sync_backends($db); sync_hafas($db); } $db->update( 'schema_version', Loading lib/Travelynx/Controller/Account.pm +42 −0 Original line number Diff line number Diff line Loading @@ -1069,6 +1069,48 @@ sub backend_form { $backend->{longname} = 'Deutsche Bahn (IRIS-TTS)'; $backend->{homepage} = 'https://www.bahn.de'; } elsif ( $backend->{efa} ) { if ( my $s = $self->efa->get_service( $backend->{name} ) ) { $type = 'EFA'; $backend->{longname} = $s->{name}; $backend->{homepage} = $s->{homepage}; $backend->{regions} = [ map { $place_map{$_} // $_ } @{ $s->{coverage}{regions} // [] } ]; $backend->{has_area} = $s->{coverage}{area} ? 1 : 0; if ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'Polygon' and $self->lonlat_in_polygon( $s->{coverage}{area}{coordinates}, [ $user_lon, $user_lat ] ) ) { push( @suggested_backends, $backend ); } elsif ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'MultiPolygon' ) { for my $s_poly ( @{ $s->{coverage}{area}{coordinates} // [] } ) { if ( $self->lonlat_in_polygon( $s_poly, [ $user_lon, $user_lat ] ) ) { push( @suggested_backends, $backend ); last; } } } } else { $type = undef; } } elsif ( $backend->{hafas} ) { if ( my $s = $self->hafas->get_service( $backend->{name} ) ) { $type = 'HAFAS'; Loading lib/Travelynx/Controller/Traveling.pm +26 −0 Original line number Diff line number Diff line Loading @@ -917,6 +917,8 @@ sub station { $timestamp = DateTime->now( time_zone => 'Europe/Berlin' ); } my $efa_service = $self->param('efa') // ( $user->{backend_efa} ? $user->{backend_name} : undef ); my $hafas_service = $self->param('hafas') // ( $user->{backend_hafas} ? $user->{backend_name} : undef ); my $promise; Loading @@ -929,6 +931,15 @@ sub station { lookahead => 30, ); } elsif ($efa_service) { $promise = $self->efa->get_departures_p( service => $efa_service, name => $station, timestamp => $timestamp, lookbehind => 10, lookahead => 30, ); } else { $promise = $self->iris->get_departures_p( station => $station, Loading Loading @@ -967,6 +978,16 @@ sub station { related_stations => [], }; } elsif ($efa_service) { @results = map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_, $_->datetime->epoch ] } $status->results; $status = { station_eva => $status->stop->id, station_name => $status->stop->full_name, related_stations => [], }; } else { # You can't check into a train which terminates here Loading Loading @@ -1013,12 +1034,14 @@ sub station { eva => $user_status->{cancellation}{dep_eva}, destination_name => $user_status->{cancellation}{arr_name}, efa => $efa_service, hafas => $hafas_service, ); } else { $connections_p = $self->get_connecting_trains_p( eva => $status->{station_eva}, efa => $efa_service, hafas => $hafas_service ); } Loading @@ -1031,6 +1054,7 @@ sub station { $self->render( 'departures', user => $user, efa => $efa_service, hafas => $hafas_service, eva => $status->{station_eva}, datetime => $timestamp, Loading @@ -1050,6 +1074,7 @@ sub station { $self->render( 'departures', user => $user, efa => $efa_service, hafas => $hafas_service, eva => $status->{station_eva}, datetime => $timestamp, Loading @@ -1068,6 +1093,7 @@ sub station { $self->render( 'departures', user => $user, efa => $efa_service, hafas => $hafas_service, eva => $status->{station_eva}, datetime => $timestamp, Loading Loading
cpanfile +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ requires 'Mojo::Pg'; requires 'Text::CSV'; requires 'Text::Markdown'; requires 'Travel::Status::DE::DBWagenreihung', '== 0.18'; requires 'Travel::Status::DE::EFA'; requires 'Travel::Status::DE::HAFAS', '>= 5.03'; requires 'Travel::Status::DE::IRIS'; requires 'UUID::Tiny'; Loading
lib/Travelynx.pm +21 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ use List::UtilsBy qw(uniq_by); use List::MoreUtils qw(first_index); use Travel::Status::DE::DBWagenreihung; use Travelynx::Helper::DBDB; use Travelynx::Helper::EFA; use Travelynx::Helper::HAFAS; use Travelynx::Helper::IRIS; use Travelynx::Helper::Sendmail; Loading Loading @@ -157,11 +158,12 @@ sub startup { cache_iris_main => sub { my ($self) = @_; return Cache::File->new( state $cache = Cache::File->new( cache_root => $self->app->config->{cache}->{schedule}, default_expires => '6 hours', lock_level => Cache::File::LOCK_LOCAL(), ); return $cache; } ); Loading @@ -169,11 +171,12 @@ sub startup { cache_iris_rt => sub { my ($self) = @_; return Cache::File->new( state $cache = Cache::File->new( cache_root => $self->app->config->{cache}->{realtime}, default_expires => '70 seconds', lock_level => Cache::File::LOCK_LOCAL(), ); return $cache; } ); Loading @@ -191,7 +194,7 @@ sub startup { $self->attr( renamed_station => sub { my $legacy_to_new = JSON->new->utf8->decode( state $legacy_to_new = JSON->new->utf8->decode( scalar read_file('share/old_station_names.json') ); return $legacy_to_new; } Loading @@ -216,6 +219,21 @@ sub startup { } ); $self->helper( efa => sub { my ($self) = @_; state $efa = Travelynx::Helper::EFA->new( log => $self->app->log, main_cache => $self->app->cache_iris_main, realtime_cache => $self->app->cache_iris_rt, root_url => $self->base_url_for('/')->to_abs, user_agent => $self->ua, version => $self->app->config->{version}, ); } ); $self->helper( hafas => sub { my ($self) = @_; Loading
lib/Travelynx/Command/database.pm +57 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use DateTime; use File::Slurp qw(read_file); use List::Util qw(); use JSON; use Travel::Status::DE::EFA; use Travel::Status::DE::HAFAS; use Travel::Status::DE::IRIS::Stations; Loading Loading @@ -2689,6 +2690,19 @@ qq{select distinct checkout_station_id from in_transit where backend_id = 0;} } ); }, # v58 -> v59 # Add EFA backend support sub { my ($db) = @_; $db->query( qq{ alter table schema_version add column efa varchar(12); update schema_version set version = 59; update schema_version set efa = '0'; } ); }, ); sub sync_stations { Loading Loading @@ -2879,7 +2893,37 @@ sub sync_stations { } } sub sync_backends { sub sync_efa { my ($db) = @_; for my $service ( Travel::Status::DE::EFA::get_services() ) { my $present = $db->select( 'backends', 'count(*) as count', { efa => 1, name => $service->{shortname} } )->hash->{count}; if ( not $present ) { $db->insert( 'backends', { iris => 0, hafas => 0, efa => 1, ris => 0, name => $service->{shortname}, }, { on_conflict => undef } ); } } $db->update( 'schema_version', { efa => $Travel::Status::DE::EFA::VERSION } ); } sub sync_hafas { my ($db) = @_; for my $service ( Travel::Status::DE::HAFAS::get_services() ) { my $present = $db->select( Loading Loading @@ -2996,6 +3040,17 @@ sub migrate_db { } } my $efa_version = get_schema_version( $db, 'efa' ); say "Found backend table for EFA v${efa_version}"; if ( $efa_version eq $Travel::Status::DE::EFA::VERSION ) { say 'Backend table is up-to-date'; } else { say "Synchronizing with Travel::Status::DE::EFA $Travel::Status::DE::EFA::VERSION"; sync_efa($db); } my $hafas_version = get_schema_version( $db, 'hafas' ); say "Found backend table for HAFAS v${hafas_version}"; if ( $hafas_version eq $Travel::Status::DE::HAFAS::VERSION ) { Loading @@ -3004,7 +3059,7 @@ sub migrate_db { else { say "Synchronizing with Travel::Status::DE::HAFAS $Travel::Status::DE::HAFAS::VERSION"; sync_backends($db); sync_hafas($db); } $db->update( 'schema_version', Loading
lib/Travelynx/Controller/Account.pm +42 −0 Original line number Diff line number Diff line Loading @@ -1069,6 +1069,48 @@ sub backend_form { $backend->{longname} = 'Deutsche Bahn (IRIS-TTS)'; $backend->{homepage} = 'https://www.bahn.de'; } elsif ( $backend->{efa} ) { if ( my $s = $self->efa->get_service( $backend->{name} ) ) { $type = 'EFA'; $backend->{longname} = $s->{name}; $backend->{homepage} = $s->{homepage}; $backend->{regions} = [ map { $place_map{$_} // $_ } @{ $s->{coverage}{regions} // [] } ]; $backend->{has_area} = $s->{coverage}{area} ? 1 : 0; if ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'Polygon' and $self->lonlat_in_polygon( $s->{coverage}{area}{coordinates}, [ $user_lon, $user_lat ] ) ) { push( @suggested_backends, $backend ); } elsif ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'MultiPolygon' ) { for my $s_poly ( @{ $s->{coverage}{area}{coordinates} // [] } ) { if ( $self->lonlat_in_polygon( $s_poly, [ $user_lon, $user_lat ] ) ) { push( @suggested_backends, $backend ); last; } } } } else { $type = undef; } } elsif ( $backend->{hafas} ) { if ( my $s = $self->hafas->get_service( $backend->{name} ) ) { $type = 'HAFAS'; Loading
lib/Travelynx/Controller/Traveling.pm +26 −0 Original line number Diff line number Diff line Loading @@ -917,6 +917,8 @@ sub station { $timestamp = DateTime->now( time_zone => 'Europe/Berlin' ); } my $efa_service = $self->param('efa') // ( $user->{backend_efa} ? $user->{backend_name} : undef ); my $hafas_service = $self->param('hafas') // ( $user->{backend_hafas} ? $user->{backend_name} : undef ); my $promise; Loading @@ -929,6 +931,15 @@ sub station { lookahead => 30, ); } elsif ($efa_service) { $promise = $self->efa->get_departures_p( service => $efa_service, name => $station, timestamp => $timestamp, lookbehind => 10, lookahead => 30, ); } else { $promise = $self->iris->get_departures_p( station => $station, Loading Loading @@ -967,6 +978,16 @@ sub station { related_stations => [], }; } elsif ($efa_service) { @results = map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_, $_->datetime->epoch ] } $status->results; $status = { station_eva => $status->stop->id, station_name => $status->stop->full_name, related_stations => [], }; } else { # You can't check into a train which terminates here Loading Loading @@ -1013,12 +1034,14 @@ sub station { eva => $user_status->{cancellation}{dep_eva}, destination_name => $user_status->{cancellation}{arr_name}, efa => $efa_service, hafas => $hafas_service, ); } else { $connections_p = $self->get_connecting_trains_p( eva => $status->{station_eva}, efa => $efa_service, hafas => $hafas_service ); } Loading @@ -1031,6 +1054,7 @@ sub station { $self->render( 'departures', user => $user, efa => $efa_service, hafas => $hafas_service, eva => $status->{station_eva}, datetime => $timestamp, Loading @@ -1050,6 +1074,7 @@ sub station { $self->render( 'departures', user => $user, efa => $efa_service, hafas => $hafas_service, eva => $status->{station_eva}, datetime => $timestamp, Loading @@ -1068,6 +1093,7 @@ sub station { $self->render( 'departures', user => $user, efa => $efa_service, hafas => $hafas_service, eva => $status->{station_eva}, datetime => $timestamp, Loading