Commit de828666 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add mot filter support

parent 9231b5cf
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
git HEAD

    * Line: Add mot and mot_name accessors
    * Result: Add mot and mot_name accessors
    * efa-m: Add -m / --mot option

Travel::Status::DE::VRR 1.11 - Tue Jun 30 2015

    * efa-m: Remove -V alias for --version
+21 −3
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ my ( $date, $time, $input_type, $list_lines, $offset, $relative_times );
my ($full_routes);
my ( $filter_via, $track_via );
my ( $timeout,    $developer_mode );
my ( @grep_lines, @grep_platforms );
my ( @grep_lines, @grep_platforms, @grep_mots );
my ( %edata,      @edata_pre );

@ARGV = map { decode( 'UTF-8', $_ ) } @ARGV;
@@ -30,6 +30,7 @@ GetOptions(
	'h|help'        => sub { show_help(0) },
	'l|line=s@'     => \@grep_lines,
	'L|linelist'    => \$list_lines,
	'm|mot=s@'      => \@grep_mots,
	'o|offset=i'    => \$offset,
	'O|output=s@'   => \@edata_pre,
	'p|platform=s@' => \@grep_platforms,
@@ -51,6 +52,7 @@ if ( @ARGV != 2 ) {
# --line=foo,bar support
@edata_pre      = split( qr{,}, join( q{,}, @edata_pre ) );
@grep_lines     = split( qr{,}, join( q{,}, @grep_lines ) );
@grep_mots      = split( qr{,}, join( q{,}, @grep_mots ) );
@grep_platforms = split( qr{,}, join( q{,}, @grep_platforms ) );

my ( $place, $input ) = @ARGV;
@@ -174,7 +176,13 @@ sub show_lines {

	for my $l ( $status->lines ) {

		if ( @grep_lines and not( $l->name ~~ \@grep_lines ) ) {
		if (   ( @grep_lines and not( $l->name ~~ \@grep_lines ) )
			or ( @grep_mots and not( $l->mot_name ~~ \@grep_mots ) ) )
		{
			next;
		}

		if ( @grep_mots and not( $l->mot_name ~~ \@grep_mots ) ) {
			next;
		}

@@ -207,6 +215,7 @@ sub show_results {

		if (
			   ( @grep_lines and not( $d->line ~~ \@grep_lines ) )
			or ( @grep_mots and not( $d->mot_name ~~ \@grep_mots ) )
			or ( @grep_platforms
				and not( $platform ~~ \@grep_platforms ) )
			or ( $offset and $d->countdown < $offset )
@@ -326,6 +335,15 @@ using B<--date> and B<--time> are guaranteed to be included.
Only show departures of I<lines> (comma-separatad list, option may be
repeated)

=item B<-m>, B<--mot> I<motlist>

Only show departures whose type appears in I<motlist> (comma-separated list,
this option may be repeated).

The following departure types ("modes of transport") are supported:
zug, s-bahn, u-bahn, stadtbahn, tram, stadtbus, regionalbus, schnellbus,
seilbahn, schiff, ast, sonstige

=item B<-o>, B<--offset> I<minutes>

Ignore departures which are less than I<minutes> from now.
+4 −0
Original line number Diff line number Diff line
@@ -293,6 +293,7 @@ sub lines {
		my $direction  = $e->getAttribute('direction');
		my $valid      = $e->getAttribute('valid');
		my $type       = $e_info->getAttribute('name');
		my $mot        = $e->getAttribute('motType');
		my $route      = ( $e_route ? $e_route->textContent : undef );
		my $operator   = ( $e_oper ? $e_oper->textContent : undef );
		my $identifier = $e->getAttribute('stateless');
@@ -304,6 +305,7 @@ sub lines {
				direction  => decode( 'UTF-8', $direction ),
				valid      => $valid,
				type       => decode( 'UTF-8', $type ),
				mot        => $mot,
				route      => decode( 'UTF-8', $route ),
				operator   => decode( 'UTF-8', $operator ),
				identifier => $identifier,
@@ -408,6 +410,7 @@ sub results {
		my $countdown     = $e->getAttribute('countdown');
		my $delay         = $e_info->getAttribute('delay');
		my $type          = $e_info->getAttribute('name');
		my $mot           = $e_line->getAttribute('motType');

		my $platform_is_db = 0;

@@ -467,6 +470,7 @@ sub results {
				sched_date    => $date,
				sched_time    => $time,
				type          => $type,
				mot           => $mot,
				prev_route    => \@prev_route,
				next_route    => \@next_route,
			)
+12 −1
Original line number Diff line number Diff line
@@ -9,7 +9,12 @@ use parent 'Class::Accessor';
our $VERSION = '1.11';

Travel::Status::DE::EFA::Line->mk_ro_accessors(
	qw(direction name operator route type valid));
	qw(direction mot name operator route type valid));

my @mot_mapping = qw{
  zug s-bahn u-bahn stadtbahn tram stadtbus regionalbus
  schnellbus seilbahn schiff ast sonstige
};

sub new {
	my ( $obj, %conf ) = @_;
@@ -19,6 +24,12 @@ sub new {
	return bless( $ref, $obj );
}

sub mot_name {
	my ($self) = @_;

	return $mot_mapping[ $self->{mot} ] // 'sonstige';
}

sub TO_JSON {
	my ($self) = @_;

+12 −1
Original line number Diff line number Diff line
@@ -12,9 +12,14 @@ our $VERSION = '1.11';

Travel::Status::DE::EFA::Result->mk_ro_accessors(
	qw(countdown date delay destination is_cancelled info key line lineref
	  platform platform_db platform_name sched_date sched_time time type)
	  mot platform platform_db platform_name sched_date sched_time time type)
);

my @mot_mapping = qw{
  zug s-bahn u-bahn stadtbahn tram stadtbus regionalbus
  schnellbus seilbahn schiff ast sonstige
};

sub new {
	my ( $obj, %conf ) = @_;

@@ -31,6 +36,12 @@ sub new {
	return bless( $ref, $obj );
}

sub mot_name {
	my ($self) = @_;

	return $mot_mapping[ $self->{mot} ] // 'sonstige';
}

sub route_pre {
	my ($self) = @_;