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
|
my $to_index
|
||||||
= first_index { $_->[2] and $_->[2] == $to_eva } @polyline;
|
= 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
|
if ( $from_index == -1
|
||||||
or $to_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");
|
->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_polyline = 0;
|
||||||
my $distance_intermediate = 0;
|
my $distance_intermediate = 0;
|
||||||
my $geo = GIS::Distance->new();
|
my $geo = GIS::Distance->new();
|
||||||
|
@ -1134,7 +1167,7 @@ sub get_travel_distance {
|
||||||
my @route = after_incl { $_->[0] eq $from } @{$route_ref};
|
my @route = after_incl { $_->[0] eq $from } @{$route_ref};
|
||||||
@route = before_incl { $_->[0] eq $to } @route;
|
@route = before_incl { $_->[0] eq $to } @route;
|
||||||
|
|
||||||
if ( @route < 2 ) {
|
if ( @route < 2 or $route[-1][0] ne $to ) {
|
||||||
|
|
||||||
# I AM ERROR
|
# I AM ERROR
|
||||||
return ( 0, 0, $distance_beeline );
|
return ( 0, 0, $distance_beeline );
|
||||||
|
@ -1145,30 +1178,31 @@ sub get_travel_distance {
|
||||||
@polyline
|
@polyline
|
||||||
= before_incl { $_->[2] and $_->[2] == $to_eva } @polyline;
|
= before_incl { $_->[2] and $_->[2] == $to_eva } @polyline;
|
||||||
|
|
||||||
my $prev_station = shift @polyline;
|
# ensure that before_incl matched -- otherwise, @polyline is too long
|
||||||
for my $station (@polyline) {
|
if ( @polyline and $polyline[-1][2] == $to_eva ) {
|
||||||
$distance_polyline += $geo->distance_metal(
|
my $prev_station = shift @polyline;
|
||||||
$prev_station->[1], $prev_station->[0],
|
for my $station (@polyline) {
|
||||||
$station->[1], $station->[0]
|
$distance_polyline += $geo->distance_metal(
|
||||||
);
|
$prev_station->[1], $prev_station->[0],
|
||||||
$prev_station = $station;
|
$station->[1], $station->[0]
|
||||||
}
|
|
||||||
|
|
||||||
if ( not( defined $route[0][2]{lat} and defined $route[0][2]{lon} ) ) {
|
|
||||||
return ( $distance_polyline, 0, $distance_beeline );
|
|
||||||
}
|
|
||||||
|
|
||||||
$prev_station = shift @route;
|
|
||||||
for my $station (@route) {
|
|
||||||
if ( defined $station->[2]{lat} and defined $station->[2]{lon} ) {
|
|
||||||
$distance_intermediate += $geo->distance_metal(
|
|
||||||
$prev_station->[2]{lat}, $prev_station->[2]{lon},
|
|
||||||
$station->[2]{lat}, $station->[2]{lon}
|
|
||||||
);
|
);
|
||||||
$prev_station = $station;
|
$prev_station = $station;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
$prev_station->[2]{lat}, $prev_station->[2]{lon},
|
||||||
|
$station->[2]{lat}, $station->[2]{lon}
|
||||||
|
);
|
||||||
|
$prev_station = $station;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ( $distance_polyline, $distance_intermediate, $distance_beeline );
|
return ( $distance_polyline, $distance_intermediate, $distance_beeline );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue