diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-08-30 16:25:08 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-08-30 16:25:08 +0200 |
commit | a6d0292bfd7581b5fc569fbb620b01dc2da89c7a (patch) | |
tree | 2216c8f64838e982b3fa8a6331b12852e4faf9fb /lib | |
parent | 423facc9dfd26bb1702078d88d8d9761d28e3a6b (diff) |
polyline: Handle trips that pass the same stop ID more than once
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travel/Status/DE/EFA/Trip.pm | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/Travel/Status/DE/EFA/Trip.pm b/lib/Travel/Status/DE/EFA/Trip.pm index d7b66c7..070c427 100644 --- a/lib/Travel/Status/DE/EFA/Trip.pm +++ b/lib/Travel/Status/DE/EFA/Trip.pm @@ -78,8 +78,19 @@ sub polyline { $distance = GIS::Distance->new; }; + # Ggf. sollte die Abbildung andersrum laufen: Im zweiten Schritt durch die + # Polyline iterieren und Stops zuordnen (d.h. polyline_i als Key); bei + # Bedarf Polyline-Indexe duplizieren. Lässt sich wunderbar an der Linie + # 101/106 in Essen testen (3x Helenenstr, davon 2x am Anfang und 1x + # mittendrin). + if ($distance) { my %min_dist; + + # A single trip may pass the same stop multiple times, meaning that + # stop IDs alone are not guaranteed to be unique. So we need to use a + # stop's index in the trip's route as key in addition to the stop's ID. + my $route_i = 0; for my $stop ( $self->route ) { for my $polyline_index ( 0 .. $#{ $self->{polyline} } ) { my $pl = $self->{polyline}[$polyline_index]; @@ -88,21 +99,38 @@ sub polyline { $stop->{latlon}[1], $pl->{lat}, $pl->{lon} ); - if ( not $min_dist{ $stop->{id_code} } - or $min_dist{ $stop->{id_code} }{dist} > $dist ) + my $key = $route_i . ';' . $stop->{id_code}; + if ( not $min_dist{$key} + or $min_dist{$key}{dist} > $dist ) { - $min_dist{ $stop->{id_code} } = { + $min_dist{$key} = { dist => $dist, index => $polyline_index, }; } } + $route_i += 1; } + $route_i = 0; for my $stop ( $self->route ) { - if ( $min_dist{ $stop->{id_code} } ) { - $self->{polyline}[ $min_dist{ $stop->{id_code} }{index} ]{stop} + my $key = $route_i . ';' . $stop->{id_code}; + if ( $min_dist{$key} ) { + if ( defined $self->{polyline}[ $min_dist{$key}{index} ]{stop} ) + { + # XXX experimental and untested + # one polyline entry maps to multiple stops → duplicate it; insert $stop after the already-present entry + $min_dist{$key}{index} += 1; + splice( + @{ $self->{polyline} }, + $min_dist{$key}{index}, + 0, { %{ $self->{polyline}[ $min_dist{$key}{index} ] } } + ); + + } + $self->{polyline}[ $min_dist{$key}{index} ]{stop} = $stop; } + $route_i += 1; } } |