Switch to Travel::Status::DE::HAFAS 5.x
This commit is contained in:
parent
c24edf3027
commit
d47195a0cf
6 changed files with 49 additions and 47 deletions
2
cpanfile
2
cpanfile
|
@ -15,7 +15,7 @@ requires 'Mojo::Pg';
|
|||
requires 'Text::CSV';
|
||||
requires 'Text::Markdown';
|
||||
requires 'Travel::Status::DE::DBWagenreihung';
|
||||
requires 'Travel::Status::DE::HAFAS', '== 4.19';
|
||||
requires 'Travel::Status::DE::HAFAS', '>= 5.03';
|
||||
requires 'Travel::Status::DE::IRIS';
|
||||
requires 'UUID::Tiny';
|
||||
requires 'JSON';
|
||||
|
|
|
@ -541,7 +541,8 @@ sub startup {
|
|||
my ($journey) = @_;
|
||||
my $found;
|
||||
for my $stop ( $journey->route ) {
|
||||
if ( $stop->name eq $station or $stop->eva == $station )
|
||||
if ( $stop->loc->name eq $station
|
||||
or $stop->loc->eva == $station )
|
||||
{
|
||||
$found = $stop;
|
||||
last;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue