Skip to content
Travel::Status::DE::DeutscheBahn 5.06 - Thu Mar 28 2024
* Add Travel::Status::DE::HAFAS::Product module to handle line numbers,
operators, and similar. This enables proper support for journeys with
multiple operators and possibly multiple train/line numbers along the
route. It also exposes the line ID.
* Journey: Add product accessor
* Stop: Add prod_arr, prod_dep accessors
* hafas-m: Improve stop list display in journey mode
* Fix polyline and platform number support in ÖBB backend (and possibly
other non-DB backends)
* ÖBB backend: correctly handle polylines and platform numbers
* ÖBB backend: Remove redundant train numbers from $journey->name /
$journey->line / $product->name
* ÖBB backend: update productbits (thanks to Cassidy Dingenskirchen)
Travel::Status::DE::DeutscheBahn 5.05 - Wed Feb 21 2024
* ÖBB backend: handle midnight crossing and fix associated warnings
......
......@@ -3,7 +3,7 @@ use strict;
use warnings;
use 5.014;
our $VERSION = '5.05';
our $VERSION = '5.06';
use utf8;
use DateTime;
......@@ -148,8 +148,12 @@ sub show_version {
exit 0;
}
sub parse_mot_options {
sub spacer {
my ($len) = @_;
return ( $len % 2 ? q { } : q{} ) . ( q{ ·} x ( $len / 2 ) );
}
sub parse_mot_options {
my $default_yes = 1;
for my $type ( split( qr{,}, $types ) ) {
......@@ -385,6 +389,7 @@ elsif ( $opt{locationSearch} ) {
elsif ( $opt{journey} ) {
my $result = $status->result;
my @prods;
my @directions;
my $prev_prod = 0;
printf( "%s → %s", $result->name, $result->route_end );
......@@ -400,6 +405,7 @@ elsif ( $opt{journey} ) {
my $delay_len = 0;
my $delay_fmt = 0;
my $occupancy_len = 0;
my $stop_len = 0;
for my $stop ( $result->route ) {
if ( $stop->delay ) {
$delay_len = max( $delay_len, length( $stop->delay ) + 1 );
......@@ -408,21 +414,33 @@ elsif ( $opt{journey} ) {
{
$occupancy_len = 2;
}
if ( length( $stop->loc->name ) > $stop_len ) {
$stop_len = length( $stop->loc->name );
}
my $prod = $stop->prod_dep // $stop->prod_arr;
if ( $prod and $prod != $prev_prod ) {
push( @prods, $prod );
$prev_prod = $prod;
}
if ( $stop->direction ) {
push( @directions, $stop->direction );
}
}
if ($delay_len) {
$delay_fmt = $delay_len + 3;
}
if ( @prods == 1 ) {
printf( "Betrieb: %s\n\n", $prev_prod->operator );
if ( $prev_prod->operator ) {
printf( "Betrieb: %s\n", $prev_prod->operator );
}
}
else {
printf( "Betrieb: %s\n\n", join( q{, }, map { $_->operator } @prods ) );
printf(
"Betrieb: %s\n",
join( q{, },
uniq map { $_->operator } grep { $_->operator } @prods )
);
}
$prev_prod = 0;
......@@ -441,6 +459,7 @@ elsif ( $opt{journey} ) {
my $message_id = 1;
print "\n";
for my $stop ( $result->route ) {
my $msg_line = q{};
for my $message ( $stop->messages ) {
......@@ -461,13 +480,18 @@ elsif ( $opt{journey} ) {
my $prod = $stop->prod_dep // $stop->prod_arr;
if ( $prod and $prod != $prev_prod ) {
$prod_line
= sprintf( " : %s (%s)", $prod->name, $prod->operator );
= sprintf( " %s (%s)", $prod->name, $prod->operator );
$prev_prod = $prod;
}
}
my $dir_line = q{};
if ( @directions > 1 and $stop->direction ) {
$dir_line = '' . $stop->direction;
}
printf(
"%s%5s %s %5s %-${delay_fmt}s%${occupancy_len}s%-${occupancy_len}s %s%s%s%s%s\n",
"%s%5s %s %5s %-${delay_fmt}s%${occupancy_len}s%-${occupancy_len}s %s%s%s%s%s%s\n",
$stop == $mark_stop ? $output_bold : q{},
$stop->arr_cancelled ? '--:--'
: ( $stop->arr ? $stop->arr->strftime('%H:%M') : q{} ),
......@@ -481,8 +505,11 @@ elsif ( $opt{journey} ) {
: q{},
$stop->loc->name,
$stop == $mark_stop ? $output_reset : q{},
( $prod_line or $dir_line or $msg_line )
? spacer( $stop_len + 1 - length( $stop->loc->name ) )
: q{},
$prod_line,
$stop->direction ? sprintf( ' → %s', $stop->direction ) : q{},
$dir_line,
$msg_line,
);
}
......@@ -614,7 +641,7 @@ B<hafas-m> [B<-s> I<service>] [B<-l> I<language>] B<!>I<query>|I<journeyID>
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......
......@@ -6,7 +6,7 @@ use 5.014;
use parent 'Travel::Status::DE::HAFAS';
our $VERSION = '5.05';
our $VERSION = '5.06';
sub new {
my ( $class, %opt ) = @_;
......@@ -49,7 +49,7 @@ monitor operated by Deutsche Bahn
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......
......@@ -21,7 +21,7 @@ use Travel::Status::DE::HAFAS::Polyline qw(decode_polyline);
use Travel::Status::DE::HAFAS::Product;
use Travel::Status::DE::HAFAS::StopFinder;
our $VERSION = '5.05';
our $VERSION = '5.06';
# {{{ Endpoint Definition
......@@ -752,9 +752,17 @@ sub parse_journey {
my $journey = $self->{raw_json}{svcResL}[0]{res}{journey};
my @polyline;
if ( $journey->{poly} ) {
@polyline = decode_polyline( $journey->{poly}{crdEncYX} );
for my $ref ( @{ $journey->{poly}{ppLocRefL} // [] } ) {
my $poly = $journey->{poly};
# ÖBB
if ( $journey->{polyG} and @{ $journey->{polyG}{polyXL} // [] } ) {
$poly = $self->{raw_json}{svcResL}[0]{res}{common}{polyL}
[ $journey->{polyG}{polyXL}[0] ];
}
if ($poly) {
@polyline = decode_polyline( $poly->{crdEncYX} );
for my $ref ( @{ $poly->{ppLocRefL} // [] } ) {
my $poly = $polyline[ $ref->{ppIdx} ];
my $loc = $locL[ $ref->{locX} ];
......@@ -1017,7 +1025,7 @@ monitors
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......@@ -1206,8 +1214,9 @@ If no result was found or the parser / http request failed, returns undef.
=item $status->messages
Returns a list of Travel::Status::DE::HAFAS::Message(3pm) objects with
service messages. Each message belongs to at least one arrival/departure.
Returns a list of Travel::Status::DE::HAFAS::Message(3pm) objects with service
messages. Each message belongs to at least one arrival/departure (station,
journey) or to at least stop alongside its route (journey).
=item $status->station
......@@ -1294,11 +1303,25 @@ The non-default services (anything other than DB) are not well tested.
=head1 SEE ALSO
Travel::Status::DE::HAFAS::Journey(3pm), Travel::Status::DE::HAFAS::StopFinder(3pm).
=over
=item * Travel::Status::DE::HAFAS::Journey(3pm)
=item * Travel::Status::DE::HAFAS::Location(3pm)
=item * Travel::Status::DE::HAFAS::Message(3pm)
=item * Travel::Status::DE::HAFAS::Product(3pm)
=item * Travel::Status::DE::HAFAS::StopFinder(3pm)
=item * Travel::Status::DE::HAFAS::Stop(3pm)
=back
=head1 AUTHOR
Copyright (C) 2015-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
Copyright (C) 2015-2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
=head1 LICENSE
......
......@@ -11,12 +11,13 @@ use DateTime::Format::Strptime;
use List::Util qw(any);
use Travel::Status::DE::HAFAS::Stop;
our $VERSION = '5.05';
our $VERSION = '5.06';
Travel::Status::DE::HAFAS::Journey->mk_ro_accessors(
qw(datetime sched_datetime rt_datetime
is_additional is_cancelled is_partially_cancelled
station station_eva platform sched_platform rt_platform operator
product
id name type type_long class number line line_no load delay
route_end route_start origin destination direction)
);
......@@ -166,9 +167,11 @@ sub new {
if ( $journey->{stbStop} ) {
$ref->{station} = $locL->[ $journey->{stbStop}{locX} ]->name;
$ref->{station_eva} = 0 + $locL->[ $journey->{stbStop}{locX} ]->eva;
$ref->{sched_platform} = $journey->{stbStop}{dPlatfS};
$ref->{rt_platform} = $journey->{stbStop}{dPlatfR};
$ref->{platform} = $ref->{rt_platform} // $ref->{sched_platform};
$ref->{sched_platform} = $journey->{stbStop}{dPlatfS}
// $journey->{stbStop}{dPltfS}{txt};
$ref->{rt_platform} = $journey->{stbStop}{dPlatfR}
// $journey->{stbStop}{dPltfR}{txt};
$ref->{platform} = $ref->{rt_platform} // $ref->{sched_platform};
my $time_s
= $journey->{stbStop}{ $hafas->{arrivals} ? 'aTimeS' : 'dTimeS' };
......@@ -392,7 +395,7 @@ journey received by Travel::Status::DE::HAFAS
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......@@ -487,6 +490,13 @@ True if the journey was cancelled, false otherwise.
True if part of the journey was cancelled, false otherwise.
=item $journey->product
Travel::Status::DE::HAFAS::Product(3pm) instance describing the product (mode
of transport, line number / ID, operator, ...) associated with this journey.
Note that journeys may be associated with multiple products -- see also
C<< $journey->route >> and C<< $stop->product >>.
=item $journey->rt_platform (station only)
Actual arrival/departure platform.
......
......@@ -6,7 +6,7 @@ use 5.014;
use parent 'Class::Accessor';
our $VERSION = '5.05';
our $VERSION = '5.06';
Travel::Status::DE::HAFAS::Location->mk_ro_accessors(
qw(lid type name eva state lat lon distance_m weight));
......@@ -57,7 +57,7 @@ Travel::Status::DE::HAFAS::Location - A single public transit location
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......
......@@ -6,7 +6,7 @@ use 5.014;
use parent 'Class::Accessor';
our $VERSION = '5.05';
our $VERSION = '5.06';
Travel::Status::DE::HAFAS::Message->mk_ro_accessors(
qw(short type text code prio is_him ref_count));
......@@ -69,7 +69,7 @@ Travel::Status::DE::HAFAS::Message - An arrival/departure-related message.
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......
......@@ -16,7 +16,7 @@ use 5.014;
use parent 'Exporter';
our @EXPORT_OK = qw(decode_polyline);
our $VERSION = '5.05';
our $VERSION = '5.06';
# Translated this php script
# <http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/>
......
......@@ -8,33 +8,44 @@ use 5.014;
use parent 'Class::Accessor';
our $VERSION = '5.05';
our $VERSION = '5.06';
Travel::Status::DE::HAFAS::Product->mk_ro_accessors(
qw(name type type_long class number line line_no operator)
);
qw(class line_id line_no name number type type_long operator));
# {{{ Constructor
sub new {
my ( $obj, %opt ) = @_;
my $product = $opt{product};
my $common = $opt{common};
my $opL = $common->{opL};
my $product = $opt{product};
my $common = $opt{common};
my $opL = $common->{opL};
my $class = $product->{cls};
# DB:
# catIn / catOutS eq "IXr" => "ICE X Regio"? regional tickets are generally accepted
# <= does not hold
my $class = $product->{cls};
my $name = $product->{addName} // $product->{name};
my $line_no = $product->{prodCtx}{line};
my $train_no = $product->{prodCtx}{num};
my $cat = $product->{prodCtx}{catOut};
my $catlong = $product->{prodCtx}{catOutL};
# ÖBB, you so silly
if ( $name and $name =~ m{Zug-Nr} and $product->{nameS} ) {
$name = $product->{nameS};
}
if ( $name and $cat and $name eq $cat and $product->{nameS} ) {
$name .= ' ' . $product->{nameS};
}
if ( defined $train_no and not $train_no ) {
$train_no = undef;
}
if (
not defined $line_no
and defined $product->{prodCtx}{matchId}
......@@ -45,6 +56,11 @@ sub new {
$line_no = $product->{prodCtx}{matchId};
}
my $line_id;
if ( $product->{prodCtx}{lineId} ) {
$line_id = lc( $product->{prodCtx}{lineId} =~ s{_+}{-}gr );
}
my $operator;
if ( defined $product->{oprX} ) {
if ( my $opref = $opL->[ $product->{oprX} ] ) {
......@@ -53,14 +69,14 @@ sub new {
}
my $ref = {
name => $name,
number => $train_no,
line => $name,
line_no => $line_no,
type => $cat,
type_long => $catlong,
class => $class,
operator => $operator,
name => $name,
number => $train_no,
line_id => $line_id,
line_no => $line_no,
type => $cat,
type_long => $catlong,
class => $class,
operator => $operator,
};
bless( $ref, $obj );
......@@ -89,7 +105,7 @@ associated with a journey.
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......@@ -103,53 +119,51 @@ stops.
=over
=item $product->name
Journey or line name, either in a format like "Bus SB16" (Bus line
SB16) or "RE 10111" (RegionalExpress train 10111, no line information). May
contain extraneous whitespace characters.
=item $product->type
Type of this journey, e.g. "S" for S-Bahn, "RE" for Regional Express
or "STR" for tram / StraE<szlig>enbahn.
=item $product->type_long
Long type of this journey, e.g. "S-Bahn" or "Regional-Express".
=item $product->class
An integer identifying the the mode of transport class.
Semantics depend on backend, e.g. "1" and "2" for long-distance trains and
"4" and "8" for regional trains.
An integer identifying the the mode of transport class. Semantics depend on
backend See Travel::Status::DE::HAFAS(3pm)'s C<< $hafas->get_active_service >>
method.
=item $product->line
=item $product->line_id
Journey or line name, either in a format like "Bus SB16" (Bus line
SB16), "RE 42" (RegionalExpress train 42) or "IC 2901" (InterCity train 2901,
no line information). May contain extraneous whitespace characters. Note that
this accessor does not return line information for IC/ICE/EC services, even if
it is available. Use B<line_no> for those.
Line identifier, or undef if it is unknown.
This is a backend-specific identifier, e.g. "7-vrr010-17" for VRR U17.
The format is compatible with L<https://github.com/Traewelling/line-colors>.
=item $product->line_no
Line identifier, or undef if it is unknown.
Line number, or undef if it is unknown.
The line identifier may be a single number such as "11" (underground train
line U 11), a single word (e.g. "AIR") or a combination (e.g. "SB16").
May also provide line numbers of IC/ICE services.
=item $product->name
Trip or line name, either in a format like "Bus SB16" (Bus line
SB16), "RE 42" (RegionalExpress train 42) or "IC 2901" (InterCity train 2901,
no line information). May contain extraneous whitespace characters. Note that
this accessor does not return line information for DB IC/ICE/EC services, even
if it is available. Use B<line_no> for those.
=item $product->number
Journey number (e.g. train number), or undef if it is unknown.
Trip number (e.g. train number), or undef if it is unknown.
=item $product->type
Type of this product, e.g. "S" for S-Bahn, "RE" for Regional Express
or "STR" for tram / StraE<szlig>enbahn.
=item $product->type_long
Long type of this product, e.g. "S-Bahn" or "Regional-Express".
=item $product->operator
The operator responsible for this journey. Returns undef
The operator responsible for this product. Returns undef
if the backend does not provide an operator.
Foo.
=back
=head1 DIAGNOSTICS
......
......@@ -8,7 +8,7 @@ use 5.014;
use parent 'Class::Accessor';
our $VERSION = '5.05';
our $VERSION = '5.06';
Travel::Status::DE::HAFAS::Stop->mk_ro_accessors(
qw(loc
......@@ -194,7 +194,7 @@ Travel::Status::DE::HAFAS::Stop - Information about a HAFAS stop.
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......
......@@ -10,7 +10,7 @@ use Encode qw(decode);
use JSON;
use LWP::UserAgent;
our $VERSION = '5.05';
our $VERSION = '5.06';
# {{{ Constructors
......@@ -180,7 +180,7 @@ finder services
=head1 VERSION
version 5.05
version 5.06
=head1 DESCRIPTION
......