Ignore stations without coordinates in distance calculation
Reported by @marudor
This commit is contained in:
parent
24d0943cdc
commit
78b2d995ef
3 changed files with 67 additions and 11 deletions
|
@ -479,6 +479,22 @@ qq{select * from pending_mails where email = ? and num_tries > 1;}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$self->helper(
|
||||||
|
'numify_skipped_stations' => sub {
|
||||||
|
my ( $self, $count ) = @_;
|
||||||
|
|
||||||
|
if ( $count == 0 ) {
|
||||||
|
return 'INTERNAL ERROR';
|
||||||
|
}
|
||||||
|
if ( $count == 1 ) {
|
||||||
|
return
|
||||||
|
'Eine Station ohne Geokoordinaten wurde nicht berücksichtigt.';
|
||||||
|
}
|
||||||
|
return
|
||||||
|
"${count} Stationen ohne Geookordinaten wurden nicht berücksichtigt.";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$self->helper(
|
$self->helper(
|
||||||
'get_departures' => sub {
|
'get_departures' => sub {
|
||||||
my ( $self, $station, $lookbehind ) = @_;
|
my ( $self, $station, $lookbehind ) = @_;
|
||||||
|
@ -1407,13 +1423,17 @@ qq{select * from pending_mails where email = ? and num_tries > 1;}
|
||||||
? $ref->{rt_arrival}->epoch
|
? $ref->{rt_arrival}->epoch
|
||||||
- $ref->{rt_departure}->epoch
|
- $ref->{rt_departure}->epoch
|
||||||
: undef;
|
: undef;
|
||||||
$ref->{km_route}
|
my ( $km, $skip )
|
||||||
= $self->get_travel_distance( $ref->{from_name},
|
= $self->get_travel_distance( $ref->{from_name},
|
||||||
$ref->{to_name}, $ref->{route} );
|
$ref->{to_name}, $ref->{route} );
|
||||||
$ref->{km_beeline}
|
$ref->{km_route} = $km;
|
||||||
|
$ref->{skip_route} = $skip;
|
||||||
|
( $km, $skip )
|
||||||
= $self->get_travel_distance( $ref->{from_name},
|
= $self->get_travel_distance( $ref->{from_name},
|
||||||
$ref->{to_name},
|
$ref->{to_name},
|
||||||
[ $ref->{from_name}, $ref->{to_name} ] );
|
[ $ref->{from_name}, $ref->{to_name} ] );
|
||||||
|
$ref->{km_beeline} = $km;
|
||||||
|
$ref->{skip_beeline} = $skip;
|
||||||
my $kmh_divisor
|
my $kmh_divisor
|
||||||
= ( $ref->{rt_duration} // $ref->{sched_duration}
|
= ( $ref->{rt_duration} // $ref->{sched_duration}
|
||||||
// 999999 ) / 3600;
|
// 999999 ) / 3600;
|
||||||
|
@ -1531,6 +1551,7 @@ qq{select * from pending_mails where email = ? and num_tries > 1;}
|
||||||
my ( $self, $from, $to, $route_ref ) = @_;
|
my ( $self, $from, $to, $route_ref ) = @_;
|
||||||
|
|
||||||
my $distance = 0;
|
my $distance = 0;
|
||||||
|
my $skipped = 0;
|
||||||
my $geo = Geo::Distance->new();
|
my $geo = Geo::Distance->new();
|
||||||
my @route = after_incl { $_ eq $from } @{$route_ref};
|
my @route = after_incl { $_ eq $from } @{$route_ref};
|
||||||
@route = before_incl { $_ eq $to } @route;
|
@route = before_incl { $_ eq $to } @route;
|
||||||
|
@ -1548,14 +1569,19 @@ qq{select * from pending_mails where email = ? and num_tries > 1;}
|
||||||
|
|
||||||
for my $station_name (@route) {
|
for my $station_name (@route) {
|
||||||
if ( my $station = get_station($station_name) ) {
|
if ( my $station = get_station($station_name) ) {
|
||||||
|
if ( $#{$prev_station} >= 4 and $#{$station} >= 4 ) {
|
||||||
$distance
|
$distance
|
||||||
+= $geo->distance( 'kilometer', $prev_station->[3],
|
+= $geo->distance( 'kilometer', $prev_station->[3],
|
||||||
$prev_station->[4], $station->[3], $station->[4] );
|
$prev_station->[4], $station->[3], $station->[4] );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$skipped++;
|
||||||
|
}
|
||||||
$prev_station = $station;
|
$prev_station = $station;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $distance;
|
return ( $distance, $skipped );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,20 @@ my @migrations = (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# v2 -> v3
|
||||||
|
# A bug in the journey distance calculation caused excessive distances to be
|
||||||
|
# reported for routes covering stations without GPS coordinates. Ensure
|
||||||
|
# all caches are rebuilt.
|
||||||
|
sub {
|
||||||
|
my ($dbh) = @_;
|
||||||
|
return $dbh->do(
|
||||||
|
qq{
|
||||||
|
delete from journey_stats;
|
||||||
|
update schema_version set version = 3;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
sub setup_db {
|
sub setup_db {
|
||||||
|
|
|
@ -89,20 +89,36 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Entfernung</th>
|
<th scope="row">Entfernung</th>
|
||||||
<td>
|
<td>
|
||||||
|
% if ($journey->{skip_route}) {
|
||||||
|
<i class="material-icons right">gps_off</i>
|
||||||
|
<%= numify_skipped_stations($journey->{skip_route}) %><br/>
|
||||||
|
% }
|
||||||
% if ($journey->{km_route} > 0.1) {
|
% if ($journey->{km_route} > 0.1) {
|
||||||
ca. <%= sprintf('%.f', $journey->{km_route}) %> km
|
ca. <%= sprintf('%.f', $journey->{km_route}) %> km
|
||||||
% }
|
|
||||||
(Luftlinie: <%= sprintf('%.f', $journey->{km_beeline}) %> km)
|
(Luftlinie: <%= sprintf('%.f', $journey->{km_beeline}) %> km)
|
||||||
|
% }
|
||||||
|
% else {
|
||||||
|
?
|
||||||
|
% }
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Geschwindigkeit</th>
|
<th scope="row">Geschwindigkeit</th>
|
||||||
<td>
|
<td>
|
||||||
|
% if ($journey->{skip_route}) {
|
||||||
|
<i class="material-icons right">gps_off</i>
|
||||||
|
<%= numify_skipped_stations($journey->{skip_route}) %><br/>
|
||||||
|
% }
|
||||||
|
% if ($journey->{km_route} > 0.1 and $journey->{kmh_route} > 0.01) {
|
||||||
∅ <%= sprintf('%.f', $journey->{kmh_route}) %> km/h
|
∅ <%= sprintf('%.f', $journey->{kmh_route}) %> km/h
|
||||||
(<%= sprintf('%.f', $journey->{kmh_beeline}) %> km/h)
|
(<%= sprintf('%.f', $journey->{kmh_beeline}) %> km/h)
|
||||||
% if ($journey->{edited} & 0x0303) {
|
% if ($journey->{edited} & 0x0303) {
|
||||||
∗
|
∗
|
||||||
% }
|
% }
|
||||||
|
% }
|
||||||
|
% else {
|
||||||
|
?
|
||||||
|
% }
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in a new issue