diff --git a/project/api/views/actualiza_GTFS.sql b/project/api/views/actualiza_GTFS.sql index d902ea0..2f73bc2 100644 --- a/project/api/views/actualiza_GTFS.sql +++ b/project/api/views/actualiza_GTFS.sql @@ -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; ----- - +/* update operador set vigente =false 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); ----- - +*/ delete from gtfs_calendar ; ----- @@ -36,11 +36,11 @@ select service_id, monday::bool , tuesday::bool , wednesday::bool , thursday::bo from z_calendar zc; ----- - +/* update paradero p set vigente = false where id_paradero::text not in (select stop_id from z_stops ); - +*/ ----- 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 select distinct 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 , zr.route_desc , zr.route_type::numeric , zr.route_url, zr.route_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 inner join z_trips zt 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)),' ','') 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 select distinct 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 , zr.route_desc , zr.route_type::numeric , zr.route_url, zr.route_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 inner join z_trips zt 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)),' ','') 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 select distinct trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, - zr.agency_id , + null,--zr.agency_id , route_short_name , zr.route_desc , zr.route_type::numeric , zr.route_url, zr.route_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 inner join z_trips zt on zr.route_id =zt.route_id @@ -126,6 +163,7 @@ select distinct or 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; -----