From 4ae2ef977ea978806634947ce8b1704fe786b049 Mon Sep 17 00:00:00 2001 From: Ronald Morales Date: Mon, 25 Mar 2024 01:20:41 -0300 Subject: [PATCH] Agrega Validaciones a Carga GTFS y define rutas de informes --- .../management/commands/actualiza_GTFS.sql | 45 ++++++++++++++++++- .../api/management/commands/procesa_zip.py | 2 +- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/project/api/management/commands/actualiza_GTFS.sql b/project/api/management/commands/actualiza_GTFS.sql index 79a49f0..2121d0d 100644 --- a/project/api/management/commands/actualiza_GTFS.sql +++ b/project/api/management/commands/actualiza_GTFS.sql @@ -92,6 +92,28 @@ BEGIN 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 + regexp_replace(trip_headsign, '^(.*)-(.*)-(.*)$', '\1-\2~\3') + 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 set vigente = False where vigente = true and id_red in @@ -351,8 +373,29 @@ 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, + 'Ruta sin Trips Asociados' + from z_routes + where route_id not in + (select route_id from z_trips ) ; + + update gtfs_archivo - set vigente = true , status = 'GTFS CARGADO' + 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 where trim(upper(status))='PROCESANDO' ; END IF; diff --git a/project/api/management/commands/procesa_zip.py b/project/api/management/commands/procesa_zip.py index 4353e75..4786080 100644 --- a/project/api/management/commands/procesa_zip.py +++ b/project/api/management/commands/procesa_zip.py @@ -131,7 +131,7 @@ def procesa_tablas_z(cursor): with open(os.path.join(current_folder, 'actualiza_GTFS.sql'),'r') as file: sqlFile = file.read() cursor.execute(sqlFile) - cursor.commit() + #cursor.commit() """ content = ''.join(file.readlines()) arr_sql = content.split('-----')