From d47195a0cf30a64ca7afcbbeed6edb6b54039104 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Wed, 27 Dec 2023 10:59:35 +0100 Subject: Switch to Travel::Status::DE::HAFAS 5.x --- lib/Travelynx/Command/work.pm | 4 ++-- lib/Travelynx/Helper/HAFAS.pm | 30 +++++++++++++++--------------- lib/Travelynx/Model/InTransit.pm | 38 +++++++++++++++++++------------------- lib/Travelynx/Model/Stations.pm | 19 ++++++++++--------- 4 files changed, 46 insertions(+), 45 deletions(-) (limited to 'lib/Travelynx') diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 09649a3..a02618b 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -46,10 +46,10 @@ sub run { my $found_dep; my $found_arr; for my $stop ( $journey->route ) { - if ( $stop->eva == $dep ) { + if ( $stop->loc->eva == $dep ) { $found_dep = $stop; } - if ( $arr and $stop->eva == $arr ) { + if ( $arr and $stop->loc->eva == $arr ) { $found_arr = $stop; last; } diff --git a/lib/Travelynx/Helper/HAFAS.pm b/lib/Travelynx/Helper/HAFAS.pm index 6a759b0..d7f2a10 100644 --- a/lib/Travelynx/Helper/HAFAS.pm +++ b/lib/Travelynx/Helper/HAFAS.pm @@ -171,20 +171,20 @@ sub get_route_timestamps_p { my $station_is_past = 1; for my $stop ( $journey->route ) { - my $name = $stop->{name}; - $ret->{$name} = $ret->{ $stop->{eva} } = { - name => $stop->{name}, - eva => $stop->{eva}, - sched_arr => _epoch( $stop->{sched_arr} ), - sched_dep => _epoch( $stop->{sched_dep} ), - rt_arr => _epoch( $stop->{rt_arr} ), - rt_dep => _epoch( $stop->{rt_dep} ), - arr_delay => $stop->{arr_delay}, - dep_delay => $stop->{dep_delay}, - load => $stop->{load} + my $name = $stop->loc->name; + $ret->{$name} = $ret->{ $stop->loc->eva } = { + name => $stop->loc->name, + eva => $stop->loc->eva, + sched_arr => _epoch( $stop->sched_arr ), + sched_dep => _epoch( $stop->sched_dep ), + rt_arr => _epoch( $stop->rt_arr ), + rt_dep => _epoch( $stop->rt_dep ), + arr_delay => $stop->arr_delay, + dep_delay => $stop->dep_delay, + load => $stop->load }; - if ( ( $stop->{arr_cancelled} or not $stop->{sched_arr} ) - and ( $stop->{dep_cancelled} or not $stop->{sched_dep} ) ) + if ( ( $stop->arr_cancelled or not $stop->sched_arr ) + and ( $stop->dep_cancelled or not $stop->sched_dep ) ) { $ret->{$name}{isCancelled} = 1; } @@ -229,8 +229,8 @@ sub get_route_timestamps_p { or index( $hafas_stations, $iris_stations ) != -1 ) { $polyline = { - from_eva => ( $journey->route )[0]{eva}, - to_eva => ( $journey->route )[-1]{eva}, + from_eva => ( $journey->route )[0]->loc->eva, + to_eva => ( $journey->route )[-1]->loc->eva, coords => \@coordinate_list, }; } diff --git a/lib/Travelynx/Model/InTransit.pm b/lib/Travelynx/Model/InTransit.pm index adcdfa3..fa9c464 100644 --- a/lib/Travelynx/Model/InTransit.pm +++ b/lib/Travelynx/Model/InTransit.pm @@ -126,16 +126,16 @@ sub add { push( @route, [ - $j_stop->name, - $j_stop->eva, + $j_stop->loc->name, + $j_stop->loc->eva, { - sched_arr => _epoch( $j_stop->{sched_arr} ), - sched_dep => _epoch( $j_stop->{sched_dep} ), - rt_arr => _epoch( $j_stop->{rt_arr} ), - rt_dep => _epoch( $j_stop->{rt_dep} ), - arr_delay => $j_stop->{arr_delay}, - dep_delay => $j_stop->{dep_delay}, - load => $j_stop->{load} + sched_arr => _epoch( $j_stop->sched_arr ), + sched_dep => _epoch( $j_stop->sched_dep ), + rt_arr => _epoch( $j_stop->rt_arr ), + rt_dep => _epoch( $j_stop->rt_dep ), + arr_delay => $j_stop->arr_delay, + dep_delay => $j_stop->dep_delay, + load => $j_stop->load } ] ); @@ -147,7 +147,7 @@ sub add { cancelled => $stop->{dep_cancelled} ? 1 : 0, - checkin_station_id => $stop->eva, + checkin_station_id => $stop->loc->eva, checkin_time => DateTime->now( time_zone => 'Europe/Berlin' ), dep_platform => $stop->{platform}, train_type => $journey->type // q{}, @@ -724,16 +724,16 @@ sub update_arrival_hafas { push( @route, [ - $j_stop->name, - $j_stop->eva, + $j_stop->loc->name, + $j_stop->loc->eva, { - sched_arr => _epoch( $j_stop->{sched_arr} ), - sched_dep => _epoch( $j_stop->{sched_dep} ), - rt_arr => _epoch( $j_stop->{rt_arr} ), - rt_dep => _epoch( $j_stop->{rt_dep} ), - arr_delay => $j_stop->{arr_delay}, - dep_delay => $j_stop->{dep_delay}, - load => $j_stop->{load} + sched_arr => _epoch( $j_stop->sched_arr ), + sched_dep => _epoch( $j_stop->sched_dep ), + rt_arr => _epoch( $j_stop->rt_arr ), + rt_dep => _epoch( $j_stop->rt_dep ), + arr_delay => $j_stop->arr_delay, + dep_delay => $j_stop->dep_delay, + load => $j_stop->load } ] ); diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm index 147219f..5bbe781 100644 --- a/lib/Travelynx/Model/Stations.pm +++ b/lib/Travelynx/Model/Stations.pm @@ -17,33 +17,34 @@ sub new { sub add_or_update { my ( $self, %opt ) = @_; my $stop = $opt{stop}; + my $loc = $stop->loc; my $source = 1; my $db = $opt{db} // $self->{pg}->db; - if ( my $s = $self->get_by_eva( $stop->eva, db => $db ) ) { + if ( my $s = $self->get_by_eva( $loc->eva, db => $db ) ) { if ( $source == 1 and $s->{source} == 0 and not $s->{archived} ) { return; } $db->update( 'stations', { - name => $stop->name, - lat => $stop->lat, - lon => $stop->lon, + name => $loc->name, + lat => $loc->lat, + lon => $loc->lon, source => $source, archived => 0 }, - { eva => $stop->eva } + { eva => $loc->eva } ); return; } $db->insert( 'stations', { - eva => $stop->eva, - name => $stop->name, - lat => $stop->lat, - lon => $stop->lon, + eva => $loc->eva, + name => $loc->name, + lat => $loc->lat, + lon => $loc->lon, source => $source, archived => 0 } -- cgit v1.2.3