integritycheck: add sub-commands
This commit is contained in:
parent
fcd78440a5
commit
0f44f8695d
1 changed files with 126 additions and 108 deletions
|
@ -9,58 +9,60 @@ use List::Util qw();
|
||||||
use Travel::Status::DE::IRIS::Stations;
|
use Travel::Status::DE::IRIS::Stations;
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self) = @_;
|
my ( $self, $mode ) = @_;
|
||||||
my $found = 0;
|
my $found = 0;
|
||||||
my $db = $self->app->pg->db;
|
my $db = $self->app->pg->db;
|
||||||
|
|
||||||
my $res1 = $db->query(
|
if ( $mode eq 'all' or $mode eq 'unknown-evas' ) {
|
||||||
qq{
|
|
||||||
select checkin_station_id
|
|
||||||
from journeys
|
|
||||||
left join stations on journeys.checkin_station_id = stations.eva
|
|
||||||
where stations.eva is null;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
my $res2 = $db->query(
|
my %notified;
|
||||||
qq{
|
my $res1 = $db->query(
|
||||||
select checkout_station_id
|
qq{
|
||||||
from journeys
|
select checkin_station_id
|
||||||
left join stations on journeys.checkout_station_id = stations.eva
|
from journeys
|
||||||
where stations.eva is null;
|
left join stations on journeys.checkin_station_id = stations.eva
|
||||||
}
|
where stations.eva is null;
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
my $res2 = $db->query(
|
||||||
|
qq{
|
||||||
|
select checkout_station_id
|
||||||
|
from journeys
|
||||||
|
left join stations on journeys.checkout_station_id = stations.eva
|
||||||
|
where stations.eva is null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
my %notified;
|
while ( my $row = $res1->hash ) {
|
||||||
while ( my $row = $res1->hash ) {
|
my $eva = $row->{checkin_station_id};
|
||||||
my $eva = $row->{checkin_station_id};
|
if ( not $found ) {
|
||||||
if ( not $found ) {
|
$found = 1;
|
||||||
$found = 1;
|
say
|
||||||
say
|
|
||||||
'Journeys in the travelynx database contain the following unknown EVA IDs.';
|
'Journeys in the travelynx database contain the following unknown EVA IDs.';
|
||||||
say '------------8<----------';
|
say '------------8<----------';
|
||||||
say 'Travel::Status::DE::IRIS v'
|
say 'Travel::Status::DE::IRIS v'
|
||||||
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
||||||
|
}
|
||||||
|
if ( not $notified{$eva} ) {
|
||||||
|
say $eva;
|
||||||
|
$notified{$eva} = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( not $notified{$eva} ) {
|
|
||||||
say $eva;
|
|
||||||
$notified{$eva} = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( my $row = $res2->hash ) {
|
while ( my $row = $res2->hash ) {
|
||||||
my $eva = $row->{checkout_station_id};
|
my $eva = $row->{checkout_station_id};
|
||||||
if ( not $found ) {
|
if ( not $found ) {
|
||||||
$found = 1;
|
$found = 1;
|
||||||
say
|
say
|
||||||
'Journeys in the travelynx database contain the following unknown EVA IDs.';
|
'Journeys in the travelynx database contain the following unknown EVA IDs.';
|
||||||
say '------------8<----------';
|
say '------------8<----------';
|
||||||
say 'Travel::Status::DE::IRIS v'
|
say 'Travel::Status::DE::IRIS v'
|
||||||
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
||||||
}
|
}
|
||||||
if ( not $notified{$eva} ) {
|
if ( not $notified{$eva} ) {
|
||||||
say $eva;
|
say $eva;
|
||||||
$notified{$eva} = 1;
|
$notified{$eva} = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,36 +72,93 @@ sub run {
|
||||||
$found = 0;
|
$found = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $rename = $self->app->renamed_station;
|
if ( $mode eq 'all' or $mode eq 'unknown-route-entries' ) {
|
||||||
|
|
||||||
my $res = $db->select( 'journeys', [ 'route', 'edited' ] )->expand;
|
my %notified;
|
||||||
while ( my $j = $res->hash ) {
|
my $rename = $self->app->renamed_station;
|
||||||
if ( $j->{edited} & 0x0010 ) {
|
my $res = $db->select( 'journeys', [ 'route', 'edited' ] )->expand;
|
||||||
next;
|
|
||||||
}
|
while ( my $j = $res->hash ) {
|
||||||
my @stops = @{ $j->{route} // [] };
|
if ( $j->{edited} & 0x0010 ) {
|
||||||
for my $stop (@stops) {
|
next;
|
||||||
my $stop_name = $stop->[0];
|
}
|
||||||
if ( $rename->{ $stop->[0] } ) {
|
my @stops = @{ $j->{route} // [] };
|
||||||
$stop->[0] = $rename->{ $stop->[0] };
|
for my $stop (@stops) {
|
||||||
|
my $stop_name = $stop->[0];
|
||||||
|
if ( $rename->{ $stop->[0] } ) {
|
||||||
|
$stop->[0] = $rename->{ $stop->[0] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my @unknown
|
||||||
|
= $self->app->stations->grep_unknown( map { $_->[0] } @stops );
|
||||||
|
for my $stop_name (@unknown) {
|
||||||
|
if ( not $notified{$stop_name} ) {
|
||||||
|
if ( not $found ) {
|
||||||
|
say
|
||||||
|
'Journeys in the travelynx database contain the following unknown route entries.';
|
||||||
|
say
|
||||||
|
'Note that this check ignores manual route entries.';
|
||||||
|
say
|
||||||
|
'All reports refer to routes obtained via HAFAS/IRIS.';
|
||||||
|
say '------------8<----------';
|
||||||
|
say 'Travel::Status::DE::IRIS v'
|
||||||
|
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
||||||
|
$found = 1;
|
||||||
|
}
|
||||||
|
say $stop_name;
|
||||||
|
$notified{$stop_name} = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my @unknown
|
}
|
||||||
= $self->app->stations->grep_unknown( map { $_->[0] } @stops );
|
|
||||||
for my $stop_name (@unknown) {
|
if ($found) {
|
||||||
if ( not $notified{$stop_name} ) {
|
say '------------8<----------';
|
||||||
|
say '';
|
||||||
|
$found = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $mode eq 'all' or $mode eq 'checkout-eva-vs-route-eva' ) {
|
||||||
|
|
||||||
|
my $res = $db->select(
|
||||||
|
'journeys_str',
|
||||||
|
[ 'journey_id', 'sched_arr_ts', 'route', 'arr_name', 'arr_eva' ],
|
||||||
|
{ backend_id => 0 }
|
||||||
|
)->expand;
|
||||||
|
|
||||||
|
journey: while ( my $j = $res->hash ) {
|
||||||
|
my $found_in_route;
|
||||||
|
my $found_arr;
|
||||||
|
for my $stop ( @{ $j->{route} // [] } ) {
|
||||||
|
if ( not $stop->[1] ) {
|
||||||
|
next journey;
|
||||||
|
}
|
||||||
|
if ( $stop->[1] == $j->{arr_eva} ) {
|
||||||
|
$found_in_route = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
if ( $stop->[2]{sched_arr}
|
||||||
|
and $j->{sched_arr_ts}
|
||||||
|
and $stop->[2]{sched_arr} == int( $j->{sched_arr_ts} ) )
|
||||||
|
{
|
||||||
|
$found_arr = $stop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $found_arr and not $found_in_route ) {
|
||||||
if ( not $found ) {
|
if ( not $found ) {
|
||||||
|
say q{};
|
||||||
say
|
say
|
||||||
'Journeys in the travelynx database contain the following unknown route entries.';
|
'The following journeys have route entries which do not agree with checkout EVA ID.';
|
||||||
say 'Note that this check ignores manual route entries.';
|
say
|
||||||
say 'All reports refer to routes obtained via HAFAS/IRIS.';
|
'checkout station ID (left) vs route entry with matching checkout time (right)';
|
||||||
say '------------8<----------';
|
say '------------8<----------';
|
||||||
say 'Travel::Status::DE::IRIS v'
|
|
||||||
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
|
||||||
$found = 1;
|
$found = 1;
|
||||||
}
|
}
|
||||||
say $stop_name;
|
printf(
|
||||||
$notified{$stop_name} = 1;
|
"%7d %d (%s) vs %d (%s)\n",
|
||||||
|
$j->{journey_id}, $j->{arr_eva}, $j->{arr_name},
|
||||||
|
$found_arr->[1], $found_arr->[0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,47 +168,6 @@ sub run {
|
||||||
say '';
|
say '';
|
||||||
$found = 0;
|
$found = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $db->select(
|
|
||||||
'journeys_str',
|
|
||||||
[ 'journey_id', 'sched_arr_ts', 'route', 'arr_name', 'arr_eva' ],
|
|
||||||
{ backend_id => 0 }
|
|
||||||
)->expand;
|
|
||||||
journey: while ( my $j = $res->hash ) {
|
|
||||||
my $found_in_route;
|
|
||||||
my $found_arr;
|
|
||||||
for my $stop ( @{ $j->{route} // [] } ) {
|
|
||||||
if ( not $stop->[1] ) {
|
|
||||||
next journey;
|
|
||||||
}
|
|
||||||
if ( $stop->[1] == $j->{arr_eva} ) {
|
|
||||||
$found_in_route = 1;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
if ( $stop->[2]{sched_arr}
|
|
||||||
and $j->{sched_arr_ts}
|
|
||||||
and $stop->[2]{sched_arr} == int( $j->{sched_arr_ts} ) )
|
|
||||||
{
|
|
||||||
$found_arr = $stop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( $found_arr and not $found_in_route ) {
|
|
||||||
if ( not $found ) {
|
|
||||||
say q{};
|
|
||||||
say
|
|
||||||
'The following journeys have route entries which do not agree with checkout EVA ID.';
|
|
||||||
say
|
|
||||||
'checkout station ID (left) vs route entry with matching checkout time (right)';
|
|
||||||
say '------------8<----------';
|
|
||||||
$found = 1;
|
|
||||||
}
|
|
||||||
printf(
|
|
||||||
"%7d %d (%s) vs %d (%s)\n",
|
|
||||||
$j->{journey_id}, $j->{arr_eva}, $j->{arr_name},
|
|
||||||
$found_arr->[1], $found_arr->[0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in a new issue