summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-06-03 08:51:33 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-06-03 08:51:33 +0200
commit98c8f19f1996ec3ef7b6bdf2f84a7f04e1982248 (patch)
tree3446e67acac5c5ab1b50318261a28b9a75738f10 /lib/Travel
parent46fbe0aef7b81bbc80a081101e97cadf5968963d (diff)
implement experimental full-route feature
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/EFA.pm46
-rw-r--r--lib/Travel/Status/DE/EFA/Result.pm12
2 files changed, 58 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm
index 76b87f2..38a4fa8 100644
--- a/lib/Travel/Status/DE/EFA.pm
+++ b/lib/Travel/Status/DE/EFA.pm
@@ -110,6 +110,7 @@ sub new {
if ( $opt{full_routes} ) {
$self->{post}->{depType} = 'stopEvents';
$self->{post}->{includeCompleteStopSeq} = 1;
+ $self->{want_full_routes} = 1;
}
bless( $self, $class );
@@ -292,6 +293,35 @@ sub lines {
return @lines;
}
+sub parse_route {
+ my ( $self, @nodes ) = @_;
+ my $xp_routepoint_date
+ = XML::LibXML::XPathExpression->new('./itdDateTime/itdDate');
+ my $xp_routepoint_time
+ = XML::LibXML::XPathExpression->new('./itdDateTime/itdTime');
+
+ my @ret;
+
+ for my $e (@nodes) {
+ my @dates = $e->findnodes($xp_routepoint_date);
+ my @times = $e->findnodes($xp_routepoint_time);
+
+ push(
+ @ret,
+ {
+ arr_date => sprintf_date( $dates[0] ),
+ arr_time => sprintf_time( $times[0] ),
+ dep_date => sprintf_date( $dates[-1] ),
+ dep_time => sprintf_time( $times[-1] ),
+ stop => decode( 'UTF-8', $e->getAttribute('name') ),
+ platform => $e->getAttribute('platformName'),
+ }
+ );
+ }
+
+ return @ret;
+}
+
sub results {
my ($self) = @_;
my @results;
@@ -309,6 +339,10 @@ sub results {
my $xp_line = XML::LibXML::XPathExpression->new('./itdServingLine');
my $xp_info
= XML::LibXML::XPathExpression->new('./itdServingLine/itdNoTrain');
+ my $xp_prev_route
+ = XML::LibXML::XPathExpression->new('./itdPrevStopSeq/itdPoint');
+ my $xp_next_route
+ = XML::LibXML::XPathExpression->new('./itdOnwardStopSeq/itdPoint');
if ( $self->{results} ) {
return @{ $self->{results} };
@@ -349,6 +383,16 @@ sub results {
my $platform_is_db = 0;
+ my @prev_route;
+ my @next_route;
+
+ if ( $self->{want_full_routes} ) {
+ @prev_route
+ = $self->parse_route( @{ [ $e->findnodes($xp_prev_route) ] } );
+ @next_route
+ = $self->parse_route( @{ [ $e->findnodes($xp_next_route) ] } );
+ }
+
my @line_obj
= grep { $_->{identifier} eq $e_line->getAttribute('stateless') }
@{ $self->{lines} };
@@ -395,6 +439,8 @@ sub results {
sched_date => $date,
sched_time => $time,
type => $type,
+ prev_route => \@prev_route,
+ next_route => \@next_route,
)
);
}
diff --git a/lib/Travel/Status/DE/EFA/Result.pm b/lib/Travel/Status/DE/EFA/Result.pm
index 95e35cd..f729034 100644
--- a/lib/Travel/Status/DE/EFA/Result.pm
+++ b/lib/Travel/Status/DE/EFA/Result.pm
@@ -29,6 +29,18 @@ sub new {
return bless( $ref, $obj );
}
+sub route_pre {
+ my ($self) = @_;
+
+ return @{ $self->{prev_route} };
+}
+
+sub route_post {
+ my ($self) = @_;
+
+ return @{ $self->{next_route} };
+}
+
sub TO_JSON {
my ($self) = @_;