Skip to content

Commit

Permalink
Route/Part, efa: Expose via delays
Browse files Browse the repository at this point in the history
  • Loading branch information
derf committed Nov 22, 2023
1 parent 10acec3 commit 30eff16
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
21 changes: 16 additions & 5 deletions bin/efa
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,22 @@ sub format_footpath {
return $str;
}

sub format_delay {
sub format_delay_incl {
my ( $delay, $len ) = @_;
if ( $delay and $len ) {
return sprintf( "(%+${len}d)", $delay );
}
return q{};
}

sub format_delay_excl {
my ( $delay, $len ) = @_;
if ( $delay and $len ) {
return sprintf( " %+${len}d ", $delay );
}
return q{};
}

sub display_routes {
my (@routes) = @_;

Expand Down Expand Up @@ -269,21 +277,24 @@ sub display_connection {
printf(
"%-5s %-${delay_fmt}s ab %-30s\n",
$c->departure_time,
format_delay( $c->departure_delay, $delay_len ),
format_delay_incl( $c->departure_delay, $delay_len ),
$c->departure_stop_and_platform,
);

if ( $opt->{'full-route'} ) {
for my $via_stop ( $c->via ) {
printf( "%-5s %-${delay_fmt}s %-30s %s\n",
$via_stop->[1], q{}, $via_stop->[2], $via_stop->[3] );
printf(
"%-5s %-${delay_fmt}s %-30s %s\n",
$via_stop->[1], format_delay_excl( $via_stop->[4], $delay_len ),
$via_stop->[2], $via_stop->[3]
);
}
}

printf(
"%-5s %-${delay_fmt}s an %-30s %s\n",
$c->arrival_time,
format_delay( $c->arrival_delay, $delay_len ),
format_delay_incl( $c->arrival_delay, $delay_len ),
$c->arrival_stop_and_platform, $occupancy
);

Expand Down
8 changes: 5 additions & 3 deletions lib/Travel/Routing/DE/EFA.pm
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,9 @@ sub parse_xml_part {
next;
}

my $name = $ve->getAttribute('name');
my $platform = $ve->getAttribute('platformName');
my $name = $ve->getAttribute('name');
my $platform = $ve->getAttribute('platformName');
my $arr_delay = $ve->getAttribute('arrDelay');

if ( $name eq $hash->{departure_stop}
or $name eq $hash->{arrival_stop} )
Expand All @@ -741,7 +742,8 @@ sub parse_xml_part {
$self->itddate_str($e_vdate),
$self->itdtime_str($e_vtime),
$name,
$platform
$platform,
$arr_delay,
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion t/21-vrr.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ is( $c0->arrival_time, '14:02', 'r0,0: artime' );
is( $c0->arrival_stime, '14:02', 'r0,0: astime' );

is_deeply( ($c0->via)[0],
['27.11.2011', '13:56', 'Essen Florastr.', 'Bstg. 1'],
['27.11.2011', '13:56', 'Essen Florastr.', 'Bstg. 1', undef],
'r0,0: via[0]');

is( $c1->delay, 3, 'r0,1: delay' );
Expand Down

0 comments on commit 30eff16

Please sign in to comment.