Store journey backend; do not rely on '|' in ID to distinguish IRIS/HAFAS
This is in preparation for supporting multiple HAFAS backends, and possibly EFA and RIS::Journeys.
This commit is contained in:
parent
c969424c2d
commit
f71348a8a8
4 changed files with 128 additions and 1 deletions
|
@ -1946,6 +1946,110 @@ my @migrations = (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# v51 -> v52
|
||||||
|
# Explicitly encode backend type; preparation for multiple hAFAS backends
|
||||||
|
sub {
|
||||||
|
my ($db) = @_;
|
||||||
|
$db->query(
|
||||||
|
qq{
|
||||||
|
create table backends (
|
||||||
|
id smallserial not null primary key,
|
||||||
|
iris bool not null,
|
||||||
|
hafas bool not null,
|
||||||
|
efa bool not null,
|
||||||
|
ris bool not null,
|
||||||
|
name varchar(32) not null,
|
||||||
|
unique (iris, hafas, efa, ris, name)
|
||||||
|
);
|
||||||
|
insert into backends (id, iris, hafas, efa, ris, name) values (0, true, false, false, false, '');
|
||||||
|
insert into backends (id, iris, hafas, efa, ris, name) values (1, false, true, false, false, 'DB');
|
||||||
|
alter sequence backends_id_seq restart with 2;
|
||||||
|
alter table in_transit add column backend_id smallint references backends (id);
|
||||||
|
alter table journeys add column backend_id smallint references backends (id);
|
||||||
|
update in_transit set backend_id = 0 where train_id not like '%|%';
|
||||||
|
update journeys set backend_id = 0 where train_id not like '%|%';
|
||||||
|
update in_transit set backend_id = 1 where train_id like '%|%';
|
||||||
|
update journeys set backend_id = 1 where train_id like '%|%';
|
||||||
|
update journeys set backend_id = 1 where train_id = 'manual';
|
||||||
|
alter table in_transit alter column backend_id set not null;
|
||||||
|
alter table journeys alter column backend_id set not null;
|
||||||
|
|
||||||
|
drop view in_transit_str;
|
||||||
|
drop view journeys_str;
|
||||||
|
create view in_transit_str as select
|
||||||
|
user_id,
|
||||||
|
backend.iris as is_iris, backend.hafas as is_hafas,
|
||||||
|
backend.efa as is_efa, backend.ris as is_ris,
|
||||||
|
backend.name as backend_name,
|
||||||
|
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,
|
||||||
|
coalesce(visibility, users.public_level & 127) as effective_visibility,
|
||||||
|
cancelled, route, messages, user_data,
|
||||||
|
dep_platform, arr_platform, data
|
||||||
|
from in_transit
|
||||||
|
left join polylines on polylines.id = polyline_id
|
||||||
|
left join users on users.id = user_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
|
||||||
|
left join backends as backend on backend_id = backend.id
|
||||||
|
;
|
||||||
|
create view journeys_str as select
|
||||||
|
journeys.id as journey_id, user_id,
|
||||||
|
backend.iris as is_iris, backend.hafas as is_hafas,
|
||||||
|
backend.efa as is_efa, backend.ris as is_ris,
|
||||||
|
backend.name as backend_name,
|
||||||
|
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,
|
||||||
|
polylines.polyline as polyline,
|
||||||
|
visibility,
|
||||||
|
coalesce(visibility, users.public_level & 127) as effective_visibility,
|
||||||
|
cancelled, edited, route, messages, user_data,
|
||||||
|
dep_platform, arr_platform
|
||||||
|
from journeys
|
||||||
|
left join polylines on polylines.id = polyline_id
|
||||||
|
left join users on users.id = user_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
|
||||||
|
left join backends as backend on backend_id = backend.id
|
||||||
|
;
|
||||||
|
update schema_version set version = 52;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
sub sync_stations {
|
sub sync_stations {
|
||||||
|
|
|
@ -102,6 +102,8 @@ sub add {
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
|
|
||||||
if ($train) {
|
if ($train) {
|
||||||
|
my $backend_id
|
||||||
|
= $db->select( 'backends', ['id'], { iris => 1 } )->hash->{id};
|
||||||
$db->insert(
|
$db->insert(
|
||||||
'in_transit',
|
'in_transit',
|
||||||
{
|
{
|
||||||
|
@ -127,10 +129,19 @@ sub add {
|
||||||
: 0
|
: 0
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
backend_id => $backend_id,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
elsif ( $journey and $stop ) {
|
elsif ( $journey and $stop ) {
|
||||||
|
my $backend_id = $db->select(
|
||||||
|
'backends',
|
||||||
|
['id'],
|
||||||
|
{
|
||||||
|
hafas => 1,
|
||||||
|
name => 'DB'
|
||||||
|
}
|
||||||
|
)->hash->{id};
|
||||||
my @route;
|
my @route;
|
||||||
my $product = $journey->product_at( $stop->loc->eva )
|
my $product = $journey->product_at( $stop->loc->eva )
|
||||||
// $journey->product;
|
// $journey->product;
|
||||||
|
@ -173,6 +184,7 @@ sub add {
|
||||||
real_departure => $stop->{rt_dep} // $stop->{sched_dep},
|
real_departure => $stop->{rt_dep} // $stop->{sched_dep},
|
||||||
route => $json->encode( \@route ),
|
route => $json->encode( \@route ),
|
||||||
data => JSON->new->encode( { rt => $stop->{rt_dep} ? 1 : 0 } ),
|
data => JSON->new->encode( { rt => $stop->{rt_dep} ? 1 : 0 } ),
|
||||||
|
backend_id => $backend_id,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,7 @@ sub add {
|
||||||
edited => 0x3fff,
|
edited => 0x3fff,
|
||||||
cancelled => $opt{cancelled} ? 1 : 0,
|
cancelled => $opt{cancelled} ? 1 : 0,
|
||||||
route => JSON->new->encode( \@route ),
|
route => JSON->new->encode( \@route ),
|
||||||
|
backend_id => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( $opt{comment} ) {
|
if ( $opt{comment} ) {
|
||||||
|
@ -515,7 +516,7 @@ sub get {
|
||||||
|
|
||||||
my @select
|
my @select
|
||||||
= (
|
= (
|
||||||
qw(journey_id train_type train_line train_no checkin_ts sched_dep_ts real_dep_ts dep_eva dep_ds100 dep_name dep_lat dep_lon checkout_ts sched_arr_ts real_arr_ts arr_eva arr_ds100 arr_name arr_lat arr_lon cancelled edited route messages user_data visibility effective_visibility)
|
qw(journey_id is_iris is_hafas backend_name train_type train_line train_no checkin_ts sched_dep_ts real_dep_ts dep_eva dep_ds100 dep_name dep_lat dep_lon checkout_ts sched_arr_ts real_arr_ts arr_eva arr_ds100 arr_name arr_lat arr_lon cancelled edited route messages user_data visibility effective_visibility)
|
||||||
);
|
);
|
||||||
my %where = (
|
my %where = (
|
||||||
user_id => $uid,
|
user_id => $uid,
|
||||||
|
@ -573,6 +574,9 @@ sub get {
|
||||||
|
|
||||||
my $ref = {
|
my $ref = {
|
||||||
id => $entry->{journey_id},
|
id => $entry->{journey_id},
|
||||||
|
is_iris => $entry->{is_iris},
|
||||||
|
is_hafas => $entry->{is_hafas},
|
||||||
|
backend_name => $entry->{backend_name},
|
||||||
type => $entry->{train_type},
|
type => $entry->{train_type},
|
||||||
line => $entry->{train_line},
|
line => $entry->{train_line},
|
||||||
no => $entry->{train_no},
|
no => $entry->{train_no},
|
||||||
|
|
|
@ -261,6 +261,13 @@
|
||||||
% if (stash('polyline_groups')) {
|
% if (stash('polyline_groups')) {
|
||||||
%= include '_map', station_coordinates => stash('station_coordinates'), polyline_groups => stash('polyline_groups')
|
%= include '_map', station_coordinates => stash('station_coordinates'), polyline_groups => stash('polyline_groups')
|
||||||
% }
|
% }
|
||||||
|
<div class="row">
|
||||||
|
<div class="col s12">
|
||||||
|
Backend:
|
||||||
|
<i class="material-icons tiny" aria-hidden="true"><%= $journey->{is_iris} ? 'train' : 'directions' %></i>
|
||||||
|
%= $journey->{backend_name} || 'IRIS'
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
% if (not stash('readonly')) {
|
% if (not stash('readonly')) {
|
||||||
% if (stash('with_share')) {
|
% if (stash('with_share')) {
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
Loading…
Reference in a new issue