summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2014-02-06 19:13:35 +0100
committerDaniel Friesel <derf@finalrewind.org>2014-02-06 19:13:35 +0100
commit765bf0794a92522d13b75ced092ab0cfd8cdbf64 (patch)
tree8b12e123f4fffac8c9f1231dc30a8688224c49df
parent822be4f5957a5f34a4542cfdf92c350953340151 (diff)
add lookahead option
-rw-r--r--Changelog4
-rwxr-xr-xbin/db-iris21
-rw-r--r--lib/Travel/Status/DE/IRIS.pm17
-rw-r--r--t/31-result-basics.t20
4 files changed, 56 insertions, 6 deletions
diff --git a/Changelog b/Changelog
index 80a0c25..f7c5d33 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
+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
diff --git a/bin/db-iris b/bin/db-iris
index 35ef783..75aec37 100755
--- a/bin/db-iris
+++ b/bin/db-iris
@@ -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,
@@ -93,10 +94,14 @@ for my $efield (@edata_pre) {
}
my $status = Travel::Status::DE::IRIS->new(
- datetime => $datetime,
- station => $station,
+ 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,
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index 2d4d068..03aa89c 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -30,7 +30,8 @@ sub new {
// DateTime->now( time_zone => 'Europe/Berlin' ),
iris_base => $opt{iris_base}
// 'http://iris.noncd.db.de/iris-tts/timetable',
- station => $opt{station},
+ 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
diff --git a/t/31-result-basics.t b/t/31-result-basics.t
index 9a76e91..7f9423b 100644
--- a/t/31-result-basics.t
+++ b/t/31-result-basics.t
@@ -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');