forked from TDTP/admin_transporte_backend
Compare commits
17 Commits
develop/Ro
...
master
Author | SHA1 | Date |
---|---|---|
|
79dd7c49e5 | |
|
1238da5e08 | |
|
5ff56e9e34 | |
|
e820757cbe | |
|
34071769c4 | |
|
056887f67f | |
|
5ace0c1828 | |
|
d54c08f356 | |
|
e540991ac0 | |
|
a4472baa84 | |
|
99d55c0b36 | |
|
dbaa8ebcfe | |
|
2ae8f790f4 | |
|
8af4239459 | |
|
147e5e3126 | |
|
324d53ff72 | |
|
c36dc582ae |
|
@ -20,8 +20,6 @@ DB_MONGO_PASS=password
|
|||
SMTP_HOST=smtp-mail.outlook.com
|
||||
SMTP_PORT=587
|
||||
SMTP_PROTOCOL=tls
|
||||
SMTP_USER=francisco.sandoval@outlook.cl
|
||||
SMTP_PASS=aigdvnrbueitklry
|
||||
SMTP_FROM='"Sistema Transporte" <francisco.sandoval@outlook.cl>'
|
||||
|
||||
# PATH UPLOAD
|
||||
|
@ -33,4 +31,4 @@ URL_PARADERO='http://localhost:3001/rutaParadero/?id='
|
|||
|
||||
#COORDENADAS DE INICIO PARA EL MAPA
|
||||
COORDINI_LAT=-36.8270
|
||||
COORDINI_LNG=-73.0503
|
||||
COORDINI_LNG=-73.0503
|
||||
|
|
|
@ -14,10 +14,8 @@ DB_REDIS_PORT=6379
|
|||
SMTP_HOST=smtp-mail.outlook.com
|
||||
SMTP_PORT=587
|
||||
SMTP_PROTOCOL=tls
|
||||
SMTP_USER=francisco.sandoval@outlook.cl
|
||||
SMTP_PASS=aigdvnrbueitklry
|
||||
SMTP_FROM='"Sistema Transporte" <francisco.sandoval@outlook.cl>'
|
||||
|
||||
# PATH UPLOAD
|
||||
GTFS_UPLOADS=/uploads/gtfs
|
||||
PHOTOS_UPLOADS=/uploads/photos
|
||||
PHOTOS_UPLOADS=/uploads/photos
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
DO $$
|
||||
DECLARE
|
||||
inicio_vigencia DATE;
|
||||
v_error TEXT := '';
|
||||
v_error TEXT := '';
|
||||
BEGIN
|
||||
|
||||
-- Verificar agency_id único
|
||||
IF (SELECT COUNT(*) FROM (SELECT agency_id FROM z_agency GROUP BY agency_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
update gtfs_archivo
|
||||
set status = 'Error - Agency_id duplicados'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '1 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
END IF;
|
||||
|
||||
|
||||
-- Verificar route_id único
|
||||
IF (SELECT COUNT(*) FROM (SELECT route_id FROM z_routes GROUP BY route_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
IF (SELECT COUNT(*) FROM (SELECT route_id FROM z_routes GROUP BY route_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
set status = 'Error - Route_id duplicados'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '2 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
|
@ -22,15 +22,15 @@ BEGIN
|
|||
|
||||
-- Verificar service_id único en calendar
|
||||
IF (SELECT COUNT(*) FROM (SELECT service_id FROM z_calendar GROUP BY service_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
update gtfs_archivo
|
||||
set status = 'Error - service_id duplicados en calendar'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '3 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
END IF;
|
||||
|
||||
-- Verificar trip_id único
|
||||
IF (SELECT COUNT(*) FROM (SELECT trip_id FROM z_trips GROUP BY trip_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
IF (SELECT COUNT(*) FROM (SELECT trip_id FROM z_trips GROUP BY trip_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
set status = 'Error - Trip_id duplicados '
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '4 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
|
@ -38,31 +38,31 @@ BEGIN
|
|||
|
||||
-- Verificar stop_id único
|
||||
IF (SELECT COUNT(*) FROM (SELECT stop_id FROM z_stops GROUP BY stop_id HAVING COUNT(*) > 1) AS duplicated) > 0 THEN
|
||||
update gtfs_archivo
|
||||
update gtfs_archivo
|
||||
set status = 'Error - Stop_id duplicados'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '5 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
v_error:= '5 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
END IF;
|
||||
|
||||
-- Verificar referencias cruzadas entre trips y routes
|
||||
IF (SELECT COUNT(*) FROM z_trips WHERE route_id NOT IN (SELECT route_id FROM z_routes)) > 0 THEN
|
||||
update gtfs_archivo
|
||||
IF (SELECT COUNT(*) FROM z_trips WHERE route_id NOT IN (SELECT route_id FROM z_routes)) > 0 THEN
|
||||
update gtfs_archivo
|
||||
set status = 'Error - Trips_id con route_id que no existen'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '6 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
END IF;
|
||||
|
||||
-- Verificar referencias cruzadas entre stop_times y trips
|
||||
IF (SELECT COUNT(*) FROM z_stop_times WHERE trip_id NOT IN (SELECT trip_id FROM z_trips)) > 0 THEN
|
||||
update gtfs_archivo
|
||||
IF (SELECT COUNT(*) FROM z_stop_times WHERE trip_id NOT IN (SELECT trip_id FROM z_trips)) > 0 THEN
|
||||
update gtfs_archivo
|
||||
set status = 'Error - Stop_times con trips_id que no existen'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '7 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
END IF;
|
||||
|
||||
-- Verificar referencias cruzadas entre stop_times y stops
|
||||
IF (SELECT COUNT(*) FROM z_stop_times WHERE stop_id NOT IN (SELECT stop_id FROM z_stops)) > 0 THEN
|
||||
update gtfs_archivo
|
||||
IF (SELECT COUNT(*) FROM z_stop_times WHERE stop_id NOT IN (SELECT stop_id FROM z_stops)) > 0 THEN
|
||||
update gtfs_archivo
|
||||
set status = 'Error - stop_time con stop_id que no existen'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '8 La validacion de archivos detecto errores en los archivos GTFS';
|
||||
|
@ -79,44 +79,34 @@ BEGIN
|
|||
) INTO inicio_vigencia;*/
|
||||
|
||||
SELECT MIN(start_date) INTO inicio_vigencia FROM z_calendar;
|
||||
update gtfs_archivo
|
||||
update gtfs_archivo
|
||||
set valid_from= inicio_vigencia
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
|
||||
IF CURRENT_DATE < inicio_vigencia THEN
|
||||
update gtfs_archivo
|
||||
set status = 'PENDIENTE'
|
||||
|
||||
IF CURRENT_DATE < inicio_vigencia THEN
|
||||
update gtfs_archivo
|
||||
set status = 'PENDIENTE'
|
||||
where trim(upper(status))='PROCESANDO' ;
|
||||
v_error:= '9 EL ARCHIVO AUN NO ESTA VIGENTE POR FECHA';
|
||||
END IF;
|
||||
|
||||
|
||||
if v_error = '' THEN
|
||||
|
||||
/* ASEGURA QUE CADA TRIPS TENGA UN SOLO GUION EN SU DESCRIPCION */
|
||||
UPDATE z_trips
|
||||
SET trip_headsign =
|
||||
CASE
|
||||
WHEN (LENGTH(trip_headsign) - LENGTH(REPLACE(trip_headsign, '-', '')) = 2) THEN
|
||||
WHEN (LENGTH(trip_headsign) - LENGTH(REPLACE(trip_headsign, '-', '')) = 2) THEN
|
||||
regexp_replace(trip_headsign, '^(.*)-(.*)-(.*)$', '\1-\2~\3')
|
||||
ELSE
|
||||
ELSE
|
||||
trip_headsign
|
||||
end
|
||||
WHERE trip_headsign LIKE '%-%-%';
|
||||
|
||||
update z_routes
|
||||
set route_long_name = replace (route_long_name,replace(
|
||||
(select distinct trip_headsign from z_trips where route_id =z_routes.route_id and trip_headsign like '%~%' ),'~','-'
|
||||
),
|
||||
(select distinct trip_headsign from z_trips where route_id =z_routes.route_id and trip_headsign like '%~%' )
|
||||
)
|
||||
WHERE route_long_name LIKE '%-%-%-%-%';
|
||||
|
||||
|
||||
|
||||
|
||||
update gtfs_archivo
|
||||
update gtfs_archivo
|
||||
set vigente = False
|
||||
where vigente = true and id_red in
|
||||
where vigente = true and id_red in
|
||||
(select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' );
|
||||
|
||||
|
||||
|
@ -136,37 +126,37 @@ if v_error = '' THEN
|
|||
|
||||
-----
|
||||
|
||||
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;
|
||||
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 );
|
||||
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
|
||||
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_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
|
||||
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);
|
||||
|
||||
-----
|
||||
|
||||
delete from linea_paradero;
|
||||
|
||||
-----
|
||||
-----
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS z_verifica_route (
|
||||
|
@ -175,102 +165,102 @@ if v_error = '' THEN
|
|||
);
|
||||
|
||||
|
||||
delete from linea l
|
||||
where id_linea in
|
||||
delete from linea l
|
||||
where id_linea in
|
||||
(
|
||||
select route_id||'-0' from z_verifica_route as v
|
||||
where coalesce((select count(*) from z_routes as r where r.route_id=v.route_id and r.route_short_name = v.route_short_name),0)=0
|
||||
union
|
||||
where coalesce((select count(*) from z_routes as r where r.route_id=v.route_id and r.route_short_name = v.route_short_name),0)=0
|
||||
union
|
||||
select route_id||'-1' from z_verifica_route as v
|
||||
where coalesce((select count(*) from z_routes as r where r.route_id=v.route_id and r.route_short_name = v.route_short_name),0)=0
|
||||
union
|
||||
where coalesce((select count(*) from z_routes as r where r.route_id=v.route_id and r.route_short_name = v.route_short_name),0)=0
|
||||
union
|
||||
select route_id from z_verifica_route as v
|
||||
where coalesce((select count(*) from z_routes as r where r.route_id=v.route_id and r.route_short_name = v.route_short_name),0)=0
|
||||
where coalesce((select count(*) from z_routes as r where r.route_id=v.route_id and r.route_short_name = v.route_short_name),0)=0
|
||||
) ;
|
||||
|
||||
delete from z_verifica_route ;
|
||||
|
||||
insert into z_verifica_route
|
||||
insert into z_verifica_route
|
||||
select route_id, route_short_name from z_routes ;
|
||||
|
||||
-----
|
||||
-----
|
||||
|
||||
update 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
|
||||
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
|
||||
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
|
||||
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
|
||||
);
|
||||
|
||||
-----
|
||||
-----
|
||||
|
||||
insert into linea
|
||||
select distinct
|
||||
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
|
||||
insert into linea
|
||||
select distinct
|
||||
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_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_type::numeric ,
|
||||
zr.route_type::numeric ,
|
||||
zr.route_url,
|
||||
zr.route_color ,
|
||||
zr.route_text_color ,
|
||||
zr.route_color ,
|
||||
zr.route_text_color ,
|
||||
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
|
||||
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,
|
||||
union
|
||||
select distinct
|
||||
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_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_type::numeric ,
|
||||
zr.route_type::numeric ,
|
||||
zr.route_url,
|
||||
zr.route_color ,
|
||||
zr.route_text_color ,
|
||||
zr.route_color ,
|
||||
zr.route_text_color ,
|
||||
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
|
||||
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,
|
||||
union
|
||||
select distinct
|
||||
trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id,
|
||||
null,--zr.agency_id ,
|
||||
route_short_name ,
|
||||
route_short_name ,
|
||||
zr.route_desc ,
|
||||
zr.route_type::numeric ,
|
||||
zr.route_type::numeric ,
|
||||
zr.route_url,
|
||||
zr.route_color ,
|
||||
zr.route_text_color ,
|
||||
zr.route_color ,
|
||||
zr.route_text_color ,
|
||||
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
|
||||
( position('-' in zt.trip_headsign) = 0
|
||||
or
|
||||
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 ||'%'
|
||||
)
|
||||
where (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea )
|
||||
|
@ -288,7 +278,7 @@ if v_error = '' THEN
|
|||
from z_shapes zs;
|
||||
|
||||
-----
|
||||
|
||||
|
||||
truncate table gtfs_stop_times;
|
||||
|
||||
-----
|
||||
|
@ -301,8 +291,8 @@ if v_error = '' THEN
|
|||
|
||||
-----
|
||||
|
||||
insert into gtfs_trips
|
||||
select
|
||||
insert into gtfs_trips
|
||||
select
|
||||
trip_id,
|
||||
trim(route_id)||'-'||trim(direction_id::varchar) as route_id,
|
||||
shape_id ,null as regreso, trip_headsign,trip_short_name,direction_id::numeric,service_id::varchar,block_id
|
||||
|
@ -310,45 +300,45 @@ if v_error = '' THEN
|
|||
|
||||
-----
|
||||
|
||||
insert into gtfs_stop_times
|
||||
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
|
||||
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 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',
|
||||
'\yentre\y',
|
||||
'-entre',
|
||||
'gi'
|
||||
),
|
||||
'\yesq\y',
|
||||
'-esq',
|
||||
'\yesq\y',
|
||||
'-esq',
|
||||
'gi'
|
||||
);
|
||||
|
||||
-----
|
||||
update paradero
|
||||
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;
|
||||
where id_comuna is not null;
|
||||
-----
|
||||
|
||||
insert into dispositivo
|
||||
select 'QRCode-'||id_paradero , id_paradero , true, null, 3
|
||||
from paradero as p where id_paradero
|
||||
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);
|
||||
|
||||
-----
|
||||
|
@ -373,26 +363,26 @@ if v_error = '' THEN
|
|||
where id_comuna is null;
|
||||
|
||||
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS gtfs_validaciones (
|
||||
id_gtfs int4 not null,
|
||||
route_id text NULL,
|
||||
route_long_name text NULL,
|
||||
observacion text NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
insert into gtfs_validaciones
|
||||
select (select id_gtfs from gtfs_archivo where trim(upper(status))='PROCESANDO' ),
|
||||
route_id, route_long_name,
|
||||
route_id, route_long_name,
|
||||
'Ruta sin Trips Asociados'
|
||||
from z_routes
|
||||
where route_id not in
|
||||
(select route_id from z_trips ) ;
|
||||
from z_routes
|
||||
where route_id not in
|
||||
(select route_id from z_trips ) ;
|
||||
|
||||
|
||||
update gtfs_archivo
|
||||
set vigente = true , status = case when
|
||||
update gtfs_archivo
|
||||
set vigente = true , status = case when
|
||||
(
|
||||
select count(*) from gtfs_validaciones where id_gtfs =(select id_gtfs from gtfs_archivo where trim(upper(status))='PROCESANDO' )
|
||||
) =0 then 'GTFS CARGADO' else 'GTFS CARGADO CON REPAROS' END
|
||||
|
@ -400,4 +390,4 @@ if v_error = '' THEN
|
|||
|
||||
END IF;
|
||||
|
||||
END$$;
|
||||
END$$;
|
||||
|
|
|
@ -14,9 +14,9 @@ class ApiMiddleware:
|
|||
if request.path[0:5] != '/api/':
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
|
||||
|
||||
match = resolve(request.path)
|
||||
logging.error(match)
|
||||
logging.info(match)
|
||||
|
||||
# se omite esta regla al mostrar imagen de paradero
|
||||
if match.url_name == 'paradero_imagen-detail' and request.method == 'GET':
|
||||
|
@ -56,16 +56,16 @@ class ApiMiddleware:
|
|||
return HttpResponse('token ya no es valido', status = 400)
|
||||
except jwt.InvalidTokenError:
|
||||
return HttpResponse('token es invalido', status = 400)
|
||||
|
||||
if decoded['login'] != '0':
|
||||
|
||||
if decoded['login'] != '0':
|
||||
usuario = Usuario.objects.filter(login = decoded['login'], vigente = True).values().first()
|
||||
if not usuario:
|
||||
return HttpResponse('Usuario ya no vigente', status = 400)
|
||||
|
||||
|
||||
persona = Persona.objects.filter(rut = usuario['rut_id']).values().first()
|
||||
if not persona:
|
||||
return HttpResponse('No existe información de la persona', status = 500)
|
||||
|
||||
|
||||
request.jwt_info = { 'login': usuario['login'], 'persona': persona }
|
||||
else:
|
||||
request.jwt_info = { 'login': '0', 'persona': None }
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
from django.db import models
|
||||
from .validaciones import rut_valido
|
||||
|
||||
|
||||
class Aplicacion(models.Model):
|
||||
id_aplicacion = models.IntegerField(primary_key=True)
|
||||
nombre_app = models.CharField(max_length=100, blank=False, null=False)
|
||||
|
@ -19,7 +18,6 @@ class Aplicacion(models.Model):
|
|||
managed = True
|
||||
db_table = 'aplicacion'
|
||||
|
||||
|
||||
class Comuna(models.Model):
|
||||
id_comuna = models.IntegerField(primary_key=True)
|
||||
id_region = models.ForeignKey('Region', models.DO_NOTHING, db_column='id_region', blank=True, null=True)
|
||||
|
@ -29,7 +27,6 @@ class Comuna(models.Model):
|
|||
managed = False
|
||||
db_table = 'comuna'
|
||||
|
||||
|
||||
class Conductor(models.Model):
|
||||
patente = models.OneToOneField('Vehiculo', models.DO_NOTHING, db_column='patente', primary_key=True)
|
||||
rut = models.ForeignKey('Persona', models.DO_NOTHING, db_column='rut', blank=True, null=True)
|
||||
|
@ -39,7 +36,6 @@ class Conductor(models.Model):
|
|||
managed = False
|
||||
db_table = 'conductor'
|
||||
|
||||
|
||||
class Dispositivo(models.Model):
|
||||
id_dispositivo = models.CharField(primary_key=True, max_length=100)
|
||||
id_paradero = models.ForeignKey('Paradero', models.DO_NOTHING, db_column='id_paradero', blank=False, null=False)
|
||||
|
@ -51,7 +47,6 @@ class Dispositivo(models.Model):
|
|||
managed = False
|
||||
db_table = 'dispositivo'
|
||||
|
||||
|
||||
class GtfsFrequencie(models.Model):
|
||||
id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip', blank=True, null=True)
|
||||
start_time = models.TimeField(blank=True, null=True)
|
||||
|
@ -63,7 +58,6 @@ class GtfsFrequencie(models.Model):
|
|||
managed = False
|
||||
db_table = 'gtfs_frequencie'
|
||||
|
||||
|
||||
class GtfsPosiciones(models.Model):
|
||||
id = models.UUIDField(primary_key=True)
|
||||
trip_id = models.UUIDField()
|
||||
|
@ -177,7 +171,6 @@ class Linea(models.Model):
|
|||
managed = False
|
||||
db_table = 'linea'
|
||||
|
||||
|
||||
class LineaParadero(models.Model):
|
||||
id_linea_paradero = models.AutoField(primary_key=True)
|
||||
id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea')
|
||||
|
@ -187,7 +180,6 @@ class LineaParadero(models.Model):
|
|||
managed = False
|
||||
db_table = 'linea_paradero'
|
||||
|
||||
|
||||
class Rol(models.Model):
|
||||
id_rol = models.IntegerField(primary_key=True)
|
||||
nombre_rol = models.CharField(max_length=100)
|
||||
|
@ -196,7 +188,6 @@ class Rol(models.Model):
|
|||
managed = False
|
||||
db_table = 'rol'
|
||||
|
||||
|
||||
class Operador(models.Model):
|
||||
id_operador = models.CharField(primary_key=True, max_length=150)
|
||||
id_region = models.ForeignKey('Region', models.DO_NOTHING, db_column='id_region', blank=True, null=True)
|
||||
|
@ -213,7 +204,6 @@ class Operador(models.Model):
|
|||
managed = False
|
||||
db_table = 'operador'
|
||||
|
||||
|
||||
class Paradero(models.Model):
|
||||
id_paradero = models.CharField(primary_key=True, max_length=50)
|
||||
id_comuna = models.ForeignKey(Comuna, models.DO_NOTHING, db_column='id_comuna', blank=True, null=True)
|
||||
|
@ -235,7 +225,6 @@ class Paradero(models.Model):
|
|||
managed = False
|
||||
db_table = 'paradero'
|
||||
|
||||
|
||||
class ParaderoImagen(models.Model):
|
||||
id_paradero_imagen = models.AutoField(primary_key=True)
|
||||
id_paradero = models.ForeignKey(Paradero, models.DO_NOTHING, db_column='id_paradero')
|
||||
|
@ -246,7 +235,6 @@ class ParaderoImagen(models.Model):
|
|||
managed = False
|
||||
db_table = 'paradero_imagen'
|
||||
|
||||
|
||||
class Persona(models.Model):
|
||||
rut = models.DecimalField(primary_key=True, max_digits=12, decimal_places=0)
|
||||
id_tipo_tratamiento = models.ForeignKey('TipoTratamientoPersona', models.DO_NOTHING, db_column='id_tipo_tratamiento', blank=True, null=True)
|
||||
|
@ -263,7 +251,7 @@ class Persona(models.Model):
|
|||
class Meta:
|
||||
managed = False
|
||||
db_table = 'persona'
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# validacion se realiza solo si se esta creando el registro
|
||||
if self._state.adding:
|
||||
|
@ -273,7 +261,6 @@ class Persona(models.Model):
|
|||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class Region(models.Model):
|
||||
id_region = models.IntegerField(primary_key=True)
|
||||
nombre_region = models.CharField(max_length=100)
|
||||
|
@ -282,9 +269,6 @@ class Region(models.Model):
|
|||
managed = False
|
||||
db_table = 'region'
|
||||
|
||||
|
||||
|
||||
|
||||
class RolAplicacion(models.Model):
|
||||
id_rol_app = models.AutoField(primary_key=True)
|
||||
id_aplicacion = models.ForeignKey(Aplicacion, models.DO_NOTHING, db_column='id_aplicacion', blank=False, null=False)
|
||||
|
@ -298,10 +282,9 @@ class RolAplicacion(models.Model):
|
|||
|
||||
class RolOperador(models.Model):
|
||||
id_rol_operador = models.AutoField(primary_key=True)
|
||||
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol')
|
||||
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol')
|
||||
id_operador = models.ForeignKey(Operador, on_delete=models.CASCADE, db_column='id_operador')
|
||||
|
||||
|
||||
class Meta:
|
||||
managed = True
|
||||
db_table = 'rol_operador'
|
||||
|
@ -327,7 +310,6 @@ class TipoDispositivo(models.Model):
|
|||
managed = False
|
||||
db_table = 'tipo_dispositivo'
|
||||
|
||||
|
||||
class TipoParadero(models.Model):
|
||||
id_tipo_paradero = models.IntegerField(primary_key=True)
|
||||
descripcion = models.CharField(max_length=100, blank=True, null=True)
|
||||
|
@ -336,7 +318,6 @@ class TipoParadero(models.Model):
|
|||
managed = False
|
||||
db_table = 'tipo_paradero'
|
||||
|
||||
|
||||
class TipoTransporte(models.Model):
|
||||
id_tipo_transporte = models.IntegerField(primary_key=True)
|
||||
descripcion = models.CharField(max_length=50, blank=True, null=True)
|
||||
|
@ -363,7 +344,6 @@ class TipoTratamientoPersona(models.Model):
|
|||
db_table = 'tipo_tratamiento_persona'
|
||||
db_table_comment = 'Establece el tratamiento de como dirigirse hacia una persona:\r\nEjemplo\r\nSeñor\r\nSeñora\r\nSrta'
|
||||
|
||||
|
||||
class TipoVehiculo(models.Model):
|
||||
id_tipo_vehiculo = models.IntegerField(primary_key=True)
|
||||
descripcion = models.CharField(max_length=100, blank=True, null=True)
|
||||
|
@ -372,7 +352,6 @@ class TipoVehiculo(models.Model):
|
|||
managed = False
|
||||
db_table = 'tipo_vehiculo'
|
||||
|
||||
|
||||
class Usuario(models.Model):
|
||||
login = models.CharField(primary_key=True, max_length=60)
|
||||
rut = models.ForeignKey(Persona, models.DO_NOTHING, db_column='rut', blank=True, null=True)
|
||||
|
@ -385,7 +364,6 @@ class Usuario(models.Model):
|
|||
managed = False
|
||||
db_table = 'usuario'
|
||||
|
||||
|
||||
class Vehiculo(models.Model):
|
||||
ppu = models.CharField(primary_key=True, max_length=10)
|
||||
id_tipo_vehiculo = models.ForeignKey(TipoVehiculo, models.DO_NOTHING, db_column='id_tipo_vehiculo', blank=True, null=True)
|
||||
|
@ -395,7 +373,6 @@ class Vehiculo(models.Model):
|
|||
managed = False
|
||||
db_table = 'vehiculo'
|
||||
|
||||
|
||||
class VehiculoLinea(models.Model):
|
||||
patente = models.OneToOneField(Vehiculo, models.DO_NOTHING, db_column='patente', primary_key=True) # The composite primary key (patente, id_linea) found, that is not supported. The first column is selected.
|
||||
id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea')
|
||||
|
@ -405,7 +382,7 @@ class VehiculoLinea(models.Model):
|
|||
managed = False
|
||||
db_table = 'vehiculo_linea'
|
||||
unique_together = (('patente', 'id_linea'),)
|
||||
|
||||
|
||||
class RedTransporte(models.Model):
|
||||
id_red = models.CharField(primary_key=True, max_length=10)
|
||||
nombre_red = models.CharField(max_length=100, blank=True, null=True)
|
||||
|
@ -426,7 +403,7 @@ class GtfsArchivo(models.Model):
|
|||
ruta_archivo = models.CharField(max_length=200, blank=True, null=True)
|
||||
valid_from = models.DateField(blank=True, null=True)
|
||||
#created = models.DateTimeField(blank=True, null=True)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
usuario = models.CharField(max_length=100, blank=True, null=True)
|
||||
vigente = models.BooleanField(blank=True, null=True)
|
||||
status = models.CharField(max_length=100, blank=True, null=True)
|
||||
|
@ -436,7 +413,6 @@ class GtfsArchivo(models.Model):
|
|||
db_table = 'gtfs_archivo'
|
||||
db_table_comment = 'Registro de los archivos GTFS que se cargan en el sistema'
|
||||
|
||||
|
||||
class VistaFuncionario(models.Model):
|
||||
rut = models.ForeignKey('Persona', models.DO_NOTHING, db_column='rut', blank=True, null=True)
|
||||
id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True)
|
||||
|
@ -456,10 +432,10 @@ class Contrato(models.Model):
|
|||
db_table = 'contrato'
|
||||
|
||||
class PersonaDatosLaborales(models.Model):
|
||||
rut = models.OneToOneField('Persona', models.DO_NOTHING, db_column='rut', primary_key=True)
|
||||
rut = models.OneToOneField('Persona', models.DO_NOTHING, db_column='rut', primary_key=True)
|
||||
vigencia_clase_licencia = models.DateField(blank=True, null=True)
|
||||
clase_licencia_conducir = models.CharField(max_length=50, blank=True, null=True)
|
||||
profesion = models.CharField(max_length=100, blank=True, null=True)
|
||||
clase_licencia_conducir = models.CharField(max_length=50, blank=True, null=True)
|
||||
profesion = models.CharField(max_length=100, blank=True, null=True)
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'persona_datos_laborales'
|
||||
db_table = 'persona_datos_laborales'
|
||||
|
|
|
@ -32,21 +32,21 @@ def jwt_login(request):
|
|||
if rut != '0':
|
||||
dv = rut[-1].upper()
|
||||
rut = rut[:-1]
|
||||
|
||||
|
||||
usuario = None
|
||||
|
||||
if rut == '0' and password == '0':
|
||||
usuario = { 'login': '0', 'clave': '0' }
|
||||
|
||||
|
||||
# solo se permite usuario 0 si no existen usuarios vigentes
|
||||
count = models.Usuario.objects.filter(vigente = True).count()
|
||||
if count > 0:
|
||||
return HttpResponse('Acceso no valido', status=400)
|
||||
return HttpResponse('Acceso no valido 1', status=400)
|
||||
else:
|
||||
usuario = models.Usuario.objects.filter(vigente=1, rut__rut=rut, rut__dv=dv).values().first()
|
||||
|
||||
if not check_password(input['password'], usuario['clave']):
|
||||
return HttpResponse('Acceso no valido', status=400)
|
||||
return HttpResponse('Acceso no valido 2', status=400)
|
||||
|
||||
ahora = datetime.utcnow()
|
||||
manana = ahora + timedelta(days=1)
|
||||
|
@ -79,10 +79,10 @@ def recuperar(request):
|
|||
usuario = models.Usuario.objects.filter(rut=rut, vigente=True).first()
|
||||
|
||||
if usuario == None or persona == None:
|
||||
return HttpResponse('Acceso no valido', status=400)
|
||||
return HttpResponse('El usuario no existe', status=400)
|
||||
|
||||
if persona.email != input['email'].lower():
|
||||
return HttpResponse('Acceso no valido', status=400)
|
||||
return HttpResponse('El correo electrónico no es el registrado para el usuario', status=400)
|
||||
|
||||
codigo_aleatorio = random.randint(100000, 999999)
|
||||
ahora = datetime.utcnow()
|
||||
|
@ -112,6 +112,7 @@ def recuperar(request):
|
|||
def info_token(request):
|
||||
input = json.loads(request.body)
|
||||
token = input['token']
|
||||
logging.warning(input)
|
||||
try:
|
||||
decoded = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
|
||||
persona = models.Persona.objects.filter(rut=decoded['rut']).first()
|
||||
|
@ -158,31 +159,27 @@ def nueva_contrasena(request):
|
|||
return HttpResponse('error al cambiar contraseña', status = 500)
|
||||
|
||||
|
||||
|
||||
|
||||
def enviar_correo(destinatario, asunto, contenido):
|
||||
try:
|
||||
template = get_template('correo_recuperar.html') # Ruta al template del correo
|
||||
contenido_renderizado = template.render(contenido)
|
||||
|
||||
mensaje = EmailMultiAlternatives(asunto, '', settings.EMAIL_HOST_USER, [destinatario])
|
||||
mensaje = EmailMultiAlternatives(asunto, '', settings.EMAIL_SENDER, [destinatario])
|
||||
mensaje.attach_alternative(contenido_renderizado, 'text/html')
|
||||
mensaje.send()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f'EMAIL_HOST: {EMAIL_HOST}', flush=True)
|
||||
print(f'EMAIL_HOST: {settings.EMAIL_HOST}', flush=True)
|
||||
print(f'ERROR: {e}', flush=True)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
def http_referer(request):
|
||||
if 'HTTP_REFERER' in request.META:
|
||||
def http_referer(request, clean=False):
|
||||
if 'HTTP_REFERER' in request.META and clean==False:
|
||||
referer = request.META['HTTP_REFERER']
|
||||
else:
|
||||
protocol = request.scheme
|
||||
host = request.META['HTTP_HOST']
|
||||
port = request.META['SERVER_PORT']
|
||||
referer = f'{protocol}://{host}'
|
||||
return referer
|
||||
return referer
|
||||
|
|
|
@ -79,12 +79,12 @@ class DispositivoViewSet(viewsets.ModelViewSet):
|
|||
trayectos_none = json.loads(json_trayectos)
|
||||
|
||||
# agregar al listado los trayecto en donde no se registro el paradero
|
||||
"""
|
||||
"""
|
||||
json_trayectos = r.get('stop_id:none')
|
||||
trayectos_none = []
|
||||
if json_trayectos != None:
|
||||
trayectos_none = json.loads(json_trayectos)
|
||||
|
||||
|
||||
for trayecto in trayectos_none:
|
||||
trayecto['stop_id'] = 'none'
|
||||
trayecto['hora_llegada'] = None
|
||||
|
@ -136,6 +136,9 @@ class DispositivoViewSet(viewsets.ModelViewSet):
|
|||
hora_llegada = row[0].strftime('%H:%M:%S')
|
||||
distancia_km = row[1]
|
||||
texto_llegada= row[2]
|
||||
if distancia_km == None:
|
||||
distancia_km == 999
|
||||
|
||||
|
||||
llegadas.append({
|
||||
'patente': trayecto['vehicle_license_plate'],
|
||||
|
@ -145,11 +148,16 @@ class DispositivoViewSet(viewsets.ModelViewSet):
|
|||
'stop_id_alterno': trayecto['stop_id_alterno'],
|
||||
'EstimadaGPS': hora_llegada,
|
||||
'DistanciaGPS': distancia_km,
|
||||
'textoLlegada' : texto_llegada,
|
||||
'textoLlegada' : texto_llegada,
|
||||
'Mensajelinea': None,
|
||||
})
|
||||
|
||||
llegadas_ordendas = sorted(llegadas, key=lambda x: x['DistanciaGPS'])
|
||||
try:
|
||||
llegadas_ordendas = sorted(llegadas, key=lambda x: x['DistanciaGPS'])
|
||||
except:
|
||||
logging.debug("No se pueden ordenar: {}".format(llegadas))
|
||||
llegadas_ordendas = llegadas
|
||||
|
||||
|
||||
item = {
|
||||
'Linea': linea.route_long_name,
|
||||
|
|
|
@ -24,7 +24,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-ozq@8*t6cy&$lmu@qsvz+l6omsfncj6r1w)s**rtl3vd&j8_#b'
|
||||
SECRET_KEY = config('SECRET_KEY')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
@ -181,7 +181,10 @@ LOGGING = {
|
|||
|
||||
|
||||
EMAIL_HOST = config('SMTP_HOST')
|
||||
EMAIL_PORT = config('SMTP_PORT', 587)
|
||||
EMAIL_HOST_USER = config('SMTP_USER', 'tu_correo@gmail.com') # Tu dirección de correo
|
||||
EMAIL_HOST_PASSWORD = config('SMTP_PASS', 'tu_contraseña') # Tu contraseña de correo
|
||||
EMAIL_USE_TLS = config('SMTP_PROTOCOL') == 'tls'
|
||||
EMAIL_PORT = config('SMTP_PORT')
|
||||
EMAIL_SENDER = config('SMTP_FROM')
|
||||
|
||||
|
||||
#EMAIL_HOST_USER = config('SMTP_USER', 'tu_correo@gmail.com') # Tu dirección de correo
|
||||
#EMAIL_HOST_PASSWORD = config('SMTP_PASS', 'tu_contraseña') # Tu contraseña de correo
|
||||
EMAIL_USE_TLS = config('SMTP_PROTOCOL') == 'tls'
|
||||
|
|
Loading…
Reference in New Issue