summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/missingstations.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-11-25 18:26:32 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-11-25 18:26:32 +0100
commit22069102a75064c403d95a6170df95b4e770f7f2 (patch)
tree28524d3e51e9b17c04d6e62e08f7a51a49625414 /lib/Travelynx/Command/missingstations.pm
parent7a42a2afe0030b7ccd64b2051263adcec856e1b3 (diff)
add missingstations maintenance command
Diffstat (limited to 'lib/Travelynx/Command/missingstations.pm')
-rw-r--r--lib/Travelynx/Command/missingstations.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Travelynx/Command/missingstations.pm b/lib/Travelynx/Command/missingstations.pm
new file mode 100644
index 0000000..ab340ce
--- /dev/null
+++ b/lib/Travelynx/Command/missingstations.pm
@@ -0,0 +1,44 @@
+package Travelynx::Command::missingstations;
+
+# Copyright (C) 2022 Daniel Friesel
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+use Mojo::Base 'Mojolicious::Command';
+use List::Util qw();
+use Travel::Status::DE::IRIS::Stations;
+
+sub run {
+ my ($self) = @_;
+
+ my %station;
+
+ for my $s ( Travel::Status::DE::IRIS::Stations::get_stations() ) {
+ $station{ $s->[2] } = 1;
+ }
+
+ my @journey_stations;
+
+ my $res
+ = $self->app->pg->db->select( 'journeys', ['checkin_station_id'], {},
+ { group_by => ['checkin_station_id'] } );
+ for my $j ( $res->hashes->each ) {
+ push( @journey_stations, $j->{checkin_station_id} );
+ }
+
+ $res = $self->app->pg->db->select( 'journeys', ['checkout_station_id'], {},
+ { group_by => ['checkout_station_id'] } );
+ for my $j ( $res->hashes->each ) {
+ push( @journey_stations, $j->{checkout_station_id} );
+ }
+
+ @journey_stations = List::Util::uniq @journey_stations;
+
+ for my $eva (@journey_stations) {
+ if ( not $station{$eva} ) {
+ say $eva;
+ }
+ }
+}
+
+1;