diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-07-27 16:10:56 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-07-27 16:10:56 +0200 |
commit | 15355cc17edbd1c83698288f3756e8648adb09e8 (patch) | |
tree | d577ed6ba907640bc2b39f6af7df77efcedd8aec /lib/Travelynx/Model/Journeys.pm | |
parent | 3647c80321bfec3471897f267be3d237f5ee9507 (diff) |
get_travel_distance: explain multi-stop-pass handling
Diffstat (limited to 'lib/Travelynx/Model/Journeys.pm')
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 7862fd9..77d2076 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -1248,16 +1248,34 @@ sub get_travel_distance { my $geo = GIS::Distance->new(); my $distance_beeline = $geo->distance_metal( @{$from_latlon}, @{$to_latlon} ); + + # A trip may pass the same stop multiple times. + # Thus, two criteria must be met to select the start/end of the actual route: + # * stop name or ID matches, and + # * one of: + # - arrival/departure time at the stop matches, or + # - the stop does not have arrival/departure time + # In the latter case, we still face the risk of selecting the wrong + # start/end stop. However, we have no way of finding the right one. As the + # majority of trips do not pass the same stop multiple times, it's better + # to risk having a few inaccurate distances than not calculating the + # distance for any journey that lacks sched_dep/rt_dep or + # schep_from/rt_from. my @route = after_incl { - ( ( $_->[1] and $_->[1] == $from_eva or $_->[0] eq $from ) - and ( defined $_->[2]{sched_dep} or defined $_->[2]{rt_dep} ) - and ( $_->[2]{sched_dep} // $_->[2]{rt_dep} )->epoch == $from_ts ) + ( + ( $_->[1] and $_->[1] == $from_eva or $_->[0] eq $from ) + and ( not( defined $_->[2]{sched_dep} or defined $_->[2]{rt_dep} ) + or ( $_->[2]{sched_dep} // $_->[2]{rt_dep} )->epoch + == $from_ts ) + ) } @{$route_ref}; @route = before_incl { - ( ( $_->[1] and $_->[1] == $to_eva or $_->[0] eq $to ) - and ( defined $_->[2]{sched_arr} or defined $_->[2]{rt_arr} ) - and ( $_->[2]{sched_arr} // $_->[2]{rt_arr} )->epoch == $to_ts ) + ( + ( $_->[1] and $_->[1] == $to_eva or $_->[0] eq $to ) + and ( not( defined $_->[2]{sched_arr} or defined $_->[2]{rt_arr} ) + or ( $_->[2]{sched_arr} // $_->[2]{rt_arr} )->epoch == $to_ts ) + ) } @route; |