summaryrefslogtreecommitdiff
path: root/lib/Travel/Status
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-25 10:02:01 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-25 10:05:30 +0100
commit9d928f5cf6bb4ec857bf2b300894d5fee5ec61e2 (patch)
treeba370f49dcfcaebeac9012a636397a487320e739 /lib/Travel/Status
parent6c2ebcb388c3ee99522b2afd9e83dcabe8eb4b61 (diff)
Add support for stop-specific messages in journeys
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r--lib/Travel/Status/DE/HAFAS/Journey.pm26
-rw-r--r--lib/Travel/Status/DE/HAFAS/Stop.pm34
2 files changed, 47 insertions, 13 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm
index d8d63ff..eb00272 100644
--- a/lib/Travel/Status/DE/HAFAS/Journey.pm
+++ b/lib/Travel/Status/DE/HAFAS/Journey.pm
@@ -8,7 +8,8 @@ use 5.014;
use parent 'Class::Accessor';
use DateTime::Format::Strptime;
-use List::Util qw(any);
+use List::Util qw(any);
+use Scalar::Util qw(weaken);
use Travel::Status::DE::HAFAS::Stop;
our $VERSION = '5.00';
@@ -110,17 +111,18 @@ sub new {
for my $stop ( @{ $journey->{stopL} // [] } ) {
my $loc = $locL->[ $stop->{locX} ];
- push(
- @stops,
- {
- loc => $loc,
- stop => $stop,
- common => $opt{common},
- date => $date,
- datetime_ref => $datetime_ref,
- strp_obj => $hafas->{strptime_obj},
- }
- );
+ my $stopref = {
+ loc => $loc,
+ stop => $stop,
+ common => $opt{common},
+ hafas => $hafas,
+ date => $date,
+ datetime_ref => $datetime_ref,
+ };
+
+ weaken( $stopref->{hafas} );
+
+ push( @stops, $stopref );
$route_end = $loc->name;
}
diff --git a/lib/Travel/Status/DE/HAFAS/Stop.pm b/lib/Travel/Status/DE/HAFAS/Stop.pm
index 5763465..5d2ab36 100644
--- a/lib/Travel/Status/DE/HAFAS/Stop.pm
+++ b/lib/Travel/Status/DE/HAFAS/Stop.pm
@@ -29,7 +29,8 @@ sub new {
my $common = $opt{common};
my $date = $opt{date};
my $datetime_ref = $opt{datetime_ref};
- my $strp_obj = $opt{strp_obj};
+ my $hafas = $opt{hafas};
+ my $strp_obj = $opt{hafas}{strptime_obj};
my $sched_arr = $stop->{aTimeS};
my $rt_arr = $stop->{aTimeR};
@@ -69,6 +70,21 @@ sub new {
my $arr_cancelled = $stop->{aCncl};
my $dep_cancelled = $stop->{dCncl};
+ my @messages;
+ for my $msg ( @{ $stop->{msgL} // [] } ) {
+ if ( $msg->{type} eq 'REM' and defined $msg->{remX} ) {
+ push( @messages,
+ $hafas->add_message( $opt{common}{remL}[ $msg->{remX} ] ) );
+ }
+ elsif ( $msg->{type} eq 'HIM' and defined $msg->{himX} ) {
+ push( @messages,
+ $hafas->add_message( $opt{common}{himL}[ $msg->{himX} ], 1 ) );
+ }
+ else {
+ say "Unknown message type $msg->{type}";
+ }
+ }
+
my $tco = {};
for my $tco_id ( @{ $stop->{dTrnCmpSX}{tcocX} // [] } ) {
my $tco_kv = $common->{tcocL}[$tco_id];
@@ -94,6 +110,7 @@ sub new {
is_changed_platform => $changed_platform,
platform => $rt_platform // $sched_platform,
load => $tco,
+ messages => \@messages,
};
bless( $ref, $obj );
@@ -121,6 +138,15 @@ sub handle_day_change {
return $timestr;
}
+sub messages {
+ my ($self) = @_;
+
+ if ( $self->{messages} ) {
+ return @{ $self->{messages} };
+ }
+ return;
+}
+
sub TO_JSON {
my ($self) = @_;
@@ -225,6 +251,12 @@ Departure or arrival delay in minutes.
Direction signage from this stop on, undef if unchanged.
+=item $journey->messages
+
+List of Travel::Status::DE::HAFAS::Message(3pm) instances related to this stop.
+These typically refer to delay reasons, platform changes, or changes in the
+line number / direction heading.
+
=item $stop->rt_platform
Actual platform.