From c250a2f2c7968966014315f76b25109b83c041ed Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 15 Jun 2025 08:23:48 +0200 Subject: Add experimental EFA support Squashed commit of the following: commit b7457791ab7ab4859ebf4a5ce173e1aaeed4c7fb Author: Birte Kristina Friesel Date: Sun Jun 15 08:18:46 2025 +0200 changelog commit 7f3d61066195cfc3c83a8fc1b2fc3743e7e6171c Author: Birte Kristina Friesel Date: Sat Jun 14 19:55:51 2025 +0200 Mark EFA backends as experimental for now For instance, VRR has very interesting issues when checking into departures that do not have real-time data yet. commit 3370c0f6c25bd6b02cc4d56e9a3aba2a66d1151a Author: Birte Kristina Friesel Date: Sat Jun 14 19:49:48 2025 +0200 InTransit: remove debug output commit deb5444fa2965228b537e86fce862436ef2e6e19 Author: Birte Kristina Friesel Date: Sat Jun 14 19:12:44 2025 +0200 frontend js for checked-in view: never show fractional delays commit d47ff9615b551bbd844a799be7717e9e74a04266 Author: Birte Kristina Friesel Date: Sat Jun 14 19:12:31 2025 +0200 worker: add EFA support commit 3a955c0105bf13d040a821e2c87a19694202cde6 Author: Birte Kristina Friesel Date: Sat Jun 14 17:48:46 2025 +0200 EFA: checkin support worker support and cancellations are still missing commit 19dea1ad13029d19cba38e7d1338718149c139fb Author: Birte Kristina Friesel Date: Sat Jun 14 14:32:59 2025 +0200 actions.js: pass on efa parameter commit 8f18ff2c8f9f906a387dbe16d372e1c4b4a6f259 Author: Birte Kristina Friesel Date: Sat Jun 14 14:32:48 2025 +0200 EFA: implement geolocation lookup commit bce1139bab9aab167cdab910fa86085529d45b80 Author: Birte Kristina Friesel Date: Sat Jun 14 14:32:21 2025 +0200 EFA: ->id is no longer supported, use ->id_num commit e4397e6b1538ddfa71da9839d6011a73fadc528f Author: Birte Kristina Friesel Date: Mon Jun 9 20:34:22 2025 +0200 ... derp commit e0c4cbf862a8f5a7bca0b1aceab3760af94093e9 Author: Birte Kristina Friesel Date: Mon Jun 9 18:28:35 2025 +0200 database: it's dbris, not ris commit bfb1e834ce6c3171011dc20b32117065960b8771 Merge: 42f9a00 f1da50f Author: Birte Kristina Friesel Date: Mon Jun 9 18:20:51 2025 +0200 Merge branch 'main' into efa-support commit 42f9a00d98dbd675234c05b3e25c3e722cfdd7ba Author: Birte Kristina Friesel Date: Wed Jan 8 18:11:28 2025 +0100 EFA support (WiP) --- lib/Travelynx/Controller/Account.pm | 43 +++++++++++++++++ lib/Travelynx/Controller/Traveling.pm | 91 +++++++++++++++++++++++++++++++++-- 2 files changed, 131 insertions(+), 3 deletions(-) (limited to 'lib/Travelynx/Controller') diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index 033b270..0978c88 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -1077,6 +1077,49 @@ sub backend_form { $backend->{homepage} = 'https://www.bahn.de'; $backend->{recommended} = 1; } + 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; + $backend->{experimental} = 1; + + 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} ) { # These backends lack a journey endpoint or are no longer diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 0cfccb1..9826211 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -562,11 +562,14 @@ sub geolocation { return; } - my ( $dbris_service, $hafas_service, $motis_service ); + my ( $dbris_service, $efa_service, $hafas_service, $motis_service ); my $backend = $self->stations->get_backend( backend_id => $backend_id ); if ( $backend->{dbris} ) { $dbris_service = $backend->{name}; } + if ( $backend->{efa} ) { + $efa_service = $backend->{name}; + } elsif ( $backend->{hafas} ) { $hafas_service = $backend->{name}; } @@ -617,6 +620,50 @@ sub geolocation { )->wait; return; } + elsif ($efa_service) { + $self->render_later; + + Travel::Status::DE::EFA->new_p( + promise => 'Mojo::Promise', + user_agent => Mojo::UserAgent->new, + service => $efa_service, + coord => { + lat => $lat, + lon => $lon + } + )->then( + sub { + my ($efa) = @_; + my @results = map { + { + name => $_->full_name, + eva => $_->id_code, + distance => 0, + efa => $efa_service, + } + } $efa->results; + if ( @results > 10 ) { + @results = @results[ 0 .. 9 ]; + } + $self->render( + json => { + candidates => [@results], + } + ); + } + )->catch( + sub { + my ($err) = @_; + $self->render( + json => { + candidates => [], + warning => $err, + } + ); + } + )->wait; + return; + } elsif ($hafas_service) { $self->render_later; @@ -726,8 +773,6 @@ sub geolocation { lon => $_->[0][3], lat => $_->[0][4], distance => $_->[1], - dbris => 0, - hafas => 0, } } Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon, $lat, 10 ); @@ -796,6 +841,7 @@ sub travel_action { sub { return $self->checkin_p( dbris => $params->{dbris}, + efa => $params->{efa}, hafas => $params->{hafas}, motis => $params->{motis}, station => $params->{station}, @@ -832,6 +878,9 @@ sub travel_action { if ( $status->{is_dbris} ) { $station_link .= '?dbris=' . $status->{backend_name}; } + elsif ( $status->{is_efa} ) { + $station_link .= '?efa=' . $status->{backend_name}; + } elsif ( $status->{is_hafas} ) { $station_link .= '?hafas=' . $status->{backend_name}; } @@ -871,6 +920,9 @@ sub travel_action { if ( $status->{is_dbris} ) { $station_link .= '?dbris=' . $status->{backend_name}; } + elsif ( $status->{is_efa} ) { + $station_link .= '?efa=' . $status->{backend_name}; + } elsif ( $status->{is_hafas} ) { $station_link .= '?hafas=' . $status->{backend_name}; } @@ -929,6 +981,12 @@ sub travel_action { . '?dbris=' . $status->{backend_name}; } + elsif ( $status->{is_efa} ) { + $redir + = '/s/' + . $status->{dep_eva} . '?efa=' + . $status->{backend_name}; + } elsif ( $status->{is_hafas} ) { $redir = '/s/' @@ -959,6 +1017,7 @@ sub travel_action { $self->render_later; $self->checkin_p( dbris => $params->{dbris}, + efa => $params->{efa}, hafas => $params->{hafas}, motis => $params->{motis}, station => $params->{station}, @@ -1091,6 +1150,8 @@ sub station { my $dbris_service = $self->param('dbris') // ( $user->{backend_dbris} ? $user->{backend_name} : undef ); + 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 $motis_service = $self->param('motis') @@ -1118,6 +1179,15 @@ sub station { lookbehind => 30, ); } + elsif ($efa_service) { + $promise = $self->efa->get_departures_p( + service => $efa_service, + name => $station, + timestamp => $timestamp, + lookbehind => 30, + lookahead => 30, + ); + } elsif ($hafas_service) { $promise = $self->hafas->get_departures_p( service => $hafas_service, @@ -1209,6 +1279,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_num, + station_name => $status->stop->full_name, + related_stations => [], + }; + } elsif ($motis_service) { @results = map { $_->[0] } sort { $b->[1] <=> $a->[1] } @@ -1268,12 +1348,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 ); } @@ -1287,6 +1369,7 @@ sub station { 'departures', user => $user, dbris => $dbris_service, + efa => $efa_service, hafas => $hafas_service, motis => $motis_service, eva => $status->{station_eva}, @@ -1308,6 +1391,7 @@ sub station { 'departures', user => $user, dbris => $dbris_service, + efa => $efa_service, hafas => $hafas_service, motis => $motis_service, eva => $status->{station_eva}, @@ -1328,6 +1412,7 @@ sub station { 'departures', user => $user, dbris => $dbris_service, + efa => $efa_service, hafas => $hafas_service, motis => $motis_service, eva => $status->{station_eva}, -- cgit v1.2.3