From 7e8258ae6c0cb53cdde02cf48f506eb9f7a29660 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 29 Nov 2011 14:41:18 +0100 Subject: Fix display and parsing of delay connections --- bin/efa | 58 ++++++++++++++++++++------------- lib/Travel/Routing/DE/VRR.pm | 41 +++++++++++++++-------- lib/Travel/Routing/DE/VRR/Route/Part.pm | 13 +++++--- 3 files changed, 72 insertions(+), 40 deletions(-) diff --git a/bin/efa b/bin/efa index 1844102..24026a3 100755 --- a/bin/efa +++ b/bin/efa @@ -105,6 +105,40 @@ sub check_for_error { return; } +sub display_connection { + my ($c) = @_; + + if ( $c->delay ) { + printf( "# +%d, scheduled: %s -> %s\n", + $c->delay, $c->departure_stime, $c->arrival_stime ); + } + + for my $extra ( $c->extra ) { + + if ( not( length $ignore_info and $extra =~ /$ignore_info/i ) ) { + say "# $extra"; + } + } + + printf( + "%-5s ab %-30s %-20s %s\n", + $c->departure_time, $c->departure_stop_and_platform, + $c->train_line, $c->train_destination, + ); + + if ( $opt->{'extended-info'} and $opt->{'extended-info'} == 2 ) { + for my $via ( @{ $c->{via} } ) { + printf( "%-5s %-22s %s\n", @{$via}[ 1 .. 3 ] ); + } + } + + printf( "%-5s an %s\n\n", + $c->arrival_time, $c->arrival_stop_and_platform, + ); + + return; +} + #<<< GetOptions( $opt, @@ -206,29 +240,7 @@ for my $i ( 0 .. $#routes ) { } for my $c ( $route->parts ) { - - for my $extra ( $c->extra ) { - - if ( not( length $ignore_info and $extra =~ /$ignore_info/i ) ) { - say "# $extra"; - } - } - - printf( - "%-5s ab %-30s %-20s %s\n", - $c->departure_time, $c->departure_stop_and_platform, - $c->train_line, $c->train_destination, - ); - - if ( $opt->{'extended-info'} and $opt->{'extended-info'} == 2 ) { - for my $via ( @{ $c->{via} } ) { - printf( "%-5s %-22s %s\n", @{$via}[ 1 .. 3 ] ); - } - } - - printf( "%-5s an %s\n\n", - $c->arrival_time, $c->arrival_stop_and_platform, - ); + display_connection($c); } if ( $i != $#routes ) { print "------\n\n"; diff --git a/lib/Travel/Routing/DE/VRR.pm b/lib/Travel/Routing/DE/VRR.pm index 713fb10..56aa28e 100644 --- a/lib/Travel/Routing/DE/VRR.pm +++ b/lib/Travel/Routing/DE/VRR.pm @@ -445,9 +445,12 @@ sub parse_part { my $xp_time = XML::LibXML::XPathExpression->new('./itdDateTime/itdTime'); my $xp_via = XML::LibXML::XPathExpression->new('./itdStopSeq/itdPoint'); -# my $xp_tdate = XML::LibXML::XPathExpression->new('./itdDateTimeTarget/itdDate'); -# my $xp_ttime = XML::LibXML::XPathExpression->new('./itdDateTimeTarget/itdTime'); - my $xp_mot = XML::LibXML::XPathExpression->new('./itdMeansOfTransport'); + my $xp_sdate + = XML::LibXML::XPathExpression->new('./itdDateTimeTarget/itdDate'); + my $xp_stime + = XML::LibXML::XPathExpression->new('./itdDateTimeTarget/itdTime'); + my $xp_mot = XML::LibXML::XPathExpression->new('./itdMeansOfTransport'); + my $xp_delay = XML::LibXML::XPathExpression->new('./itdRBLControlled'); my $xp_info = XML::LibXML::XPathExpression->new('./itdInfoTextList/infoTextListElem'); @@ -472,24 +475,36 @@ sub parse_part { for my $e ( $route->findnodes($xp_route) ) { - my $e_dep = ( $e->findnodes($xp_dep) )[0]; - my $e_arr = ( $e->findnodes($xp_arr) )[0]; - my $e_ddate = ( $e_dep->findnodes($xp_date) )[0]; - my $e_dtime = ( $e_dep->findnodes($xp_time) )[0]; - my $e_adate = ( $e_arr->findnodes($xp_date) )[0]; - my $e_atime = ( $e_arr->findnodes($xp_time) )[0]; - my $e_mot = ( $e->findnodes($xp_mot) )[0]; - my @e_info = $e->findnodes($xp_info); + my $e_dep = ( $e->findnodes($xp_dep) )[0]; + my $e_arr = ( $e->findnodes($xp_arr) )[0]; + my $e_ddate = ( $e_dep->findnodes($xp_date) )[0]; + my $e_dtime = ( $e_dep->findnodes($xp_time) )[0]; + my $e_dsdate = ( $e_dep->findnodes($xp_sdate) )[0]; + my $e_dstime = ( $e_dep->findnodes($xp_stime) )[0]; + my $e_adate = ( $e_arr->findnodes($xp_date) )[0]; + my $e_atime = ( $e_arr->findnodes($xp_time) )[0]; + my $e_asdate = ( $e_arr->findnodes($xp_sdate) )[0]; + my $e_astime = ( $e_arr->findnodes($xp_stime) )[0]; + my $e_mot = ( $e->findnodes($xp_mot) )[0]; + my $e_delay = ( $e->findnodes($xp_delay) )[0]; + my @e_info = $e->findnodes($xp_info); + + my $delay = $e_delay ? $e_delay->getAttribute('delayMinutes') : 0; my $hash = { - departure_time => $self->itdtime_str($e_dtime), + delay => $delay, departure_date => $self->itddate_str($e_ddate), + departure_time => $self->itdtime_str($e_dtime), + departure_sdate => $self->itddate_str($e_dsdate), + departure_stime => $self->itdtime_str($e_dstime), departure_stop => $e_dep->getAttribute('name'), departure_platform => $e_dep->getAttribute('platformName'), train_line => $e_mot->getAttribute('name'), train_destination => $e_mot->getAttribute('destination'), - arrival_time => $self->itdtime_str($e_atime), arrival_date => $self->itddate_str($e_adate), + arrival_time => $self->itdtime_str($e_atime), + arrival_sdate => $self->itddate_str($e_asdate), + arrival_stime => $self->itdtime_str($e_astime), arrival_stop => $e_arr->getAttribute('name'), arrival_platform => $e_arr->getAttribute('platformName'), }; diff --git a/lib/Travel/Routing/DE/VRR/Route/Part.pm b/lib/Travel/Routing/DE/VRR/Route/Part.pm index d01260c..e31e713 100644 --- a/lib/Travel/Routing/DE/VRR/Route/Part.pm +++ b/lib/Travel/Routing/DE/VRR/Route/Part.pm @@ -9,8 +9,12 @@ use parent 'Class::Accessor'; our $VERSION = '1.06'; Travel::Routing::DE::VRR::Route::Part->mk_ro_accessors( - qw(arrival_platform arrival_stop arrival_time departure_platform departure_stop departure_time train_line - train_destination) + qw(arrival_platform arrival_stop + arrival_date arrival_time arrival_sdate arrival_stime + delay departure_platform departure_stop + departure_date departure_time departure_sdate departure_stime + train_line train_destination + ) ); sub new { @@ -24,13 +28,14 @@ sub new { sub arrival_stop_and_platform { my ($self) = @_; - return sprintf('%s: %s', $self->get(qw(arrival_stop arrival_platform))); + return sprintf( '%s: %s', $self->get(qw(arrival_stop arrival_platform)) ); } sub departure_stop_and_platform { my ($self) = @_; - return sprintf('%s: %s', $self->get(qw(departure_stop departure_platform))); + return + sprintf( '%s: %s', $self->get(qw(departure_stop departure_platform)) ); } sub extra { -- cgit v1.2.3