summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2023-04-11 19:30:05 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2023-04-11 19:30:05 +0200
commit4871bc50f636dca9030575b2d693079a5fd663d7 (patch)
tree7e0f158a035fd311a8b1a37c6465f0983d1fe46f /lib/Travel/Status/DE
parent72bc43a9e4e010020e94a701648ba51dc8d580ed (diff)
Journey->route: Return Stop instances
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r--lib/Travel/Status/DE/HAFAS/Journey.pm111
-rw-r--r--lib/Travel/Status/DE/HAFAS/Stop.pm94
2 files changed, 121 insertions, 84 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm
index cd209c0..824019b 100644
--- a/lib/Travel/Status/DE/HAFAS/Journey.pm
+++ b/lib/Travel/Status/DE/HAFAS/Journey.pm
@@ -9,6 +9,7 @@ use 5.014;
no if $] >= 5.018, warnings => 'experimental::smartmatch';
use parent 'Class::Accessor';
+use Travel::Status::DE::HAFAS::Stop;
our $VERSION = '4.09';
@@ -139,27 +140,26 @@ sub new {
push(
@stops,
{
- name => $loc->{name},
- eva => $loc->{extId} + 0,
- lon => $loc->{crd}{x} * 1e-6,
- lat => $loc->{crd}{y} * 1e-6,
- sched_arr => $sched_arr,
- rt_arr => $rt_arr,
- arr => $rt_arr // $sched_arr,
- arr_delay => $arr_delay,
- arr_cancelled => $arr_cancelled,
- sched_dep => $sched_dep,
- rt_dep => $rt_dep,
- dep => $rt_dep // $sched_dep,
- dep_delay => $dep_delay,
- dep_cancelled => $dep_cancelled,
- delay => $dep_delay // $arr_delay,
- direction => $stop->{dDirTxt},
- sched_platform => $sched_platform,
- rt_platform => $rt_platform,
- is_changed_platform => $changed_platform,
- platform => $rt_platform // $sched_platform,
- load => $tco,
+ loc => $loc,
+ extra => {
+ sched_arr => $sched_arr,
+ rt_arr => $rt_arr,
+ arr => $rt_arr // $sched_arr,
+ arr_delay => $arr_delay,
+ arr_cancelled => $arr_cancelled,
+ sched_dep => $sched_dep,
+ rt_dep => $rt_dep,
+ dep => $rt_dep // $sched_dep,
+ dep_delay => $dep_delay,
+ dep_cancelled => $dep_cancelled,
+ delay => $dep_delay // $arr_delay,
+ direction => $stop->{dDirTxt},
+ sched_platform => $sched_platform,
+ rt_platform => $rt_platform,
+ is_changed_platform => $changed_platform,
+ platform => $rt_platform // $sched_platform,
+ load => $tco,
+ }
}
);
$route_end = $loc->{name};
@@ -338,6 +338,11 @@ sub route {
my ($self) = @_;
if ( $self->{route} ) {
+ if ( $self->{route}[0] and $self->{route}[0]{extra} ) {
+ $self->{route}
+ = [ map { Travel::Status::DE::HAFAS::Stop->new( %{$_} ) }
+ @{ $self->{route} } ];
+ }
return @{ $self->{route} };
}
return;
@@ -413,14 +418,6 @@ sub TO_JSON {
}
}
- for my $stop ( @{ $ret->{route} } ) {
- for my $k ( keys %{$stop} ) {
- if ( ref( $stop->{$k} ) eq 'DateTime' ) {
- $stop->{$k} = $stop->{$k}->epoch;
- }
- }
- }
-
return $ret;
}
@@ -598,58 +595,10 @@ UIC/EVA ID of the station at which this journey was requested.
=item $journey->route
-Returns a list of hashes; each hash describes a single journey stop.
-In stationboard mode, it only contains arrivals prior to the requested station
-or departures after the requested station. In journey mode, it contains the
-entire route. Each hash contains the following keys:
-
-=over
-
-=item * name (name)
-
-=item * eva (EVA ID)
-
-=item * lon (longitude)
-
-=item * lat (latitude)
-
-=item * rt_arr (DateTime object for actual arrival)
-
-=item * sched_arr (DateTime object for scheduled arrival)
-
-=item * arr (DateTime object for actual or scheduled arrival)
-
-=item * arr_delay (arrival delay in minutes)
-
-=item * arr_cancelled (arrival is cancelled)
-
-=item * rt_dep (DateTime object for actual departure)
-
-=item * sched_dep (DateTime object for scheduled departure)
-
-=item * dep (DateTIme object for actual or scheduled departure)
-
-=item * dep_delay (departure delay in minutes)
-
-=item * dep_cancelled (departure is cancelled)
-
-=item * delay (departure or arrival delay in minutes)
-
-=item * direction (direction signage from this stop on, undef if unchanged)
-
-=item * rt_platform (actual platform)
-
-=item * sched_platform (scheduled platform)
-
-=item * platform (actual or scheduled platform)
-
-=item * is_changed_platform (true if real-time and scheduled platform disagree)
-
-=item * load (expected utilization / passenger load from this stop on)
-
-=back
-
-Individual entries may be undef.
+Returns a list of Travel::Status::DE::HAFAS::Stop(3pm) objects that describe
+individual stops along the journey. In stationboard mode, the list only
+contains arrivals prior to the requested station or departures after the
+requested station. In journey mode, it contains the entire route.
=item $journey->route_interesting([I<count>])
diff --git a/lib/Travel/Status/DE/HAFAS/Stop.pm b/lib/Travel/Status/DE/HAFAS/Stop.pm
index 3c56900..7e05ad0 100644
--- a/lib/Travel/Status/DE/HAFAS/Stop.pm
+++ b/lib/Travel/Status/DE/HAFAS/Stop.pm
@@ -20,7 +20,7 @@ sub new {
my $loc = $opt{loc};
my $ref = {
- eva => 0 + $loc->{extId},
+ eva => $loc->{extId} + 0,
name => $loc->{name},
lat => $loc->{crd}{x} * 1e-6,
lon => $loc->{crd}{y} * 1e-6,
@@ -28,6 +28,12 @@ sub new {
distance_m => $loc->{dist},
};
+ if ( $opt{extra} ) {
+ while ( my ( $k, $v ) = each %{ $opt{extra} } ) {
+ $ref->{$k} = $v;
+ }
+ }
+
bless( $ref, $obj );
return $ref;
@@ -35,6 +41,20 @@ sub new {
# }}}
+sub TO_JSON {
+ my ($self) = @_;
+
+ my $ret = { %{$self} };
+
+ for my $k ( keys %{$ret} ) {
+ if ( ref( $ret->{$k} ) eq 'DateTime' ) {
+ $ret->{$k} = $ret->{$k}->epoch;
+ }
+ }
+
+ return $ret;
+}
+
1;
__END__
@@ -63,8 +83,8 @@ version 4.09
Travel::Status::DE::HAFAS::Stop describes a HAFAS stop. It may be part of a
journey or part of a geoSearch / locationSearch request.
-geoSearch- and locationSearch-specific accessors are annotated accordingly and
-return undef for non-geoSearch / non-locationSearch stops.
+Journey-, geoSearch- and locationSearch-specific accessors are annotated
+accordingly and return undef in other contexts.
=head1 METHODS
@@ -97,6 +117,74 @@ Distance in meters between the requested coordinates and this stop.
Weight / Relevance / Importance of this stop using an unknown metric.
Higher values indicate more relevant stops.
+=item $stop->rt_arr (journey)
+
+DateTime object for actual arrival.
+
+=item $stop->sched_arr (journey)
+
+DateTime object for scheduled arrival.
+
+=item $stop->arr (journey)
+
+DateTime object for actual or scheduled arrival.
+
+=item $stop->arr_delay (journey)
+
+Arrival delay in minutes.
+
+=item $stop->arr_cancelled (journey)
+
+Arrival is cancelled.
+
+=item $stop->rt_dep (journey)
+
+DateTime object for actual departure.
+
+=item $stop->sched_dep (journey)
+
+DateTime object for scheduled departure.
+
+=item $stop->dep (journey)
+
+DateTIme object for actual or scheduled departure.
+
+=item $stop->dep_delay (journey)
+
+Departure delay in minutes.
+
+=item $stop->dep_cancelled (journey)
+
+Departure is cancelled.
+
+=item $stop->delay (journey)
+
+Departure or arrival delay in minutes.
+
+=item $stop->direction (journey)
+
+Direction signage from this stop on, undef if unchanged.
+
+=item $stop->rt_platform (journey)
+
+Actual platform.
+
+=item $stop->sched_platform (journey)
+
+Scheduled platform.
+
+=item $stop->platform (journey)
+
+Actual or scheduled platform.
+
+=item $stop->is_changed_platform (journey)
+
+True if real-time and scheduled platform disagree.
+
+=item $stop->load (journey)
+
+Expected utilization / passenger load from this stop on.
+
=back
=head1 DIAGNOSTICS