From 2c75f4a4f7b29f7ef174b79c704678804701ac36 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 25 Jan 2022 19:23:20 +0100 Subject: JSON interface: add (not-yet-final) replacement train data --- lib/DBInfoscreen/Controller/Stationboard.pm | 93 ++++++++++++++++------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 7f5b0d5..7e16502 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -1170,48 +1170,57 @@ sub handle_result { if ( $result->sched_departure ) { $sched_dep = $result->sched_departure->strftime('%H:%M'); } - push( - @departures, - { - delayArrival => $delay_arr, - delayDeparture => $delay_dep, - destination => $result->destination, - isCancelled => $result->is_cancelled, - messages => { - delay => [ - map { - { - timestamp => $_->[0], - text => $_->[1] - } - } $result->delay_messages - ], - qos => [ - map { - { - timestamp => $_->[0], - text => $_->[1] - } - } $result->qos_messages - ], - }, - missingRealtime => ( - ( - not $result->has_realtime - and $result->start < $now - ) ? \1 : \0 - ), - platform => $result->platform, - route => \@json_route, - scheduledPlatform => $result->sched_platform, - scheduledArrival => $sched_arr, - scheduledDeparture => $sched_dep, - train => $result->train, - trainClasses => [ $result->classes ], - trainNumber => $result->train_no, - via => [ $result->route_interesting(3) ], - } - ); + my $dep = { + delayArrival => $delay_arr, + delayDeparture => $delay_dep, + destination => $result->destination, + isCancelled => $result->is_cancelled, + messages => { + delay => [ + map { { timestamp => $_->[0], text => $_->[1] } } + $result->delay_messages + ], + qos => [ + map { { timestamp => $_->[0], text => $_->[1] } } + $result->qos_messages + ], + }, + missingRealtime => ( + ( not $result->has_realtime and $result->start < $now ) + ? \1 + : \0 + ), + platform => $result->platform, + route => \@json_route, + scheduledPlatform => $result->sched_platform, + scheduledArrival => $sched_arr, + scheduledDeparture => $sched_dep, + train => $result->train, + trainClasses => [ $result->classes ], + trainNumber => $result->train_no, + via => [ $result->route_interesting(3) ], + }; + for my $replaced_by ( $result->replaced_by ) { + push( + @{ $dep->{replacementTrains} }, + { + train => $replaced_by->train, + trainType => $replaced_by->type, + trainNumber => $replaced_by->train_no + } + ); + } + for my $replacement_for ( $result->replacement_for ) { + push( + @{ $dep->{replacedTrains} }, + { + train => $replacement_for->train, + trainType => $replacement_for->type, + trainNumber => $replacement_for->train_no + } + ); + } + push( @departures, $dep ); } } elsif ( $template eq 'text' ) { -- cgit v1.2.3