summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/IRIS.pm41
-rw-r--r--lib/Travel/Status/DE/IRIS/Result.pm58
2 files changed, 87 insertions, 12 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index 95194ff..cea7d4a 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -101,6 +101,9 @@ sub new {
# references to each other. therefore, they must be processed last.
$self->create_wing_refs;
+ # same goes for replacement refs (the <ref> tag in the fchg document)
+ $self->create_replacement_refs;
+
return $self;
}
@@ -218,12 +221,12 @@ sub get_realtime {
my $station = ( $xml->findnodes('/timetable') )[0]->getAttribute('station');
for my $s ( $xml->findnodes('/timetable/s') ) {
- my $id = $s->getAttribute('id');
- my $e_tl = ( $s->findnodes('./tl') )[0];
- my $e_ar = ( $s->findnodes('./ar') )[0];
- my $e_dp = ( $s->findnodes('./dp') )[0];
- my $e_ref = ( $s->findnodes('./ref') )[0];
- my @e_ms = $s->findnodes('.//m');
+ my $id = $s->getAttribute('id');
+ my $e_tl = ( $s->findnodes('./tl') )[0];
+ my $e_ar = ( $s->findnodes('./ar') )[0];
+ my $e_dp = ( $s->findnodes('./dp') )[0];
+ my @e_refs = $s->findnodes('./ref/tl');
+ my @e_ms = $s->findnodes('.//m');
my %messages;
@@ -268,8 +271,8 @@ sub get_realtime {
unknown_o => $e_tl->getAttribute('o'), # owner: 03/80/R2/...
);
}
- if ($e_ref) {
- $result->set_ref(
+ for my $e_ref (@e_refs) {
+ $result->add_raw_ref(
class => $e_ref->getAttribute('f'), # D N S F
unknown_t => $e_ref->getAttribute('t'), # p
train_no => $e_ref->getAttribute('n'), # dep number
@@ -312,6 +315,14 @@ sub get_result_by_id {
return $res;
}
+sub get_result_by_train {
+ my ( $self, $type, $train_no ) = @_;
+
+ my $res = first { $_->type eq $type and $_->train_no eq $train_no }
+ @{ $self->{results} };
+ return $res;
+}
+
sub create_wing_refs {
my ($self) = @_;
@@ -336,6 +347,20 @@ sub create_wing_refs {
}
+sub create_replacement_refs {
+ my ($self) = @_;
+
+ for my $r ( $self->results ) {
+ for my $ref_hash ( @{ $r->{refs} // [] } ) {
+ my $ref = $self->get_result_by_train( $ref_hash->{type},
+ $ref_hash->{train_no} );
+ if ($ref) {
+ $r->add_reference($ref);
+ }
+ }
+ }
+}
+
sub errstr {
my ($self) = @_;
diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm
index ebcb5be..85ee1bf 100644
--- a/lib/Travel/Status/DE/IRIS/Result.pm
+++ b/lib/Travel/Status/DE/IRIS/Result.pm
@@ -96,8 +96,8 @@ my %translation = (
Travel::Status::DE::IRIS::Result->mk_ro_accessors(
qw(arrival classes date datetime delay departure is_cancelled is_transfer
- is_unscheduled is_wing line_no old_train_id
- old_train_no platform raw_id realtime_xml route_start route_end
+ is_unscheduled is_wing line_no old_train_id old_train_no platform raw_id
+ realtime_xml route_start route_end
sched_arrival sched_departure sched_platform sched_route_start
sched_route_end start stop_no time train_id train_no transfer type
unknown_t unknown_o wing_id)
@@ -309,10 +309,10 @@ sub set_realtime {
return $self;
}
-sub set_ref {
+sub add_raw_ref {
my ( $self, %attrib ) = @_;
- # TODO
+ push( @{ $self->{refs} }, \%attrib );
return $self;
}
@@ -337,6 +337,7 @@ sub add_arrival_wingref {
$ref->{is_wing} = 1;
weaken($ref);
push( @{ $self->{arrival_wings} }, $ref );
+ return $self;
}
sub add_departure_wingref {
@@ -345,6 +346,25 @@ sub add_departure_wingref {
$ref->{is_wing} = 1;
weaken($ref);
push( @{ $self->{departure_wings} }, $ref );
+ return $self;
+}
+
+sub add_reference {
+ my ( $self, $ref ) = @_;
+
+ $ref->add_inverse_reference($self);
+ weaken($ref);
+ push( @{ $self->{replacement_for} }, $ref );
+ return $self;
+}
+
+# never called externally
+sub add_inverse_reference {
+ my ( $self, $ref ) = @_;
+
+ weaken($ref);
+ push( @{ $self->{replaced_by} }, $ref );
+ return $self;
}
# List::Compare does not keep the order of its arguments (even with unsorted).
@@ -476,6 +496,24 @@ sub departure_wings {
return;
}
+sub replaced_by {
+ my ($self) = @_;
+
+ if ( $self->{replaced_by} ) {
+ return @{ $self->{replaced_by} };
+ }
+ return;
+}
+
+sub replacement_for {
+ my ($self) = @_;
+
+ if ( $self->{replacement_for} ) {
+ return @{ $self->{replacement_for} };
+ }
+ return;
+}
+
sub dump_message_codes {
my ($self) = @_;
@@ -912,6 +950,18 @@ available.
This is a developer option. It may be removed without prior warning.
+=item $result->replaced_by
+
+Returns a list of references to Travel::Status::DE::IRIS::Result(3pm) objects
+which replace the (usually cancelled) arrival/departure of this train.
+Returns nothing (false / empty list) otherwise.
+
+=item $result->replacement_for
+
+Returns a list of references to Travel::Status::DE::IRIS::Result(3pm) objects
+which this (usually unplanned) train is meant to replace.
+Returns nothing (false / empty list) otherwise.
+
=item $result->route
List of all stations served by this train, according to its schedule. Does