From 8f657f59c7c306040f39057c02f705bb4a0c3158 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 8 Sep 2020 18:07:01 +0200 Subject: always calculate tripid via trainsearch.exe --- lib/DBInfoscreen/Controller/Stationboard.pm | 6 +-- lib/DBInfoscreen/Helper/HAFAS.pm | 68 +---------------------------- 2 files changed, 4 insertions(+), 70 deletions(-) (limited to 'lib') diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index f8426c5..c2aa613 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -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} ) ) @@ -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 diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index 2eb156c..c4f0883 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -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 ) = @_; @@ -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) -- cgit v1.2.3