Update HAFAS polylines prior to checkout
In case of diversions, the polyline fetched at checkin time may no longer be accurate. Request a new polyline prior to checkout to address this. Closes #66
This commit is contained in:
parent
e4e660e839
commit
852c7797b0
3 changed files with 62 additions and 11 deletions
|
@ -803,7 +803,7 @@ sub startup {
|
||||||
}
|
}
|
||||||
if ( not $opt{in_transaction} ) {
|
if ( not $opt{in_transaction} ) {
|
||||||
$self->run_hook( $uid, 'update' );
|
$self->run_hook( $uid, 'update' );
|
||||||
$self->add_route_timestamps( $uid, $train, 0 );
|
$self->add_route_timestamps( $uid, $train, 0, 1 );
|
||||||
}
|
}
|
||||||
return ( 1, undef );
|
return ( 1, undef );
|
||||||
}
|
}
|
||||||
|
@ -901,7 +901,7 @@ sub startup {
|
||||||
|
|
||||||
$self->helper(
|
$self->helper(
|
||||||
'add_route_timestamps' => sub {
|
'add_route_timestamps' => sub {
|
||||||
my ( $self, $uid, $train, $is_departure ) = @_;
|
my ( $self, $uid, $train, $is_departure, $update_polyline ) = @_;
|
||||||
|
|
||||||
$uid //= $self->current_user->{id};
|
$uid //= $self->current_user->{id};
|
||||||
|
|
||||||
|
@ -909,20 +909,20 @@ sub startup {
|
||||||
|
|
||||||
# TODO "with_timestamps" is misleading, there are more differences between in_transit and in_transit_str
|
# TODO "with_timestamps" is misleading, there are more differences between in_transit and in_transit_str
|
||||||
# Here it's only needed because of dep_eva / arr_eva names
|
# Here it's only needed because of dep_eva / arr_eva names
|
||||||
my $journey = $self->in_transit->get(
|
my $in_transit = $self->in_transit->get(
|
||||||
db => $db,
|
db => $db,
|
||||||
uid => $uid,
|
uid => $uid,
|
||||||
with_data => 1,
|
with_data => 1,
|
||||||
with_timestamps => 1
|
with_timestamps => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( not $journey ) {
|
if ( not $in_transit ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($platform) = ( ( $train->platform // 0 ) =~ m{(\d+)} );
|
my ($platform) = ( ( $train->platform // 0 ) =~ m{(\d+)} );
|
||||||
|
|
||||||
my $route = $journey->{route};
|
my $route = $in_transit->{route};
|
||||||
|
|
||||||
my $base
|
my $base
|
||||||
= 'https://reiseauskunft.bahn.de/bin/trainsearch.exe/dn?L=vs_json.vs_hap&start=yes&rt=1';
|
= 'https://reiseauskunft.bahn.de/bin/trainsearch.exe/dn?L=vs_json.vs_hap&start=yes&rt=1';
|
||||||
|
@ -988,7 +988,10 @@ sub startup {
|
||||||
return $self->hafas->get_route_timestamps_p(
|
return $self->hafas->get_route_timestamps_p(
|
||||||
train => $train,
|
train => $train,
|
||||||
trip_id => $trip_id,
|
trip_id => $trip_id,
|
||||||
with_polyline => not $journey->{polyline}
|
with_polyline => (
|
||||||
|
$update_polyline
|
||||||
|
or not $in_transit->{polyline}
|
||||||
|
) ? 1 : 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)->then(
|
)->then(
|
||||||
|
@ -1085,7 +1088,12 @@ sub startup {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($polyline_id) {
|
if (
|
||||||
|
$polyline_id
|
||||||
|
and ( not $in_transit->{polyline_id}
|
||||||
|
or $polyline_id != $in_transit->{polyline_id} )
|
||||||
|
)
|
||||||
|
{
|
||||||
$self->in_transit->set_polyline_id(
|
$self->in_transit->set_polyline_id(
|
||||||
uid => $uid,
|
uid => $uid,
|
||||||
db => $db,
|
db => $db,
|
||||||
|
@ -1189,7 +1197,7 @@ sub startup {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_departure) {
|
if ($is_departure) {
|
||||||
$self->dbdb->get_stationinfo_p( $journey->{dep_eva} )->then(
|
$self->dbdb->get_stationinfo_p( $in_transit->{dep_eva} )->then(
|
||||||
sub {
|
sub {
|
||||||
my ($station_info) = @_;
|
my ($station_info) = @_;
|
||||||
my $data = { stationinfo_dep => $station_info };
|
my $data = { stationinfo_dep => $station_info };
|
||||||
|
@ -1209,8 +1217,8 @@ sub startup {
|
||||||
)->wait;
|
)->wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $journey->{arr_eva} and not $is_departure ) {
|
if ( $in_transit->{arr_eva} and not $is_departure ) {
|
||||||
$self->dbdb->get_stationinfo_p( $journey->{arr_eva} )->then(
|
$self->dbdb->get_stationinfo_p( $in_transit->{arr_eva} )->then(
|
||||||
sub {
|
sub {
|
||||||
my ($station_info) = @_;
|
my ($station_info) = @_;
|
||||||
my $data = { stationinfo_arr => $station_info };
|
my $data = { stationinfo_arr => $station_info };
|
||||||
|
|
|
@ -1428,6 +1428,48 @@ my @migrations = (
|
||||||
}
|
}
|
||||||
$db->update( 'schema_version', { version => 33 } );
|
$db->update( 'schema_version', { version => 33 } );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# v33 -> v34
|
||||||
|
# add polyline_id to in_transit_str
|
||||||
|
# (https://github.com/derf/travelynx/issues/66)
|
||||||
|
sub {
|
||||||
|
my ($db) = @_;
|
||||||
|
$db->query(
|
||||||
|
qq{
|
||||||
|
drop view in_transit_str;
|
||||||
|
create view in_transit_str as select
|
||||||
|
user_id,
|
||||||
|
train_type, train_line, train_no, train_id,
|
||||||
|
extract(epoch from checkin_time) as checkin_ts,
|
||||||
|
extract(epoch from sched_departure) as sched_dep_ts,
|
||||||
|
extract(epoch from real_departure) as real_dep_ts,
|
||||||
|
checkin_station_id as dep_eva,
|
||||||
|
dep_station.ds100 as dep_ds100,
|
||||||
|
dep_station.name as dep_name,
|
||||||
|
dep_station.lat as dep_lat,
|
||||||
|
dep_station.lon as dep_lon,
|
||||||
|
extract(epoch from checkout_time) as checkout_ts,
|
||||||
|
extract(epoch from sched_arrival) as sched_arr_ts,
|
||||||
|
extract(epoch from real_arrival) as real_arr_ts,
|
||||||
|
checkout_station_id as arr_eva,
|
||||||
|
arr_station.ds100 as arr_ds100,
|
||||||
|
arr_station.name as arr_name,
|
||||||
|
arr_station.lat as arr_lat,
|
||||||
|
arr_station.lon as arr_lon,
|
||||||
|
polyline_id,
|
||||||
|
polylines.polyline as polyline,
|
||||||
|
visibility,
|
||||||
|
cancelled, route, messages, user_data,
|
||||||
|
dep_platform, arr_platform, data
|
||||||
|
from in_transit
|
||||||
|
left join polylines on polylines.id = polyline_id
|
||||||
|
left join stations as dep_station on checkin_station_id = dep_station.eva
|
||||||
|
left join stations as arr_station on checkout_station_id = arr_station.eva
|
||||||
|
;
|
||||||
|
update schema_version set version = 34;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
sub sync_stations {
|
sub sync_stations {
|
||||||
|
|
|
@ -164,7 +164,8 @@ sub run {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->app->add_route_timestamps( $uid, $train, 0 );
|
$self->app->add_route_timestamps( $uid, $train, 0,
|
||||||
|
$now->epoch > $entry->{real_arr_ts} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $entry->{real_arr_ts} ) {
|
elsif ( $entry->{real_arr_ts} ) {
|
||||||
|
|
Loading…
Reference in a new issue