move grep_unknown_stations to Stations model
This commit is contained in:
parent
afedcef266
commit
115e07f35c
3 changed files with 23 additions and 31 deletions
|
@ -419,21 +419,6 @@ sub startup {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->helper(
|
|
||||||
'grep_unknown_stations' => sub {
|
|
||||||
my ( $self, @stations ) = @_;
|
|
||||||
|
|
||||||
my @unknown_stations;
|
|
||||||
for my $station (@stations) {
|
|
||||||
my $station_info = $self->stations->get_by_name($station);
|
|
||||||
if ( not $station_info ) {
|
|
||||||
push( @unknown_stations, $station );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return @unknown_stations;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$self->helper(
|
$self->helper(
|
||||||
'load_icon' => sub {
|
'load_icon' => sub {
|
||||||
my ( $self, $load ) = @_;
|
my ( $self, $load ) = @_;
|
||||||
|
@ -750,7 +735,7 @@ sub startup {
|
||||||
$has_arrived = $train->arrival->epoch < $now->epoch ? 1 : 0;
|
$has_arrived = $train->arrival->epoch < $now->epoch ? 1 : 0;
|
||||||
if ($has_arrived) {
|
if ($has_arrived) {
|
||||||
my @unknown_stations
|
my @unknown_stations
|
||||||
= $self->grep_unknown_stations( $train->route );
|
= $self->stations->grep_unknown( $train->route );
|
||||||
if (@unknown_stations) {
|
if (@unknown_stations) {
|
||||||
$self->app->log->warn(
|
$self->app->log->warn(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
|
|
@ -34,19 +34,6 @@ sub epoch_to_dt {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub grep_unknown_stations {
|
|
||||||
my ( $self, @stations ) = @_;
|
|
||||||
|
|
||||||
my @unknown_stations;
|
|
||||||
for my $station (@stations) {
|
|
||||||
my $station_info = $self->{stations}->get_by_name($station);
|
|
||||||
if ( not $station_info ) {
|
|
||||||
push( @unknown_stations, $station );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return @unknown_stations;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $class, %opt ) = @_;
|
my ( $class, %opt ) = @_;
|
||||||
|
|
||||||
|
@ -917,8 +904,8 @@ sub sanity_check {
|
||||||
}
|
}
|
||||||
if ( $journey->{edited} & 0x0010 and not $lax ) {
|
if ( $journey->{edited} & 0x0010 and not $lax ) {
|
||||||
my @unknown_stations
|
my @unknown_stations
|
||||||
= $self->grep_unknown_stations( map { $_->[0] }
|
= $self->{stations}
|
||||||
@{ $journey->{route} } );
|
->grep_unknown( map { $_->[0] } @{ $journey->{route} } );
|
||||||
if (@unknown_stations) {
|
if (@unknown_stations) {
|
||||||
return 'Unbekannte Station(en): ' . join( ', ', @unknown_stations );
|
return 'Unbekannte Station(en): ' . join( ', ', @unknown_stations );
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,16 @@ sub get_by_name {
|
||||||
->hash;
|
->hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Slow
|
||||||
|
sub get_by_names {
|
||||||
|
my ( $self, @names ) = @_;
|
||||||
|
|
||||||
|
my @ret
|
||||||
|
= $self->{pg}->db->select( 'stations', '*', { name => { '=', \@names } } )
|
||||||
|
->hashes->each;
|
||||||
|
return @ret;
|
||||||
|
}
|
||||||
|
|
||||||
# Slow
|
# Slow
|
||||||
sub get_by_ds100 {
|
sub get_by_ds100 {
|
||||||
my ( $self, $ds100, %opt ) = @_;
|
my ( $self, $ds100, %opt ) = @_;
|
||||||
|
@ -85,4 +95,14 @@ sub search {
|
||||||
// $self->get_by_name( $identifier, %opt );
|
// $self->get_by_name( $identifier, %opt );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Slow
|
||||||
|
sub grep_unknown {
|
||||||
|
my ( $self, @stations ) = @_;
|
||||||
|
|
||||||
|
my %station = map { $_->{name} => 1 } $self->get_by_names(@stations);
|
||||||
|
my @unknown_stations = grep { not $station{$_} } @stations;
|
||||||
|
|
||||||
|
return @unknown_stations;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in a new issue