diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travel/Status/DE/EFA.pm | 27 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Departure.pm | 39 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Info.pm | 6 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Line.pm | 6 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Services.pm.PL | 7 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Stop.pm | 17 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Trip.pm | 16 | ||||
-rw-r--r-- | lib/Travel/Status/DE/VRR.pm | 6 |
8 files changed, 84 insertions, 40 deletions
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm index bb228b4..fef460d 100644 --- a/lib/Travel/Status/DE/EFA.pm +++ b/lib/Travel/Status/DE/EFA.pm @@ -5,7 +5,7 @@ use warnings; use 5.010; use utf8; -our $VERSION = '3.03'; +our $VERSION = '3.06'; use Carp qw(confess cluck); use DateTime; @@ -441,7 +441,8 @@ sub stop { place => $place, full_name => $point->{name}, name => $point->{name} =~ s{\Q$place\E,? ?}{}r, - id => $point->{stateless}, + id_num => $point->{ref}{id}, + id_code => $point->{ref}{gid}, ); return $self->{stop}; @@ -468,7 +469,8 @@ sub stops { place => $stop->{place}, name => $stop->{name}, full_name => $stop->{nameWithPlace}, - id => $stop->{stopID}, + id_num => $stop->{stopID}, + id_code => $stop->{gid}, ) ); } @@ -557,7 +559,7 @@ sub results_coord { full_name => $stop->{properties}{STOP_NAME_WITH_PLACE}, distance_m => $stop->{properties}{distance}, name => $stop->{name}, - id => $stop->{id}, + id_code => $stop->{id}, ) ); } @@ -572,6 +574,15 @@ sub results_stopfinder { my $json = $self->{response}; my @results; + + # Edge case: there is just a single result. + # Oh EFA, you so silly. + if ( ref( $json->{stopFinder}{points} ) eq 'HASH' + and exists $json->{stopFinder}{points}{point} ) + { + $json->{stopFinder}{points} = [ $json->{stopFinder}{points}{point} ]; + } + for my $stop ( @{ $json->{stopFinder}{points} // [] } ) { push( @results, @@ -579,8 +590,8 @@ sub results_stopfinder { place => $stop->{ref}{place}, full_name => $stop->{name}, name => $stop->{object}, - id => $stop->{stateless}, - stop_id => $stop->{ref}{gid}, + id_num => $stop->{ref}{id}, + id_code => $stop->{ref}{gid}, ) ); } @@ -669,7 +680,7 @@ Travel::Status::DE::EFA - unofficial EFA departure monitor =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -893,7 +904,7 @@ efa-m(1), Travel::Status::DE::EFA::Departure(3pm). =head1 AUTHOR -Copyright (C) 2011-2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2011-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE diff --git a/lib/Travel/Status/DE/EFA/Departure.pm b/lib/Travel/Status/DE/EFA/Departure.pm index c5cc2d6..a34fab3 100644 --- a/lib/Travel/Status/DE/EFA/Departure.pm +++ b/lib/Travel/Status/DE/EFA/Departure.pm @@ -10,12 +10,12 @@ use Travel::Status::DE::EFA::Stop; use parent 'Class::Accessor'; -our $VERSION = '3.03'; +our $VERSION = '3.06'; Travel::Status::DE::EFA::Departure->mk_ro_accessors( qw(countdown datetime delay destination is_cancelled key line lineref mot occupancy operator origin platform platform_db platform_name rt_datetime - sched_datetime stateless stop_id train_type train_name train_no type) + sched_datetime stateless stop_id_num train_type train_name train_no type) ); my @mot_mapping = qw{ @@ -69,7 +69,7 @@ sub new { platform_type => $departure->{pointType}, key => $departure->{servingLine}{key}, stateless => $departure->{servingLine}{stateless}, - stop_id => $departure->{stopID}, + stop_id_num => $departure->{stopID}, line => $departure->{servingLine}{symbol}, train_type => $departure->{servingLine}{trainType}, train_name => $departure->{servingLine}{trainName}, @@ -154,7 +154,8 @@ sub parse_route { sched_dep => $dep, arr_delay => $ref->{arrValid} ? $ref->{arrDelay} : undef, dep_delay => $ref->{depValid} ? $ref->{depDelay} : undef, - id => $ref->{id}, + id_num => $ref->{id}, + id_code => $ref->{gid}, full_name => $stop->{name}, place => $stop->{place}, name => $stop->{nameWO}, @@ -167,6 +168,22 @@ sub parse_route { return \@ret; } +sub id { + my ($self) = @_; + + if ( $self->{id} ) { + return $self->{id}; + } + + return $self->{id} = sprintf( '%s@%d(%s)%d', + $self->stateless =~ s{ }{}gr, + scalar $self->route_pre + ? ( $self->route_pre )[0]->id_num + : $self->stop_id_num, + $self->sched_datetime->strftime('%Y%m%d'), + $self->key ); +} + sub hints { my ($self) = @_; @@ -248,6 +265,9 @@ sub route_interesting { sub TO_JSON { my ($self) = @_; + # compute on-demand keys + $self->id; + my $ret = { %{$self} }; delete $ret->{strp_stopseq}; @@ -283,7 +303,7 @@ departure received by Travel::Status::DE::EFA =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -324,6 +344,13 @@ Additional information related to the departure (list of strings). If departures for an address were requested, this is the stop name, otherwise it may be recent news related to the line's schedule. +=item $departure->id + +Stringified unique(?) identifier of this departure; suitable for passing to +Travel::Status::DE::EFA->new(stopseq) after decomposing it again. +The returned string combines B<stateless>, B<stop_id_num> (or the ID of the first +stop in B<route_pre>, if present), B<sched_datetime>, and B<key>. + =item $departure->is_cancelled 1 if the departure got cancelled, 0 otherwise. @@ -493,7 +520,7 @@ Travel::Status::DE::EFA(3pm). =head1 AUTHOR -Copyright (C) 2011-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2011-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE diff --git a/lib/Travel/Status/DE/EFA/Info.pm b/lib/Travel/Status/DE/EFA/Info.pm index 8715f11..703382c 100644 --- a/lib/Travel/Status/DE/EFA/Info.pm +++ b/lib/Travel/Status/DE/EFA/Info.pm @@ -6,7 +6,7 @@ use 5.010; use parent 'Class::Accessor'; -our $VERSION = '3.03'; +our $VERSION = '3.06'; Travel::Status::DE::EFA::Info->mk_ro_accessors( qw(link_url link_text subject content subtitle additional_text)); @@ -58,7 +58,7 @@ Travel::Status::DE::EFA::Info - Information about a public transit stop =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -120,7 +120,7 @@ Travel::Status::DE::EFA(3pm). =head1 AUTHOR -Copyright (C) 2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2024-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE diff --git a/lib/Travel/Status/DE/EFA/Line.pm b/lib/Travel/Status/DE/EFA/Line.pm index 8775dfc..a43dda0 100644 --- a/lib/Travel/Status/DE/EFA/Line.pm +++ b/lib/Travel/Status/DE/EFA/Line.pm @@ -6,7 +6,7 @@ use 5.010; use parent 'Class::Accessor'; -our $VERSION = '3.03'; +our $VERSION = '3.06'; Travel::Status::DE::EFA::Line->mk_ro_accessors( qw(direction mot name number operator route type valid)); @@ -57,7 +57,7 @@ requested station =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -151,7 +151,7 @@ Travel::Status::DE::EFA(3pm). =head1 AUTHOR -Copyright (C) 2011-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2011-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE diff --git a/lib/Travel/Status/DE/EFA/Services.pm.PL b/lib/Travel/Status/DE/EFA/Services.pm.PL index a2d6488..c3cb9e3 100644 --- a/lib/Travel/Status/DE/EFA/Services.pm.PL +++ b/lib/Travel/Status/DE/EFA/Services.pm.PL @@ -34,6 +34,7 @@ sub load_instance { # GVH: 403 # Rolph: 404 # VRT: Encoding issues +# VVSt: NXDOMAIN my %efa_instance = ( BSVG => { url => 'https://bsvg.efa.de/bsvagstd', @@ -55,6 +56,10 @@ my %efa_instance = ( url => 'https://www.efa-bw.de/nvbw', name => 'Nahverkehrsgesellschaft Baden-Württemberg', }, + NWL => { + url => 'https://westfalenfahrplan.de/nwl-efa', + name => 'Nahverkehr Westfalen-Lippe', + }, VAG => { url => 'https://efa.vagfr.de/vagfr3', name => 'Freiburger Verkehrs AG', @@ -95,7 +100,7 @@ use warnings; use 5.014; use utf8; -our $VERSION = '3.03'; +our $VERSION = '3.06'; # Most of these have been adapted from # <https://github.com/public-transport/transport-apis> and diff --git a/lib/Travel/Status/DE/EFA/Stop.pm b/lib/Travel/Status/DE/EFA/Stop.pm index 46d3b08..1dc8cda 100644 --- a/lib/Travel/Status/DE/EFA/Stop.pm +++ b/lib/Travel/Status/DE/EFA/Stop.pm @@ -6,13 +6,13 @@ use 5.010; use parent 'Class::Accessor'; -our $VERSION = '3.03'; +our $VERSION = '3.06'; Travel::Status::DE::EFA::Stop->mk_ro_accessors( qw(sched_arr rt_arr arr arr_delay sched_dep rt_dep dep dep_delay occupancy delay distance_m - place name full_name id stop_id latlon + place name full_name id_num id_code latlon platform niveau) ); @@ -93,7 +93,7 @@ in a Travel::Status::DE::EFA::Result's route =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -152,14 +152,13 @@ Delay in minutes. Departure delya if available, arrival delay otherwise. Distance from request coordinates in meters. undef if the object has not been obtained by means of a coord request. -=item $stop->id +=item $stop->id_num -Stop ID. +Stop ID (numeric). -=item $stop->stop_id +=item $stop->id_code -The other kind of stop ID. -Yes, EFA has two. +Stop ID (code). =item $stop->place @@ -222,7 +221,7 @@ Travel::Status::DE::EFA(3pm). =head1 AUTHOR -Copyright (C) 2015-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2015-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE diff --git a/lib/Travel/Status/DE/EFA/Trip.pm b/lib/Travel/Status/DE/EFA/Trip.pm index 3435431..839fcca 100644 --- a/lib/Travel/Status/DE/EFA/Trip.pm +++ b/lib/Travel/Status/DE/EFA/Trip.pm @@ -9,7 +9,7 @@ use Travel::Status::DE::EFA::Stop; use parent 'Class::Accessor'; -our $VERSION = '3.03'; +our $VERSION = '3.06'; Travel::Status::DE::EFA::Trip->mk_ro_accessors( qw(operator product product_class name line number type id dest_name dest_id) @@ -49,6 +49,7 @@ sub polyline { my ( $self, %opt ) = @_; if ( $opt{fallback} and not @{ $self->{polyline} // [] } ) { + # TODO add $_->{id} as well? return map { $_->{latlon} } $self->route; } @@ -77,7 +78,7 @@ sub route { for my $stop ( @{ $self->{route_raw} // [] } ) { my $chain = $stop; - my ( $platform, $place, $name, $name_full, $stop_id ); + my ( $platform, $place, $name, $name_full, $id_num, $id_code ); while ( $chain->{type} ) { if ( $chain->{type} eq 'platform' ) { $platform = $chain->{properties}{platformName} @@ -86,7 +87,8 @@ sub route { elsif ( $chain->{type} eq 'stop' ) { $name = $chain->{disassembledName}; $name_full = $chain->{name}; - $stop_id = $chain->{properties}{stopId}; + $id_code = $chain->{id}; + $id_num = $chain->{properties}{stopId}; } elsif ( $chain->{type} eq 'locality' ) { $place = $chain->{name}; @@ -106,8 +108,8 @@ sub route { place => $place, niveau => $stop->{niveau}, platform => $platform, - id => $stop->{id}, - stop_id => $stop_id, + id_code => $id_code, + id_num => $id_num, ) ); } @@ -148,7 +150,7 @@ trip =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -256,7 +258,7 @@ Travel::Status::DE::EFA(3pm). =head1 AUTHOR -Copyright (C) 2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2024-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE diff --git a/lib/Travel/Status/DE/VRR.pm b/lib/Travel/Status/DE/VRR.pm index b472c5c..a0c183f 100644 --- a/lib/Travel/Status/DE/VRR.pm +++ b/lib/Travel/Status/DE/VRR.pm @@ -4,7 +4,7 @@ use strict; use warnings; use 5.010; -our $VERSION = '3.03'; +our $VERSION = '3.06'; use parent 'Travel::Status::DE::EFA'; @@ -43,7 +43,7 @@ Travel::Status::DE::VRR - unofficial VRR departure monitor. =head1 VERSION -version 3.03 +version 3.06 =head1 DESCRIPTION @@ -95,7 +95,7 @@ efa-m(1), Travel::Status::DE::EFA(3pm). =head1 AUTHOR -Copyright (C) 2013-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2013-2023 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE |