stats, map: deal with multiple EVA IDs mapping to the same station name
This commit is contained in:
parent
d156e3389e
commit
9b7013907b
2 changed files with 79 additions and 20 deletions
|
@ -2136,6 +2136,31 @@ sub startup {
|
|||
my $to_index
|
||||
= first_index { $_->[2] and $_->[2] == $to_eva } @polyline;
|
||||
|
||||
# Work around inconsistencies caused by a multiple EVA IDs mapping to the same station name
|
||||
if ( $from_index == -1 ) {
|
||||
for my $entry ( @{ $journey->{route} // [] } ) {
|
||||
if ( $entry->[0] eq $journey->{from_name} ) {
|
||||
$from_eva = $entry->[1];
|
||||
$from_index
|
||||
= first_index { $_->[2] and $_->[2] == $from_eva }
|
||||
@polyline;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $to_index == -1 ) {
|
||||
for my $entry ( @{ $journey->{route} // [] } ) {
|
||||
if ( $entry->[0] eq $journey->{to_name} ) {
|
||||
$to_eva = $entry->[1];
|
||||
$to_index
|
||||
= first_index { $_->[2] and $_->[2] == $to_eva }
|
||||
@polyline;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $from_index == -1
|
||||
or $to_index == -1 )
|
||||
{
|
||||
|
|
|
@ -1126,6 +1126,39 @@ sub get_travel_distance {
|
|||
->warn("Journey $journey->{id} has no from_name for EVA $from_eva");
|
||||
}
|
||||
|
||||
# Work around inconsistencies caused by a multiple EVA IDs mapping to the same station name
|
||||
if (
|
||||
not List::MoreUtils::any { $_->[2] and $_->[2] == $from_eva }
|
||||
@{ $polyline_ref // [] }
|
||||
)
|
||||
{
|
||||
$self->{log}->debug(
|
||||
"Journey $journey->{id} from_eva ($from_eva) is not part of polyline"
|
||||
);
|
||||
for my $entry ( @{$route_ref} ) {
|
||||
if ( $entry->[0] eq $from ) {
|
||||
$from_eva = $entry->[1];
|
||||
$self->{log}->debug("... setting to $from_eva");
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
not List::MoreUtils::any { $_->[2] and $_->[2] == $to_eva }
|
||||
@{ $polyline_ref // [] }
|
||||
)
|
||||
{
|
||||
$self->{log}->debug(
|
||||
"Journey $journey->{id} to_eva ($to_eva) is not part of polyline");
|
||||
for my $entry ( @{$route_ref} ) {
|
||||
if ( $entry->[0] eq $to ) {
|
||||
$to_eva = $entry->[1];
|
||||
$self->{log}->debug("... setting to $to_eva");
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $distance_polyline = 0;
|
||||
my $distance_intermediate = 0;
|
||||
my $geo = GIS::Distance->new();
|
||||
|
@ -1134,7 +1167,7 @@ sub get_travel_distance {
|
|||
my @route = after_incl { $_->[0] eq $from } @{$route_ref};
|
||||
@route = before_incl { $_->[0] eq $to } @route;
|
||||
|
||||
if ( @route < 2 ) {
|
||||
if ( @route < 2 or $route[-1][0] ne $to ) {
|
||||
|
||||
# I AM ERROR
|
||||
return ( 0, 0, $distance_beeline );
|
||||
|
@ -1145,6 +1178,8 @@ sub get_travel_distance {
|
|||
@polyline
|
||||
= before_incl { $_->[2] and $_->[2] == $to_eva } @polyline;
|
||||
|
||||
# ensure that before_incl matched -- otherwise, @polyline is too long
|
||||
if ( @polyline and $polyline[-1][2] == $to_eva ) {
|
||||
my $prev_station = shift @polyline;
|
||||
for my $station (@polyline) {
|
||||
$distance_polyline += $geo->distance_metal(
|
||||
|
@ -1153,12 +1188,10 @@ sub get_travel_distance {
|
|||
);
|
||||
$prev_station = $station;
|
||||
}
|
||||
|
||||
if ( not( defined $route[0][2]{lat} and defined $route[0][2]{lon} ) ) {
|
||||
return ( $distance_polyline, 0, $distance_beeline );
|
||||
}
|
||||
|
||||
$prev_station = shift @route;
|
||||
if ( defined $route[0][2]{lat} and defined $route[0][2]{lon} ) {
|
||||
my $prev_station = shift @route;
|
||||
for my $station (@route) {
|
||||
if ( defined $station->[2]{lat} and defined $station->[2]{lon} ) {
|
||||
$distance_intermediate += $geo->distance_metal(
|
||||
|
@ -1168,6 +1201,7 @@ sub get_travel_distance {
|
|||
$prev_station = $station;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( $distance_polyline, $distance_intermediate, $distance_beeline );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue