SQL Para carga GTFS

francisco/photos
Ronald Morales 2024-01-26 21:00:49 -03:00
parent 1a79bf8dd7
commit 5407854077
1 changed files with 50 additions and 12 deletions

View File

@ -6,7 +6,7 @@ ALTER TABLE rol_linea drop CONSTRAINT IF EXISTS rol_linea_id_linea_fkey;
ALTER TABLE linea_paradero drop CONSTRAINT IF EXISTS linea_paradero_id_linea_fkey; ALTER TABLE linea_paradero drop CONSTRAINT IF EXISTS linea_paradero_id_linea_fkey;
----- -----
/*
update operador update operador
set vigente =false set vigente =false
where id_operador not in (select agency_id from z_agency za); where id_operador not in (select agency_id from z_agency za);
@ -26,7 +26,7 @@ from z_agency za
where agency_id not in (select id_operador from operador za); where agency_id not in (select id_operador from operador za);
----- -----
*/
delete from gtfs_calendar ; delete from gtfs_calendar ;
----- -----
@ -36,11 +36,11 @@ select service_id, monday::bool , tuesday::bool , wednesday::bool , thursday::bo
from z_calendar zc; from z_calendar zc;
----- -----
/*
update paradero p update paradero p
set vigente = false set vigente = false
where id_paradero::text not in (select stop_id from z_stops ); where id_paradero::text not in (select stop_id from z_stops );
*/
----- -----
update paradero update paradero
@ -69,55 +69,92 @@ delete from linea_paradero;
----- -----
delete from linea ; /*delete from linea*/ ;
----- -----
update linea
set vigente = false
where id_red in (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' )
and id_linea not in (select trim(zr.route_id)||'-'||trim(zt.direction_id::varchar)
from z_routes zr
inner join z_trips zt
on zr.route_id =zt.route_id
);
update linea
set vigente = true
where id_red in (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' )
and id_linea in (select trim(zr.route_id)||'-'||trim(zt.direction_id::varchar)
from z_routes zr
inner join z_trips zt
on zr.route_id =zt.route_id
);
/*
update linea
route_short_name = (select substring(zt.trip_headsign FROM '(\S+) -') as route_short_name )
route_desc =
route_type =
route_url
route_color
route_text_color
route_long_name
vigente
id_red = (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1)
id_linea
*/
insert into linea insert into linea
select distinct select distinct
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
zr.agency_id , null,--zr.agency_id ,
substring(zt.trip_headsign FROM '(\S+) -') as route_short_name , substring(zt.trip_headsign FROM '(\S+) -') as route_short_name ,
zr.route_desc , zr.route_desc ,
zr.route_type::numeric , zr.route_type::numeric ,
zr.route_url, zr.route_url,
zr.route_color , zr.route_color ,
zr.route_text_color , zr.route_text_color ,
zt.trip_headsign as route_long_name , true zt.trip_headsign as route_long_name , true ,
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red
from z_routes zr from z_routes zr
inner join z_trips zt inner join z_trips zt
on zr.route_id =zt.route_id on zr.route_id =zt.route_id
and replace (zt.trip_headsign,' ','') =replace ((SPLIT_PART(route_long_name, '-', 1)||'-'||SPLIT_PART(route_long_name, '-', 2)),' ','') and replace (zt.trip_headsign,' ','') =replace ((SPLIT_PART(route_long_name, '-', 1)||'-'||SPLIT_PART(route_long_name, '-', 2)),' ','')
where route_long_name not like '%'||route_short_name ||'%' where route_long_name not like '%'||route_short_name ||'%'
and (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
union union
select distinct select distinct
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
zr.agency_id , null,--zr.agency_id ,
substring(zt.trip_headsign FROM '(\S+) -') as route_short_name , substring(zt.trip_headsign FROM '(\S+) -') as route_short_name ,
zr.route_desc , zr.route_desc ,
zr.route_type::numeric , zr.route_type::numeric ,
zr.route_url, zr.route_url,
zr.route_color , zr.route_color ,
zr.route_text_color , zr.route_text_color ,
zt.trip_headsign as route_long_name , true zt.trip_headsign as route_long_name , true ,
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red
from z_routes zr from z_routes zr
inner join z_trips zt inner join z_trips zt
on zr.route_id =zt.route_id on zr.route_id =zt.route_id
and replace (zt.trip_headsign,' ','') =replace ((SPLIT_PART(route_long_name, '-', 3)||'-'||SPLIT_PART(route_long_name, '-', 4)),' ','') and replace (zt.trip_headsign,' ','') =replace ((SPLIT_PART(route_long_name, '-', 3)||'-'||SPLIT_PART(route_long_name, '-', 4)),' ','')
where route_long_name not like '%'||route_short_name ||'%' where route_long_name not like '%'||route_short_name ||'%'
and (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
union union
select distinct select distinct
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
zr.agency_id , null,--zr.agency_id ,
route_short_name , route_short_name ,
zr.route_desc , zr.route_desc ,
zr.route_type::numeric , zr.route_type::numeric ,
zr.route_url, zr.route_url,
zr.route_color , zr.route_color ,
zr.route_text_color , zr.route_text_color ,
zt.trip_headsign as route_long_name , true zt.trip_headsign as route_long_name , true ,
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red
from z_routes zr from z_routes zr
inner join z_trips zt inner join z_trips zt
on zr.route_id =zt.route_id on zr.route_id =zt.route_id
@ -126,6 +163,7 @@ select distinct
or or
route_long_name like '%'||route_short_name ||'%' route_long_name like '%'||route_short_name ||'%'
) )
where (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
order by 1; order by 1;
----- -----