From b4f2978792b1abb8ec994aa96f993641d6bdfb53 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 25 Jan 2022 21:25:29 +0100 Subject: refactor json_route_diff into Stationboard controller --- lib/DBInfoscreen.pm | 69 ++--------------------------------------------------- 1 file changed, 2 insertions(+), 67 deletions(-) (limited to 'lib/DBInfoscreen.pm') diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index ef3e0a0..afe139a 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -25,8 +25,8 @@ sub startup { hafas_rest_api => $ENV{DBFAKEDISPLAY_HAFAS_API} // 'https://v5.db.transport.rest', hypnotoad => { - accepts => $ENV{DBFAKEDISPLAY_ACCEPTS} // 100, - clients => $ENV{DBFAKEDISPLAY_CLIENTS} // 10, + accepts => $ENV{DBFAKEDISPLAY_ACCEPTS} // 100, + clients => $ENV{DBFAKEDISPLAY_CLIENTS} // 10, listen => [ $ENV{DBFAKEDISPLAY_LISTEN} // 'http://*:8092' ], pid_file => $ENV{DBFAKEDISPLAY_PID_FILE} // '/tmp/db-fakedisplay.pid', @@ -213,71 +213,6 @@ sub startup { } ); - $self->helper( - 'json_route_diff' => sub { - my ( $self, $route, $sched_route ) = @_; - my @json_route; - my @route = @{$route}; - my @sched_route = @{$sched_route}; - - my $route_idx = 0; - my $sched_idx = 0; - - while ( $route_idx <= $#route and $sched_idx <= $#sched_route ) { - if ( $route[$route_idx] eq $sched_route[$sched_idx] ) { - push( @json_route, { name => $route[$route_idx] } ); - $route_idx++; - $sched_idx++; - } - - # this branch is inefficient, but won't be taken frequently - elsif ( not( $route[$route_idx] ~~ \@sched_route ) ) { - push( - @json_route, - { - name => $route[$route_idx], - isAdditional => 1 - } - ); - $route_idx++; - } - else { - push( - @json_route, - { - name => $sched_route[$sched_idx], - isCancelled => 1 - } - ); - $sched_idx++; - } - } - while ( $route_idx <= $#route ) { - push( - @json_route, - { - name => $route[$route_idx], - isAdditional => 1, - isCancelled => 0 - } - ); - $route_idx++; - } - while ( $sched_idx <= $#sched_route ) { - push( - @json_route, - { - name => $sched_route[$sched_idx], - isAdditional => 0, - isCancelled => 1 - } - ); - $sched_idx++; - } - return @json_route; - } - ); - $self->helper( 'occupancy_icon' => sub { my ( $self, $occupancy ) = @_; -- cgit v1.2.3