summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-12-27 19:43:40 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-12-27 19:43:40 +0100
commit364137b9b6339b724b109160e6e0d3904b022037 (patch)
treed1477e0b9929e416685997ffd838c46c711f14e0 /lib
parent3bdfdc74045b48937c446d96fc581931f544fc64 (diff)
IRIS: refactor checkin suggestions into IRIS helper
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm24
-rw-r--r--lib/Travelynx/Helper/IRIS.pm35
2 files changed, 45 insertions, 14 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index 148701f..28d7bfd 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -996,20 +996,16 @@ sub station {
backend_id => 0,
eva => $status->{station_eva},
);
- for my $dep (@results) {
- destination: for my $dest (@destinations) {
- for my $via_name ( $dep->route_post ) {
- if ( $via_name eq $dest->{name} ) {
- push( @suggestions, [ $dep, $dest ] );
- next destination;
- }
- }
- }
- }
- @suggestions = map { $_->[0] }
- sort { $a->[1] <=> $b->[1] }
- grep { $_->[1] >= $now - 300 }
- map { [ $_, $_->[0]->departure->epoch ] } @suggestions;
+ @suggestions = $self->iris->grep_suggestions(
+ results => \@results,
+ destinations => \@destinations
+ );
+ @suggestions
+ = sort { $a->[0]{sort_ts} <=> $b->[0]{sort_ts} }
+ grep {
+ $_->[0]{sort_ts} >= $now - 300
+ and $_->[0]{sort_ts} <= $now + 1800
+ } @suggestions;
}
}
diff --git a/lib/Travelynx/Helper/IRIS.pm b/lib/Travelynx/Helper/IRIS.pm
index 34739eb..d42e7a3 100644
--- a/lib/Travelynx/Helper/IRIS.pm
+++ b/lib/Travelynx/Helper/IRIS.pm
@@ -201,6 +201,41 @@ sub get_departures_p {
}
}
+sub grep_suggestions {
+ my ( $self, %opt ) = @_;
+ my $results = $opt{results};
+ my $destinations = $opt{destinations};
+
+ my @suggestions;
+
+ for my $dep ( @{$results} ) {
+ destination: for my $dest ( @{$destinations} ) {
+ for my $via_name ( $dep->route_post ) {
+ if ( $via_name eq $dest->{name} ) {
+ my $dep_json = {
+ id => $dep->train_id,
+ ts =>
+ ( $dep->sched_departure // $dep->departure )->epoch,
+ sort_ts => $dep->departure->epoch,
+ station_uic => $dep->station_uic,
+ departure_is_cancelled => $dep->departure_is_cancelled,
+ sched_hhmm => $dep->sched_departure->strftime('%H:%M'),
+ rt_hhmm => $dep->departure->strftime('%H:%M'),
+ departure_delay => $dep->departure_delay,
+ platform => $dep->platform,
+ type => $dep->type,
+ line => $dep->line,
+ };
+ push( @suggestions, [ $dep_json, $dest ] );
+ next destination;
+ }
+ }
+ }
+ }
+
+ return @suggestions;
+}
+
sub route_diff {
my ( $self, $train ) = @_;
my @json_route;