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