diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travelynx/Model/InTransit.pm | 107 | ||||
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 18 |
2 files changed, 80 insertions, 45 deletions
diff --git a/lib/Travelynx/Model/InTransit.pm b/lib/Travelynx/Model/InTransit.pm index ab724a4..d0a7c2b 100644 --- a/lib/Travelynx/Model/InTransit.pm +++ b/lib/Travelynx/Model/InTransit.pm @@ -154,20 +154,22 @@ sub add { $j_stop->full_name, $j_stop->id_num, { - 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 ), - isCancelled => $j_stop->is_cancelled, - arr_delay => $j_stop->arr_delay, - dep_delay => $j_stop->dep_delay, - platform => $j_stop->platform, - efa_load => $j_stop->occupancy, - lat => $j_stop->latlon->[0], - lon => $j_stop->latlon->[1], + 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, + platform => $j_stop->platform, + efa_load => $j_stop->occupancy, + lat => $j_stop->latlon->[0], + lon => $j_stop->latlon->[1], } ] ); + if ( $j_stop->is_cancelled ) { + $route[-1][2]{isCancelled} = 1; + } } $persistent_data->{operator} = $journey->operator; $db->insert( @@ -280,15 +282,14 @@ sub add { $j_stop->name, $j_stop->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 ), - isCancelled => $j_stop->is_cancelled, - arr_delay => $j_stop->arr_delay, - dep_delay => $j_stop->dep_delay, - platform => $j_stop->platform, - 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, + platform => $j_stop->platform, + load => { FIRST => $j_stop->occupancy_first, SECOND => $j_stop->occupancy_second }, @@ -297,6 +298,12 @@ sub add { } ] ); + if ( $j_stop->is_additional ) { + $route[-1][2]{isAdditional} = 1; + } + if ( $j_stop->is_cancelled ) { + $route[-1][2]{isCancelled} = 1; + } } my @messages; for my $msg ( $journey->messages ) { @@ -517,6 +524,14 @@ sub postprocess { $ret->{comment} = $ret->{user_data}{comment}; $ret->{wagongroups} = $ret->{user_data}{wagongroups}; + if ( $ret->{sched_dep_ts} and $ret->{real_dep_ts} ) { + $ret->{dep_delay} = $ret->{real_dep_ts} - $ret->{sched_dep_ts}; + } + + if ( $ret->{sched_arr_ts} and $ret->{real_arr_ts} ) { + $ret->{arr_delay} = $ret->{real_arr_ts} - $ret->{sched_arr_ts}; + } + $ret->{platform_type} = 'Gleis'; if ( $ret->{train_type} and $ret->{train_type} =~ m{ ast | bus | ruf }ix ) { $ret->{platform_type} = 'Steig'; @@ -1249,16 +1264,15 @@ sub update_arrival_dbris { $j_stop->name, $j_stop->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 ), - platform => $j_stop->platform, - isCancelled => $j_stop->is_cancelled, - arr_delay => $j_stop->arr_delay, - dep_delay => $j_stop->dep_delay, - platform => $j_stop->platform, - 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 ), + platform => $j_stop->platform, + arr_delay => $j_stop->arr_delay, + dep_delay => $j_stop->dep_delay, + platform => $j_stop->platform, + load => { FIRST => $j_stop->occupancy_first, SECOND => $j_stop->occupancy_second }, @@ -1267,6 +1281,12 @@ sub update_arrival_dbris { } ] ); + if ( $j_stop->is_additional ) { + $route[-1][2]{isAdditional} = 1; + } + if ( $j_stop->is_cancelled ) { + $route[-1][2]{isCancelled} = 1; + } } # selecting on user_id and train_no avoids a race condition if a user checks @@ -1318,22 +1338,27 @@ sub update_arrival_efa { $j_stop->full_name, $j_stop->id_num, { - 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 ), - isCancelled => $j_stop->is_cancelled, - arr_delay => $j_stop->arr_delay, - dep_delay => $j_stop->dep_delay, - platform => $j_stop->platform, - efa_load => $j_stop->occupancy, - lat => $j_stop->latlon->[0], - lon => $j_stop->latlon->[1], + 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, + platform => $j_stop->platform, + efa_load => $j_stop->occupancy, + lat => $j_stop->latlon->[0], + lon => $j_stop->latlon->[1], } ] ); + if ( $j_stop->is_cancelled ) { + $route[-1][2]{isCancelled} = 1; + } } + # TODO set efa_load from old route entry if missing in current route entry + # (at least in VVO, occupancy data is only provided for future stops) + # selecting on user_id and train_no avoids a race condition if a user checks # into a new train while we are fetching data for their previous journey. In # this case, the new train would receive data from the previous journey. diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 46ad1c0..a6061e6 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -445,13 +445,23 @@ sub update { # Otherwise, fetch stop IDs so that polylines remain usable if ( @new_route != @{ $opt{route} } ) { - my %stop_id - = map { $_->{name} => $_->{eva} } - $self->{stations}->get_by_names( + my %stop + = map { $_->{name} => $_ } $self->{stations}->get_by_names( backend_id => $journey->{backend_id}, names => [ $opt{route} ] ); - @new_route = map { [ $_, $stop_id{$_}, {} ] } @{ $opt{route} }; + @new_route = map { + [ + $_, + $stop{$_}{eva}, + defined $stop{$_}{eva} + ? { + lat => $stop{$_}{lat}, + lon => $stop{$_}{lon} + } + : {} + ] + } @{ $opt{route} }; } $rows = $db->update( |