summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Helper
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-12-27 18:42:42 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-12-27 18:42:42 +0100
commite9e06417cff8f42beb4debc9a90cb439f53e0bce (patch)
tree6e38b4689bd8d63eac31e518804666e5374b695e /lib/Travelynx/Helper
parent3acb1b379b9be3c1cc252d7a55f1ec34240e48f6 (diff)
DBRIS: show connections while still checked in
Diffstat (limited to 'lib/Travelynx/Helper')
-rw-r--r--lib/Travelynx/Helper/DBRIS.pm76
-rw-r--r--lib/Travelynx/Helper/EFA.pm1
2 files changed, 77 insertions, 0 deletions
diff --git a/lib/Travelynx/Helper/DBRIS.pm b/lib/Travelynx/Helper/DBRIS.pm
index deeed65..e1f52eb 100644
--- a/lib/Travelynx/Helper/DBRIS.pm
+++ b/lib/Travelynx/Helper/DBRIS.pm
@@ -127,6 +127,39 @@ 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 => '@L=' . $opt{station},
+ timestamp => $opt{timestamp},
+ lookbehind => 0,
+ lookahead => 60,
+ )->then(
+ sub {
+ my ($status) = @_;
+ my @suggestions = $self->grep_suggestions(
+ status => $status,
+ 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 get_journey_p {
my ( $self, %opt ) = @_;
@@ -186,4 +219,47 @@ sub get_wagonorder_p {
);
}
+sub grep_suggestions {
+ my ( $self, %opt ) = @_;
+ my $status = $opt{status};
+ my $destinations = $opt{destinations};
+ my $max_per_dest = $opt{max_per_dest};
+
+ my @suggestions;
+ my %via_count;
+
+ for my $dep ( $status->results ) {
+ my $dep_json = {
+ id => $dep->id,
+ 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},
+ sched_hhmm => $dep->sched_dep->strftime('%H:%M'),
+ rt_hhmm => $dep->dep->strftime('%H:%M'),
+ delay => $dep->delay,
+ platform => $dep->platform,
+ type => $dep->type,
+ line => $dep->line,
+ };
+ destination: for my $dest ( @{$destinations} ) {
+ if ( $dep->destination
+ and $dep->destination eq $dest->{name} )
+ {
+ push( @suggestions, [ $dep_json, $dest ] );
+ next destination;
+ }
+ for my $via_name ( $dep->via ) {
+ if ( $via_name eq $dest->{name} ) {
+ push( @suggestions, [ $dep_json, $dest ] );
+ next destination;
+ }
+ }
+ }
+ }
+
+ return @suggestions;
+}
+
1;
diff --git a/lib/Travelynx/Helper/EFA.pm b/lib/Travelynx/Helper/EFA.pm
index 2f3ff1f..f717f1e 100644
--- a/lib/Travelynx/Helper/EFA.pm
+++ b/lib/Travelynx/Helper/EFA.pm
@@ -56,6 +56,7 @@ sub grep_suggestions {
my @suggestions;
my %via_count;
+
for my $dep ( $status->results ) {
destination: for my $dest ( @{$destinations} ) {
for my $stop ( $dep->route_post ) {