Loading lib/DBInfoscreen/Controller/Stationboard.pm +3 −3 Original line number Diff line number Diff line Loading @@ -412,8 +412,6 @@ sub render_train { ) ]; $departure->{trip_id} = $self->hafas->get_tripid($result); if ( $departure->{wr_link} and not $self->wagonorder->is_available( $result, $departure->{wr_link} ) ) Loading @@ -421,9 +419,11 @@ sub render_train { $departure->{wr_link} = undef; } my ( $route_ts, $route_info ) my ( $route_ts, $route_info, $trainsearch ) = $self->hafas->get_route_timestamps( train => $result ); $departure->{trip_id} = $trainsearch->{trip_id}; # If a train number changes on the way, IRIS routes are incomplete, # whereas HAFAS data has all stops -> merge HAFAS stops into IRIS # stops. This is a rare case, one point where it can be observed is Loading lib/DBInfoscreen/Helper/HAFAS.pm +1 −67 Original line number Diff line number Diff line Loading @@ -24,31 +24,6 @@ sub new { } sub hafas_rest_req { my ( $self, $cache, $url ) = @_; if ( my $content = $cache->thaw($url) ) { return $content; } my $res = eval { $self->{user_agent}->get( $url => $self->{header} )->result; }; if ($@) { $self->{log}->debug("hafas_rest_req($url): $@"); return; } if ( $res->is_error ) { return; } my $json = decode_json( $res->body ); $cache->freeze( $url, $json ); return $json; } sub hafas_json_req { my ( $self, $cache, $url ) = @_; Loading Loading @@ -282,48 +257,7 @@ sub get_route_timestamps { } } return ( $ret, $traindelay // {} ); } sub get_tripid { my ( $self, $train ) = @_; my $cache = $self->{main_cache}; my $eva = $train->station_uic; my $dep_ts = DateTime->now( time_zone => 'Europe/Berlin' ); my $url = "https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts"; if ( $train->sched_departure ) { $dep_ts = $train->sched_departure->epoch; $url = "https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts"; } elsif ( $train->sched_arrival ) { $dep_ts = $train->sched_arrival->epoch; $url = "https://2.db.transport.rest/stations/${eva}/arrivals?duration=5&when=$dep_ts"; } my $json = $self->hafas_rest_req( $cache, $url ); #say "looking for " . $train->train_no . " in $url"; for my $result ( @{ $json // [] } ) { my $trip_id = $result->{tripId}; my $fahrt = $result->{line}{fahrtNr}; #say "checking $fahrt"; if ( $result->{line} and $result->{line}{fahrtNr} == $train->train_no ) { #say "Trip ID is $trip_id"; return $trip_id; } else { #say "unmatched Trip ID $trip_id"; } } return; return ( $ret, $traindelay // {}, $trainsearch_result ); } # Input: (HAFAS TripID, line number) Loading Loading
lib/DBInfoscreen/Controller/Stationboard.pm +3 −3 Original line number Diff line number Diff line Loading @@ -412,8 +412,6 @@ sub render_train { ) ]; $departure->{trip_id} = $self->hafas->get_tripid($result); if ( $departure->{wr_link} and not $self->wagonorder->is_available( $result, $departure->{wr_link} ) ) Loading @@ -421,9 +419,11 @@ sub render_train { $departure->{wr_link} = undef; } my ( $route_ts, $route_info ) my ( $route_ts, $route_info, $trainsearch ) = $self->hafas->get_route_timestamps( train => $result ); $departure->{trip_id} = $trainsearch->{trip_id}; # If a train number changes on the way, IRIS routes are incomplete, # whereas HAFAS data has all stops -> merge HAFAS stops into IRIS # stops. This is a rare case, one point where it can be observed is Loading
lib/DBInfoscreen/Helper/HAFAS.pm +1 −67 Original line number Diff line number Diff line Loading @@ -24,31 +24,6 @@ sub new { } sub hafas_rest_req { my ( $self, $cache, $url ) = @_; if ( my $content = $cache->thaw($url) ) { return $content; } my $res = eval { $self->{user_agent}->get( $url => $self->{header} )->result; }; if ($@) { $self->{log}->debug("hafas_rest_req($url): $@"); return; } if ( $res->is_error ) { return; } my $json = decode_json( $res->body ); $cache->freeze( $url, $json ); return $json; } sub hafas_json_req { my ( $self, $cache, $url ) = @_; Loading Loading @@ -282,48 +257,7 @@ sub get_route_timestamps { } } return ( $ret, $traindelay // {} ); } sub get_tripid { my ( $self, $train ) = @_; my $cache = $self->{main_cache}; my $eva = $train->station_uic; my $dep_ts = DateTime->now( time_zone => 'Europe/Berlin' ); my $url = "https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts"; if ( $train->sched_departure ) { $dep_ts = $train->sched_departure->epoch; $url = "https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts"; } elsif ( $train->sched_arrival ) { $dep_ts = $train->sched_arrival->epoch; $url = "https://2.db.transport.rest/stations/${eva}/arrivals?duration=5&when=$dep_ts"; } my $json = $self->hafas_rest_req( $cache, $url ); #say "looking for " . $train->train_no . " in $url"; for my $result ( @{ $json // [] } ) { my $trip_id = $result->{tripId}; my $fahrt = $result->{line}{fahrtNr}; #say "checking $fahrt"; if ( $result->{line} and $result->{line}{fahrtNr} == $train->train_no ) { #say "Trip ID is $trip_id"; return $trip_id; } else { #say "unmatched Trip ID $trip_id"; } } return; return ( $ret, $traindelay // {}, $trainsearch_result ); } # Input: (HAFAS TripID, line number) Loading