diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-01-25 19:23:20 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-01-25 19:23:20 +0100 |
commit | 2c75f4a4f7b29f7ef174b79c704678804701ac36 (patch) | |
tree | f46f50e8fd4252bf75c1331fd19fa978f1913091 /lib/DBInfoscreen/Controller | |
parent | e3f62e54e62c94f71b9c0ef63da553cf728a0477 (diff) |
JSON interface: add (not-yet-final) replacement train data
Diffstat (limited to 'lib/DBInfoscreen/Controller')
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 93 |
1 files 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' ) { |