summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/db-iris16
-rw-r--r--lib/Travel/Status/DE/IRIS/Result.pm30
2 files changed, 39 insertions, 7 deletions
diff --git a/bin/db-iris b/bin/db-iris
index 530af08..8e5909a 100755
--- a/bin/db-iris
+++ b/bin/db-iris
@@ -75,6 +75,7 @@ if ($time) {
for my $efield (@edata_pre) {
given ($efield) {
when ('d') { $edata{delay} = 1 }
+ when ('D') { $edata{delays} = 1 }
when ('f') { $edata{fullroute} = 1 }
when ('m') { $edata{messages} = 1 }
when ('q') { $edata{qos} = 1 }
@@ -141,12 +142,17 @@ sub display_result {
for my $line (@lines) {
printf(
- join( q{ }, ( map { "%-${_}s" } @line_length ) ) . "\n",
+ join( q{ }, ( map { "%-${_}s" } @line_length ) ),
@{$line}[ 0 .. 4 ]
);
my $d = $line->[5];
+ if ( $edata{delay} and $d->delay and $d->delay_messages ) {
+ printf( ' %s', ( $d->delay_messages )[-1]->[1] );
+ }
+ print "\n";
+
if ( $edata{times} ) {
if ( not defined $d->delay ) {
print "\n";
@@ -293,8 +299,12 @@ Valid output types are:
=item d / delay
-List all delay reasons entered into the IRIS, even if the train is on time
-by now.
+If a train is delayed, show the most recent reason for this delay.
+
+=item d / delays
+
+List all delay reasons entered into the IRIS for each train, even if the
+particular train is on time by now.
=item f / fullroute
diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm
index c3dd8aa..58a3a99 100644
--- a/lib/Travel/Status/DE/IRIS/Result.pm
+++ b/lib/Travel/Status/DE/IRIS/Result.pm
@@ -173,6 +173,25 @@ sub destination {
return $self->route_end;
}
+sub delay_messages {
+ my ($self) = @_;
+
+ my $strp = DateTime::Format::Strptime->new(
+ pattern => '%y%m%d%H%M',
+ time_zone => 'Europe/Berlin',
+ );
+
+ my @keys = sort keys %{ $self->{messages} };
+ my @msgs
+ = uniq( grep { $_->[1] eq 'd' } map { $self->{messages}{$_} } @keys );
+
+ my @ret = map {
+ [ $strp->parse_datetime( $_->[0] ), $self->translate_msg( $_->[2] ) ]
+ } @msgs;
+
+ return @ret;
+}
+
sub messages {
my ($self) = @_;
@@ -181,10 +200,13 @@ sub messages {
time_zone => 'Europe/Berlin',
);
- my @messages = sort keys %{ $self->{messages } };
- my @ret = map { [ $strp->parse_datetime($self->{messages}->{$_}->[0]),
- $self->translate_msg($self->{messages}->{$_}->[2]) ] }
- @messages;
+ my @messages = sort keys %{ $self->{messages} };
+ my @ret = map {
+ [
+ $strp->parse_datetime( $self->{messages}->{$_}->[0] ),
+ $self->translate_msg( $self->{messages}->{$_}->[2] )
+ ]
+ } @messages;
return @ret;
}