2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
ALTER TABLE linea_paradero drop CONSTRAINT IF EXISTS linea_paradero_id_linea_fkey;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
2024-02-04 17:22:21 -03:00
|
|
|
ALTER TABLE gtfs_stop_times drop CONSTRAINT IF EXISTS fk_gtfs_sto_reference_gtfs_tri;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
ALTER TABLE gtfs_frequencie drop CONSTRAINT IF EXISTS fk_gtfs_fre_reference_gtfs_tri;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
DELETE FROM gtfs_calendar;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
insert into gtfs_calendar
|
|
|
|
select service_id, monday::bool , tuesday::bool , wednesday::bool , thursday::bool ,friday::bool ,saturday::bool ,sunday::bool
|
|
|
|
from z_calendar zc;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
update paradero
|
|
|
|
set vigente = true,
|
|
|
|
stop_name= (select stop_name from z_stops where stop_id=paradero.id_paradero::text limit 1 ),
|
|
|
|
stop_desc=(select stop_desc from z_stops where stop_id=paradero.id_paradero::text limit 1 ),
|
|
|
|
stop_lat =(select stop_lat from z_stops where stop_id=paradero.id_paradero::text limit 1)::float(8),
|
|
|
|
stop_lon =(select stop_lon from z_stops where stop_id=paradero.id_paradero::text limit 1)::float(8),
|
|
|
|
stop_code=(select stop_code from z_stops where stop_id=paradero.id_paradero::text limit 1)
|
|
|
|
where id_paradero::text in (select stop_id from z_stops );
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
insert into paradero
|
|
|
|
select
|
|
|
|
stop_id, null as id_comuna, null as id_tipo_paradero, true,
|
|
|
|
stop_code , stop_name , stop_desc , stop_lat::float(8) , stop_lon::float(8) , zone_id ,
|
|
|
|
stop_url , location_type ,
|
|
|
|
parent_station ,null as stop_time_zone , wheelchair_boarding::numeric
|
|
|
|
from z_stops zs
|
|
|
|
where stop_id not in (select id_paradero::text from paradero);
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
2024-03-02 18:10:38 -03:00
|
|
|
delete from linea_paradero;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
delete from linea;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
2024-02-01 12:28:51 -03:00
|
|
|
|
2024-01-26 21:00:49 -03:00
|
|
|
update linea
|
|
|
|
set vigente = false
|
|
|
|
where id_red in (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' )
|
2024-02-04 17:22:21 -03:00
|
|
|
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
|
|
|
|
);
|
2024-01-26 21:00:49 -03:00
|
|
|
|
2024-02-01 12:28:51 -03:00
|
|
|
-----
|
|
|
|
|
2024-01-26 21:00:49 -03:00
|
|
|
update linea
|
|
|
|
set vigente = true
|
|
|
|
where id_red in (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' )
|
2024-02-04 17:22:21 -03:00
|
|
|
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
|
|
|
|
);
|
2024-01-26 21:00:49 -03:00
|
|
|
|
2024-02-01 12:28:51 -03:00
|
|
|
-----
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
insert into linea
|
|
|
|
select distinct
|
|
|
|
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
|
2024-01-26 21:00:49 -03:00
|
|
|
null,--zr.agency_id ,
|
2024-01-20 14:18:32 -03:00
|
|
|
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 ,
|
2024-01-26 21:00:49 -03:00
|
|
|
zt.trip_headsign as route_long_name , true ,
|
|
|
|
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red
|
2024-01-20 14:18:32 -03:00
|
|
|
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 ||'%'
|
2024-01-26 21:00:49 -03:00
|
|
|
and (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
|
2024-01-20 14:18:32 -03:00
|
|
|
union
|
|
|
|
select distinct
|
|
|
|
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
|
2024-01-26 21:00:49 -03:00
|
|
|
null,--zr.agency_id ,
|
2024-01-20 14:18:32 -03:00
|
|
|
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 ,
|
2024-01-26 21:00:49 -03:00
|
|
|
zt.trip_headsign as route_long_name , true ,
|
|
|
|
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red
|
2024-01-20 14:18:32 -03:00
|
|
|
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 ||'%'
|
2024-01-26 21:00:49 -03:00
|
|
|
and (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
|
2024-01-20 14:18:32 -03:00
|
|
|
union
|
|
|
|
select distinct
|
|
|
|
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
|
2024-01-26 21:00:49 -03:00
|
|
|
null,--zr.agency_id ,
|
2024-01-20 14:18:32 -03:00
|
|
|
route_short_name ,
|
|
|
|
zr.route_desc ,
|
|
|
|
zr.route_type::numeric ,
|
|
|
|
zr.route_url,
|
|
|
|
zr.route_color ,
|
|
|
|
zr.route_text_color ,
|
2024-01-26 21:00:49 -03:00
|
|
|
zt.trip_headsign as route_long_name , true ,
|
|
|
|
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red
|
2024-01-20 14:18:32 -03:00
|
|
|
from z_routes zr
|
|
|
|
inner join z_trips zt
|
|
|
|
on zr.route_id =zt.route_id
|
|
|
|
and
|
|
|
|
( position('-' in zt.trip_headsign) = 0
|
|
|
|
or
|
|
|
|
route_long_name like '%'||route_short_name ||'%'
|
|
|
|
)
|
2024-01-26 21:00:49 -03:00
|
|
|
where (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
|
2024-01-20 14:18:32 -03:00
|
|
|
order by 1;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
2024-02-04 17:22:21 -03:00
|
|
|
truncate table gtfs_shape;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
insert into gtfs_shape
|
|
|
|
select shape_id::numeric,shape_pt_lat::float8,shape_pt_lon::float8,
|
|
|
|
shape_pt_sequence::numeric,shape_dist_traveled::float8
|
|
|
|
from z_shapes zs;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
2024-02-04 17:22:21 -03:00
|
|
|
truncate table gtfs_stop_times;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
2024-02-04 17:22:21 -03:00
|
|
|
truncate table gtfs_frequencie;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
2024-02-04 17:22:21 -03:00
|
|
|
truncate table gtfs_trips;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
insert into gtfs_trips
|
|
|
|
select
|
|
|
|
trip_id,
|
|
|
|
trim(route_id)||'-'||trim(direction_id::varchar) as route_id,
|
|
|
|
shape_id::numeric ,null as regreso, trip_headsign,trip_short_name,direction_id::numeric,service_id::varchar,block_id
|
2024-02-04 17:22:21 -03:00
|
|
|
from z_trips zt;
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
insert into gtfs_stop_times
|
|
|
|
select stop_id,trip_id,arrival_time,stop_sequence::numeric,stop_headsign,departure_time,drop_off_type::numeric,null as shape_dist_traveled ,
|
|
|
|
timepoint::numeric , pickup_type::numeric
|
|
|
|
from z_stop_times zst ;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
insert into linea_paradero (id_linea , id_paradero )
|
|
|
|
SELECT DISTINCT
|
|
|
|
l.id_linea , p.id_paradero
|
|
|
|
FROM linea l
|
|
|
|
JOIN gtfs_trips t ON l.id_linea =t.id_linea
|
|
|
|
JOIN gtfs_stop_times st ON t.id_trip = st.id_trip
|
|
|
|
JOIN paradero p ON st.id_paradero = p.id_paradero;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
UPDATE paradero
|
|
|
|
SET stop_name = REGEXP_REPLACE(
|
|
|
|
REGEXP_REPLACE(
|
|
|
|
stop_name,
|
|
|
|
'\yentre\y',
|
|
|
|
'-entre',
|
|
|
|
'gi'
|
|
|
|
),
|
|
|
|
'\yesq\y',
|
|
|
|
'-esq',
|
|
|
|
'gi'
|
|
|
|
);
|
|
|
|
|
2024-01-29 20:18:11 -03:00
|
|
|
-----
|
2024-02-04 17:22:21 -03:00
|
|
|
update paradero
|
|
|
|
set id_comuna = (select id_comuna from comuna_georeferencia as c where ST_Contains(c.geom, ST_SetSRID(ST_MakePoint(paradero.stop_lon, paradero.stop_lat), 4326)) limit 1)
|
|
|
|
where id_comuna is not null;
|
|
|
|
-----
|
|
|
|
|
2024-03-02 18:10:38 -03:00
|
|
|
insert into dispositivo
|
|
|
|
select 'QRCode-'||id_paradero , id_paradero , true, null, 3
|
|
|
|
from paradero as p where id_paradero
|
|
|
|
not in (select id_paradero from dispositivo as d where id_tipo_dispositivo=3 and d.id_paradero = p.id_paradero);
|
2024-01-20 14:18:32 -03:00
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
ALTER TABLE linea_paradero ADD CONSTRAINT linea_paradero_id_linea_fkey FOREIGN KEY (id_linea) REFERENCES linea(id_linea);
|
|
|
|
|
2024-02-04 17:22:21 -03:00
|
|
|
-----
|
|
|
|
|
|
|
|
ALTER TABLE gtfs_stop_times ADD CONSTRAINT fk_gtfs_sto_reference_gtfs_tri FOREIGN KEY (id_trip) REFERENCES gtfs_trips(id_trip) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
ALTER TABLE gtfs_frequencie ADD CONSTRAINT fk_gtfs_fre_reference_gtfs_tri FOREIGN KEY (id_trip) REFERENCES gtfs_trips(id_trip) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
|
|
|
|
2024-01-20 14:18:32 -03:00
|
|
|
-----
|