summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-12-27 20:11:26 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-12-27 20:11:26 +0100
commiteade158164e93484c1ca00e5005ce66bef58c704 (patch)
treec692a1ada4e5c666a6f16f83121036e1f3607d1d
parent364137b9b6339b724b109160e6e0d3904b022037 (diff)
IRIS: show connections at destination while checked in
-rw-r--r--lib/Travelynx/Command/work.pm35
-rw-r--r--lib/Travelynx/Helper/DBRIS.pm20
-rw-r--r--lib/Travelynx/Helper/IRIS.pm44
-rw-r--r--templates/_checked_in.html.ep7
-rw-r--r--templates/use_history.html.ep2
5 files changed, 105 insertions, 3 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm
index d6e70ed..41325d2 100644
--- a/lib/Travelynx/Command/work.pm
+++ b/lib/Travelynx/Command/work.pm
@@ -782,6 +782,41 @@ sub run {
$self->app->add_stationinfo( $uid, 0, $train->train_id,
$dep, $arr );
}
+ if ( $now->epoch - $entry->{real_arr_ts} < 900 ) {
+ my @destinations
+ = $self->app->journeys->get_connection_targets(
+ uid => $uid,
+ backend_id => $entry->{backend_id},
+ eva => $arr,
+ exclude => $dep,
+ );
+ $self->app->iris->get_connections_p(
+ station => $arr,
+ timestamp => $entry->{real_arr},
+ destinations => \@destinations
+ )->then(
+ sub {
+ my ($suggestions) = @_;
+ $self->app->in_transit->update_data(
+ uid => $uid,
+ train_id => $train_id,
+ data => {
+ connection_suggestions_iris =>
+ $suggestions
+ },
+ );
+ return;
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $self->app->log->debug(
+"work($uid) @ DBRIS $entry->{backend_name}: get_departures_p($arr): $err"
+ );
+ return;
+ }
+ )->wait;
+ }
}
elsif ( $entry->{real_arr_ts} ) {
my ( undef, $error ) = $self->app->checkout_p(
diff --git a/lib/Travelynx/Helper/DBRIS.pm b/lib/Travelynx/Helper/DBRIS.pm
index e1f52eb..6441a98 100644
--- a/lib/Travelynx/Helper/DBRIS.pm
+++ b/lib/Travelynx/Helper/DBRIS.pm
@@ -234,8 +234,8 @@ sub grep_suggestions {
ts => ( $dep->sched_dep // $dep->dep )->epoch,
sort_ts => $dep->dep->epoch,
is_cancelled => $dep->is_cancelled,
- stop_eva => $dep->{stop_eva},
- maybe_line_no => $dep->{maybe_line_no},
+ stop_eva => $dep->stop_eva,
+ maybe_line_no => $dep->maybe_line_no,
sched_hhmm => $dep->sched_dep->strftime('%H:%M'),
rt_hhmm => $dep->dep->strftime('%H:%M'),
delay => $dep->delay,
@@ -247,11 +247,27 @@ sub grep_suggestions {
if ( $dep->destination
and $dep->destination eq $dest->{name} )
{
+ if ( not $dep->is_cancelled ) {
+ $via_count{ $dep->stop_eva } += 1;
+ }
+ if ( $max_per_dest
+ and $via_count{ $dep->stop_eva } > $max_per_dest )
+ {
+ next destination;
+ }
push( @suggestions, [ $dep_json, $dest ] );
next destination;
}
for my $via_name ( $dep->via ) {
if ( $via_name eq $dest->{name} ) {
+ if ( not $dep->is_cancelled ) {
+ $via_count{ $dep->stop_eva } += 1;
+ }
+ if ( $max_per_dest
+ and $via_count{ $dep->stop_eva } > $max_per_dest )
+ {
+ next destination;
+ }
push( @suggestions, [ $dep_json, $dest ] );
next destination;
}
diff --git a/lib/Travelynx/Helper/IRIS.pm b/lib/Travelynx/Helper/IRIS.pm
index d42e7a3..7a4a274 100644
--- a/lib/Travelynx/Helper/IRIS.pm
+++ b/lib/Travelynx/Helper/IRIS.pm
@@ -201,17 +201,61 @@ sub get_departures_p {
}
}
+sub get_connections_p {
+ my ( $self, %opt ) = @_;
+ my $promise = Mojo::Promise->new;
+ my $destinations = $opt{destinations};
+
+ $self->get_departures_p(
+ station => $opt{station},
+ timestamp => $opt{timestamp},
+ lookbehind => 0,
+ lookahead => 60,
+ with_related => 1,
+ )->then(
+ sub {
+ my ($res) = @_;
+ my @suggestions = $self->grep_suggestions(
+ results => $res->{results},
+ destinations => $destinations,
+ max_per_dest => 2
+ );
+ @suggestions
+ = sort { $a->[0]{sort_ts} <=> $b->[0]{sort_ts} } @suggestions;
+ $promise->resolve( \@suggestions );
+ return;
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $promise->reject("get_departures_p($opt{station}): $err");
+ return;
+ }
+ )->wait;
+ return $promise;
+}
+
sub grep_suggestions {
my ( $self, %opt ) = @_;
my $results = $opt{results};
my $destinations = $opt{destinations};
+ my $max_per_dest = $opt{max_per_dest};
my @suggestions;
+ my %via_count;
for my $dep ( @{$results} ) {
destination: for my $dest ( @{$destinations} ) {
for my $via_name ( $dep->route_post ) {
if ( $via_name eq $dest->{name} ) {
+ if ( not $dep->departure_is_cancelled ) {
+ $via_count{ $dep->station_uic } += 1;
+ }
+ if ( $max_per_dest
+ and $via_count{ $dep->station_uic } > $max_per_dest )
+ {
+ next destination;
+ }
my $dep_json = {
id => $dep->train_id,
ts =>
diff --git a/templates/_checked_in.html.ep b/templates/_checked_in.html.ep
index 837032a..659abff 100644
--- a/templates/_checked_in.html.ep
+++ b/templates/_checked_in.html.ep
@@ -235,6 +235,13 @@
% }
%= include '_connections_efa', efa => $journey->{backend_name}, suggestions => \@suggestions, checkin_from => $journey->{arrival_countdown} < 0 ? $journey->{arr_eva} : undef
% }
+ % if (my @suggestions = @{$journey->{extra_data}{connection_suggestions_iris} // []}) {
+ <span class="card-title" style="margin-top: 2ex;">Verbindungen</span>
+ % if ($journey->{arrival_countdown} < 0) {
+ <p>Fahrt auswählen zum Einchecken mit Zielwahl.</p>
+ % }
+ %= include '_connections_iris', suggestions => \@suggestions, checkin_from => $journey->{arrival_countdown} < 0 ? $journey->{arr_eva} : undef
+ % }
% if (defined $journey->{arrival_countdown} and $journey->{arrival_countdown} <= 0) {
<p style="margin-top: 2ex;">
%= L('status.delayed-auto-checkout')
diff --git a/templates/use_history.html.ep b/templates/use_history.html.ep
index b02df18..2211603 100644
--- a/templates/use_history.html.ep
+++ b/templates/use_history.html.ep
@@ -2,7 +2,7 @@
<div class="row">
<div class="col s12">
<p>
- Travelynx kann bei DBRIS- und EFA-Backends anhand deiner
+ Travelynx kann bei DBRIS-, EFA- und IRIS-Backends anhand deiner
vergangenen Fahrten Verbindungen zum Einchecken vorschlagen. Fährst
zu z.B regelmäßig von Dortmund Hbf nach Essen Hbf, werden dir in
Dortmund bevorzugt Fahrten angezeigt, die Essen passieren. Bei