diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-12-15 13:37:06 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-12-15 13:37:06 +0100 |
commit | 60f287aa9abfef8a3649c395615b854c08effef0 (patch) | |
tree | 585e76610c59dbd395b7726cb91e42682caefa0f /lib/Travel/Status | |
parent | 2a434fe71ea9c9d4a3b43eb52b8a39701a252505 (diff) |
add keep_transfers option
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r-- | lib/Travel/Status/DE/IRIS.pm | 67 | ||||
-rw-r--r-- | lib/Travel/Status/DE/IRIS/Result.pm | 2 |
2 files changed, 48 insertions, 21 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index f21a839..9c5cb31 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -44,10 +44,11 @@ sub new { developer_mode => $opt{developer_mode}, iris_base => $opt{iris_base} // 'https://iris.noncd.db.de/iris-tts/timetable', - lookahead => $opt{lookahead} // ( 2 * 60 ), - lookbehind => $opt{lookbehind} // ( 0 * 60 ), - main_cache => $opt{main_cache}, - rt_cache => $opt{realtime_cache}, + keep_transfers => $opt{keep_transfers}, + lookahead => $opt{lookahead} // ( 2 * 60 ), + lookbehind => $opt{lookbehind} // ( 0 * 60 ), + main_cache => $opt{main_cache}, + rt_cache => $opt{realtime_cache}, serializable => $opt{serializable}, user_agent => $opt{user_agent}, with_related => $opt{with_related}, @@ -83,6 +84,7 @@ sub new { my $ref_status = Travel::Status::DE::IRIS->new( datetime => $self->{datetime}, developer_mode => $self->{developer_mode}, + keep_transfers => $self->{keep_transfers}, lookahead => $self->{lookahead}, lookbehind => $self->{lookbehind}, station => $ref->{uic}, @@ -124,22 +126,26 @@ sub new { $self->get_realtime; - # tra (transfer?) indicates a train changing its ID, so there are two - # results for the same train. Remove the departure-only trains from the - # result set and merge them with their arrival-only counterpart. - # This way, in case the arrival is available but the departure isn't, - # nothing gets lost. - my @merge_candidates - = grep { $_->transfer and $_->departure } @{ $self->{results} }; - @{ $self->{results} } - = grep { not( $_->transfer and $_->departure ) } @{ $self->{results} }; - - for my $transfer (@merge_candidates) { - my $result - = first { $_->transfer and $_->transfer eq $transfer->train_id } - @{ $self->{results} }; - if ($result) { - $result->merge_with_departure($transfer); + if ( not $self->{keep_transfers} ) { + + # tra (transfer?) indicates a train changing its ID, so there are two + # results for the same train. Remove the departure-only trains from the + # result set and merge them with their arrival-only counterpart. + # This way, in case the arrival is available but the departure isn't, + # nothing gets lost. + my @merge_candidates + = grep { $_->transfer and $_->departure } @{ $self->{results} }; + @{ $self->{results} } + = grep { not( $_->transfer and $_->departure ) } + @{ $self->{results} }; + + for my $transfer (@merge_candidates) { + my $result + = first { $_->transfer and $_->transfer eq $transfer->train_id } + @{ $self->{results} }; + if ($result) { + $result->merge_with_departure($transfer); + } } } @@ -654,6 +660,27 @@ current date and time. IRIS base url, defaults to C<< http://iris.noncd.db.de/iris-tts/timetable >>. +=item B<keep_transfers> => I<bool> + +A train may change its ID and number at a station, indicating that although the +previous logical train ends here, the physical train will continue its journey +under a new number to a new destination. A notable example is the Berlin +Ringbahn, which travels round and round from Berlin SE<uuml>dkreuz to Berlin +SE<uuml>dkreuz. Each train number corresponds to a single revolution, but the +actual trains just keep going. + +The IRIS backend returns two results for each transfer train: An arrival-only +result using the old ID (linked to the new one) and a departure-only result +using the new ID (linked to the old one). By default, this library merges these +into a single result with both arrival and departure time. Train number, ID, +and route are taken from the departure only. The original train ID and number +are available using the B<old_train_id> and B<old_train_no> accessors. + +In case this is not desirable (e.g. because you intend to track a single +train to its destination station and do not want to implement special cases +for transfer trains), set B<keep_transfers> to a true value. In this case, +backend data will be reported as-is and transfer trains will not be merged. + =item B<lookahead> => I<int> Compute only results which are scheduled less than I<int> minutes in the diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm index e871420..0dc03a2 100644 --- a/lib/Travel/Status/DE/IRIS/Result.pm +++ b/lib/Travel/Status/DE/IRIS/Result.pm @@ -1013,7 +1013,7 @@ see also B<is_transfer>. =item $result->old_train_no Number of the pre-tarnsfer train, unique per day. E.g. C<< 2225 >> for -C<< IC 2225 >>. See also B<is_transfer>. Only defined if a transfer took +C<< IC 2225 >>. Only defined if a transfer took place, see also B<is_transfer>. =item $result->origin |