Commit 765bf079 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add lookahead option

parent 822be4f5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
git HEAD

    * IRIS / db-iris: Add lookahead option

Travel::Status::DE::IRIS 0.02 - Mon Feb 03 2014

    * Fix warnings when encountering unplanned (fchg-only) trains without
+18 −3
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ use List::MoreUtils qw(none);
use Travel::Status::DE::IRIS;
use Travel::Status::DE::IRIS::Stations;

my ( $date, $time );
my ( $date, $time, $lookahead );
my $datetime = DateTime->now( time_zone => 'Europe/Berlin' );
my $realtime = 0;
my ( $filter_via, $track_via, $status_via );
@@ -34,6 +34,7 @@ GetOptions(
	'c|class=s@'    => \@grep_class,
	'd|date=s'      => \$date,
	'h|help'        => sub { show_help(0) },
	'l|lookahead=i' => \$lookahead,
	'o|output=s@'   => \@edata_pre,
	'p|platform=s@' => \@grep_platform,
	'r|realtime'    => \$realtime,
@@ -94,9 +95,13 @@ for my $efield (@edata_pre) {

my $status = Travel::Status::DE::IRIS->new(
	datetime  => $datetime,
	lookahead => $lookahead,
	station   => $station,
);
if ($track_via) {

	# lookahead should not be used here - the via stop is reached an unknown
	# amount of time later
	$status_via = Travel::Status::DE::IRIS->new(
		datetime => $datetime,
		station  => $track_via,
@@ -378,6 +383,16 @@ Request results for I<date> in dd.mm. oder dd.mm.YYYY format. Note that only
slight (a few hours max) deviations from the current time are supported by the
IRIS backend, larger ones will not return data.

=item B<-l>, B<--lookahead> I<int>

Return only those results which are less than I<int> minutes in the future.
Defaults to 240 (4 hours).

Note that this is only an upper limit, not a guarantee to get every train
with a departure in less than I<int> minutes. This guarantee holds only for
I<int> below 120. However, any non-negative number is accepted for this
option.

=item B<-o>, B<--output> I<outputtypes>

For each result, output I<outputtypes> in addition to the normal time, delay,
+15 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ sub new {
		  // DateTime->now( time_zone => 'Europe/Berlin' ),
		iris_base => $opt{iris_base}
		  // 'http://iris.noncd.db.de/iris-tts/timetable',
		lookahead => $opt{lookahead} // ( 4 * 60 ),
		station => $opt{station},
		user_agent => $ua,
	};
@@ -68,7 +69,7 @@ sub new {
		my $d
		  = ( $_->departure // $_->arrival )
		  ->subtract_datetime( $self->{datetime} );
		not $d->is_negative and $d->in_units('hours') < 4
		not $d->is_negative and $d->in_units('minutes') < $self->{lookahead}
	} @{ $self->{results} };

	@{ $self->{results} }
@@ -303,6 +304,18 @@ current date and time.

IRIS base url, defaults to C<< http://iris.noncd.db.de/iris-tts/timetable >>.

=item B<lookahead> => I<int>

Compute only those results which are less than I<int> minutes in the future.
Default: 240 (4 hours).

Note that the DeutscheBahn IRIS backend only provides schedules up to four
to five hours into the future, and this module only requests data for up to
three hours. So in most cases, setting this to a value above 180 minutes will
have no effect. However, as the IRIS occasionally contains unscheduled
departures or qos messages known far in advance (e.g. 12 hours from now), any
non-negative integer is accepted.

=item B<station> => I<stationcode>

Mandatory: Which station to return departures for. Note that this is not a
+19 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ use 5.014;
use utf8;

use DateTime;
use Test::More tests => 435;
use Test::More tests => 436;
use Test::Fatal;

use Travel::Status::DE::IRIS;
@@ -87,3 +87,21 @@ $status = Travel::Status::DE::IRIS->new(
@results = $status->results;

is(@results, 0, 'no data available -> empty result list');

$status = Travel::Status::DE::IRIS->new(
	iris_base => 'file:t/in',
	lookahead => 0,
	station   => 'EE',
	datetime  => DateTime->new(
		year      => 2014,
		month     => 1,
		day       => 3,
		hour      => 20,
		minute    => 1,
		time_zone => 'Europe/Berlin'
	)
);

@results = $status->results;

is(@results, 0, 'lookahead 0 -> no results');