diff --git a/project/api/models.py b/project/api/models.py index f8debe0..c6e3af2 100755 --- a/project/api/models.py +++ b/project/api/models.py @@ -405,3 +405,32 @@ class RolLinea(models.Model): managed = True db_table = 'rol_linea' unique_together = (('id_rol', '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) + descripcion = models.CharField(max_length=1000, blank=True, null=True) + url_gtfs_rt = models.CharField(max_length=100, blank=True, null=True) + api_key = models.CharField(max_length=100, blank=True, null=True) + vigente = models.BooleanField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'red_transporte' + db_table_comment = 'Tabla que contiene las diferentes tipos de red de transporte, como son los de transporte publico, trenes, colectivos, etc.' + +class GtfsArchivo(models.Model): + id_gtfs = models.AutoField(primary_key=True) + id_red = models.ForeignKey('RedTransporte', models.DO_NOTHING, db_column='id_red', blank=True, null=True) + 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) + created = models.DateTimeField(blank=True, null=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) + + class Meta: + managed = False + db_table = 'gtfs_archivo' + db_table_comment = 'Registro de los archivos GTFS que se cargan en el sistema' diff --git a/project/api/models2.py b/project/api/models2.py new file mode 100644 index 0000000..ab1e87f --- /dev/null +++ b/project/api/models2.py @@ -0,0 +1,735 @@ +# This is an auto-generated Django model module. +# You'll have to do the following manually to clean this up: +# * Rearrange models' order +# * Make sure each model has one field with primary_key=True +# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior +# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table +# Feel free to rename the models, but don't rename db_table values or field names. +from django.db import models + + +class Aplicacion(models.Model): + id_aplicacion = models.IntegerField(primary_key=True) + nombre_app = models.CharField(max_length=100) + path_app = models.CharField(max_length=200) + vigente = models.BooleanField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'aplicacion' + + +class AuthGroup(models.Model): + name = models.CharField(unique=True, max_length=150) + + class Meta: + managed = False + db_table = 'auth_group' + + +class AuthGroupPermissions(models.Model): + id = models.BigAutoField(primary_key=True) + group = models.ForeignKey(AuthGroup, models.DO_NOTHING) + permission = models.ForeignKey('AuthPermission', models.DO_NOTHING) + + class Meta: + managed = False + db_table = 'auth_group_permissions' + unique_together = (('group', 'permission'),) + + +class AuthPermission(models.Model): + name = models.CharField(max_length=255) + content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING) + codename = models.CharField(max_length=100) + + class Meta: + managed = False + db_table = 'auth_permission' + unique_together = (('content_type', 'codename'),) + + +class AuthUser(models.Model): + password = models.CharField(max_length=128) + last_login = models.DateTimeField(blank=True, null=True) + is_superuser = models.BooleanField() + username = models.CharField(unique=True, max_length=150) + first_name = models.CharField(max_length=150) + last_name = models.CharField(max_length=150) + email = models.CharField(max_length=254) + is_staff = models.BooleanField() + is_active = models.BooleanField() + date_joined = models.DateTimeField() + + class Meta: + managed = False + db_table = 'auth_user' + + +class AuthUserGroups(models.Model): + id = models.BigAutoField(primary_key=True) + user = models.ForeignKey(AuthUser, models.DO_NOTHING) + group = models.ForeignKey(AuthGroup, models.DO_NOTHING) + + class Meta: + managed = False + db_table = 'auth_user_groups' + unique_together = (('user', 'group'),) + + +class AuthUserUserPermissions(models.Model): + id = models.BigAutoField(primary_key=True) + user = models.ForeignKey(AuthUser, models.DO_NOTHING) + permission = models.ForeignKey(AuthPermission, models.DO_NOTHING) + + class Meta: + managed = False + db_table = 'auth_user_user_permissions' + unique_together = (('user', 'permission'),) + + +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) + nombre_comuna = models.CharField(max_length=100, blank=True, null=True) + + class Meta: + managed = False + db_table = 'comuna' + + +class ComunaGeoreferencia(models.Model): + id_comuna = models.IntegerField(primary_key=True) + geom = models.TextField(blank=True, null=True) # This field type is a guess. + + class Meta: + managed = False + db_table = 'comuna_georeferencia' + + +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) + vigente = models.BooleanField(blank=True, null=True) + + class Meta: + 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=True, null=True) + vigente = models.BooleanField(blank=True, null=True) + ultima_conexion = models.DateField(blank=True, null=True) + id_tipo_dispositivo = models.ForeignKey('TipoDispositivo', models.DO_NOTHING, db_column='id_tipo_dispositivo') + + class Meta: + managed = False + db_table = 'dispositivo' + + +class DjangoAdminLog(models.Model): + action_time = models.DateTimeField() + object_id = models.TextField(blank=True, null=True) + object_repr = models.CharField(max_length=200) + action_flag = models.SmallIntegerField() + change_message = models.TextField() + content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING, blank=True, null=True) + user = models.ForeignKey(AuthUser, models.DO_NOTHING) + + class Meta: + managed = False + db_table = 'django_admin_log' + + +class DjangoContentType(models.Model): + app_label = models.CharField(max_length=100) + model = models.CharField(max_length=100) + + class Meta: + managed = False + db_table = 'django_content_type' + unique_together = (('app_label', 'model'),) + + +class DjangoMigrations(models.Model): + id = models.BigAutoField(primary_key=True) + app = models.CharField(max_length=255) + name = models.CharField(max_length=255) + applied = models.DateTimeField() + + class Meta: + managed = False + db_table = 'django_migrations' + + +class DjangoSession(models.Model): + session_key = models.CharField(primary_key=True, max_length=40) + session_data = models.TextField() + expire_date = models.DateTimeField() + + class Meta: + managed = False + db_table = 'django_session' + + +class Funcionario(models.Model): + rut = models.OneToOneField('Persona', models.DO_NOTHING, db_column='rut', primary_key=True) + id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True) + desde = models.DateField(blank=True, null=True) + hasta = models.DateField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'funcionario' + + +class GtfsArchivo(models.Model): + id_gtfs = models.AutoField(primary_key=True) + id_red = models.ForeignKey('RedTransporte', models.DO_NOTHING, db_column='id_red', blank=True, null=True) + 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) + 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) + + class Meta: + managed = False + db_table = 'gtfs_archivo' + db_table_comment = 'Registro de los archivos GTFS que se cargan en el sistema' + + +class GtfsCalendar(models.Model): + service_id = models.CharField(primary_key=True, max_length=150) + monday = models.BooleanField(blank=True, null=True) + tuesday = models.BooleanField(blank=True, null=True) + wednesday = models.BooleanField(blank=True, null=True) + thursday = models.BooleanField(blank=True, null=True) + friday = models.BooleanField(blank=True, null=True) + saturday = models.BooleanField(blank=True, null=True) + sunday = models.BooleanField(blank=True, null=True) + start_date = models.DateField(blank=True, null=True) + end_date = models.DateField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_calendar' + + +class GtfsCalendarDates(models.Model): + service_id = models.DecimalField(primary_key=True, max_digits=8, decimal_places=0) # The composite primary key (service_id, date) found, that is not supported. The first column is selected. + date = models.CharField(max_length=10) + exception_type = models.DecimalField(max_digits=2, decimal_places=0, blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_calendar_dates' + unique_together = (('service_id', 'date'),) + + +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) + end_time = models.TimeField(blank=True, null=True) + headway_secs = models.IntegerField(blank=True, null=True) + exact_time = models.IntegerField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_frequencie' + + +class GtfsPosiciones(models.Model): + id = models.TextField(blank=True, null=True) + trip_id = models.TextField(blank=True, null=True) + route_id = models.TextField(blank=True, null=True) + direction_id = models.BigIntegerField(blank=True, null=True) + start_time = models.TextField(blank=True, null=True) + start_date = models.TextField(blank=True, null=True) + schedule_relationship = models.BigIntegerField(blank=True, null=True) + vehicle_license_plate = models.TextField(blank=True, null=True) + latitude = models.FloatField(blank=True, null=True) + longitude = models.FloatField(blank=True, null=True) + bearing = models.FloatField(blank=True, null=True) + odometer = models.FloatField(blank=True, null=True) + speed = models.FloatField(blank=True, null=True) + stop_sequence = models.TextField(blank=True, null=True) + stop_id = models.TextField(blank=True, null=True) + arrival_time = models.TextField(blank=True, null=True) + hora_llegada = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_posiciones' + + +class GtfsPosicionesJson(models.Model): + stop_id = models.CharField(primary_key=True, max_length=255) + json_data = models.TextField(blank=True, null=True) # This field type is a guess. + + class Meta: + managed = False + db_table = 'gtfs_posiciones_json' + + +class GtfsRouteType(models.Model): + id_route_type = models.DecimalField(primary_key=True, max_digits=2, decimal_places=0) + descripcion = models.CharField(max_length=100, blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_route_type' + + +class GtfsShape(models.Model): + id_shape = models.DecimalField(max_digits=18, decimal_places=0) + shape_pt_lat = models.FloatField(blank=True, null=True) + shape_pt_lon = models.FloatField(blank=True, null=True) + shape_pt_sequence = models.IntegerField(blank=True, null=True) + shape_dist_traveled = models.FloatField(blank=True, null=True) + id_gtfs_pk = models.AutoField(primary_key=True) + + class Meta: + managed = False + db_table = 'gtfs_shape' + unique_together = (('id_shape', 'shape_dist_traveled'),) + + +class GtfsStopTimes(models.Model): + id_paradero = models.OneToOneField('Paradero', models.DO_NOTHING, db_column='id_paradero', primary_key=True) # The composite primary key (id_paradero, id_trip) found, that is not supported. The first column is selected. + id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip') + arrival_time = models.CharField(max_length=15, blank=True, null=True) + stop_sequence = models.IntegerField(blank=True, null=True) + stop_headsign = models.CharField(max_length=100, blank=True, null=True) + departure_time = models.CharField(max_length=15, blank=True, null=True) + drop_off_type = models.IntegerField(blank=True, null=True) + shape_dist_traveled = models.FloatField(blank=True, null=True) + timepoint = models.IntegerField(blank=True, null=True) + pickup_type = models.IntegerField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_stop_times' + unique_together = (('id_paradero', 'id_trip'),) + + +class GtfsTrips(models.Model): + id_trip = models.CharField(primary_key=True, max_length=150) + id_linea = models.CharField(max_length=150, blank=True, null=True) + id_shape = models.IntegerField(blank=True, null=True) + id_trip_regreso = models.ForeignKey('self', models.DO_NOTHING, db_column='id_trip_regreso', blank=True, null=True) + trip_headsign = models.CharField(max_length=100, blank=True, null=True) + trip_short_name = models.CharField(max_length=100, blank=True, null=True) + direction_id = models.IntegerField(blank=True, null=True) + service_id = models.CharField(max_length=50, blank=True, null=True, db_comment='de calendario') + block_id = models.CharField(max_length=50, blank=True, null=True) + + class Meta: + managed = False + db_table = 'gtfs_trips' + + +class LetreroLur(models.Model): + codigo = models.CharField(primary_key=True, max_length=10) + linea1 = models.CharField(max_length=50) + linea2 = models.CharField(max_length=50, blank=True, null=True) + linea3 = models.CharField(max_length=50, blank=True, null=True) + linea4 = models.CharField(max_length=50, blank=True, null=True) + bgcolor1 = models.CharField(max_length=20, blank=True, null=True) + color1 = models.CharField(max_length=20, blank=True, null=True) + bgcolor2 = models.CharField(max_length=20, blank=True, null=True) + color2 = models.CharField(max_length=20, blank=True, null=True) + + class Meta: + managed = False + db_table = 'letrero_lur' + + +class Linea(models.Model): + id_linea = models.CharField(primary_key=True, max_length=150) + id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True) + route_short_name = models.CharField(max_length=150, blank=True, null=True) + route_desc = models.CharField(max_length=150, blank=True, null=True) + route_type = models.ForeignKey(GtfsRouteType, models.DO_NOTHING, db_column='route_type', blank=True, null=True) + route_url = models.CharField(max_length=150, blank=True, null=True) + route_color = models.CharField(max_length=150, blank=True, null=True) + route_text_color = models.CharField(max_length=150, blank=True, null=True) + route_long_name = models.CharField(max_length=200, blank=True, null=True) + vigente = models.BooleanField(blank=True, null=True) + id_red = models.ForeignKey('RedTransporte', models.DO_NOTHING, db_column='id_red', blank=True, null=True) + + class Meta: + 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') + id_paradero = models.ForeignKey('Paradero', models.DO_NOTHING, db_column='id_paradero') + + class Meta: + managed = False + db_table = 'linea_paradero' + + +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) + vigente = models.BooleanField(blank=True, null=True) + nombre_operador = models.CharField(max_length=150, blank=True, null=True) + agency_url = models.CharField(max_length=200, blank=True, null=True) + agency_timezone = models.CharField(max_length=200, blank=True, null=True) + agency_lang = models.CharField(max_length=50, blank=True, null=True) + agency_phone = models.CharField(max_length=50, blank=True, null=True) + agency_fare_url = models.CharField(max_length=50, blank=True, null=True) + + class Meta: + 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) + id_tipo_paradero = models.ForeignKey('TipoParadero', models.DO_NOTHING, db_column='id_tipo_paradero', blank=True, null=True) + vigente = models.BooleanField(blank=True, null=True) + stop_code = models.CharField(max_length=100, blank=True, null=True) + stop_name = models.CharField(max_length=100, blank=True, null=True) + stop_desc = models.CharField(max_length=300, blank=True, null=True) + stop_lat = models.FloatField(blank=True, null=True) + stop_lon = models.FloatField(blank=True, null=True) + zone_id = models.CharField(max_length=200, blank=True, null=True) + stop_url = models.CharField(max_length=200, blank=True, null=True) + location_type = models.CharField(max_length=200, blank=True, null=True) + parent_station = models.CharField(max_length=200, blank=True, null=True) + stop_timezonene_id = models.CharField(max_length=200, blank=True, null=True) + wheelchair_boarding = models.DecimalField(max_digits=2, decimal_places=0, blank=True, null=True) + + class Meta: + managed = False + db_table = 'paradero' + + +class ParaderoDistancia(models.Model): + trip_id = models.TextField(blank=True, null=True) + stop_id_inicio = models.TextField(blank=True, null=True) + stop_id_fin = models.TextField(blank=True, null=True) + stop_sequence = models.IntegerField(blank=True, null=True) + km = models.FloatField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'paradero_distancia' + + +class ParaderoImagen(models.Model): + id_paradero_imagen = models.AutoField(primary_key=True) + id_paradero = models.ForeignKey(Paradero, models.DO_NOTHING, db_column='id_paradero') + imagen = models.BinaryField(blank=True, null=True) + content_type = models.CharField(max_length=50, blank=True, null=True) + + class Meta: + 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) + id_comuna = models.ForeignKey(Comuna, models.DO_NOTHING, db_column='id_comuna', blank=True, null=True) + dv = models.CharField(max_length=1, blank=True, null=True) + nombres = models.CharField(max_length=100, blank=True, null=True) + apellido_a = models.CharField(max_length=100, blank=True, null=True) + apellido_b = models.CharField(max_length=100, blank=True, null=True) + fono = models.CharField(max_length=100, blank=True, null=True) + email = models.CharField(max_length=100, blank=True, null=True) + fecha_nacimiento = models.DateField(blank=True, null=True) + direccion = models.CharField(max_length=100, blank=True, null=True) + + class Meta: + managed = False + db_table = 'persona' + + +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) + descripcion = models.CharField(max_length=1000, blank=True, null=True) + url_gtfs_rt = models.CharField(max_length=100, blank=True, null=True) + api_key = models.CharField(max_length=100, blank=True, null=True) + vigente = models.BooleanField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'red_transporte' + db_table_comment = 'Tabla que contiene las diferentes tipos de red de transporte, como son los de transporte publico, trenes, colectivos, etc.' + + +class Region(models.Model): + id_region = models.IntegerField(primary_key=True) + nombre_region = models.CharField(max_length=100) + + class Meta: + managed = False + db_table = 'region' + + +class Rol(models.Model): + id_rol = models.IntegerField(primary_key=True) + nombre_rol = models.CharField(max_length=100) + + class Meta: + managed = False + db_table = 'rol' + + +class RolAplicacion(models.Model): + id_rol_app = models.AutoField(primary_key=True) + solo_visualizar = models.BooleanField(blank=True, null=True) + id_aplicacion = models.ForeignKey(Aplicacion, models.DO_NOTHING, db_column='id_aplicacion') + id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol') + + class Meta: + managed = False + db_table = 'rol_aplicacion' + unique_together = (('id_aplicacion', 'id_rol'),) + + +class RolLinea(models.Model): + id_rol_linea = models.AutoField(primary_key=True) + id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea') + id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol') + + class Meta: + managed = False + db_table = 'rol_linea' + unique_together = (('id_rol', 'id_linea'),) + + +class SpatialRefSys(models.Model): + srid = models.IntegerField(primary_key=True) + auth_name = models.CharField(max_length=256, blank=True, null=True) + auth_srid = models.IntegerField(blank=True, null=True) + srtext = models.CharField(max_length=2048, blank=True, null=True) + proj4text = models.CharField(max_length=2048, blank=True, null=True) + + class Meta: + managed = False + db_table = 'spatial_ref_sys' + + +class TipoDispositivo(models.Model): + id_tipo_dispositivo = models.IntegerField(primary_key=True) + descripcion = models.CharField(max_length=50) + + class Meta: + 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) + + class Meta: + 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) + + class Meta: + managed = False + db_table = 'tipo_transporte' + + +class TipoTratamientoPersona(models.Model): + id_tipo_tratamiento = models.IntegerField(primary_key=True) + tratamiento = models.CharField(max_length=50, blank=True, null=True) + + class Meta: + managed = False + 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) + + class Meta: + 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) + vigente = models.BooleanField(blank=True, null=True) + superuser = models.BooleanField(blank=True, null=True) + id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol') + + class Meta: + managed = False + db_table = 'usuario' + + +class UsuarioClave(models.Model): + login = models.OneToOneField(Usuario, models.DO_NOTHING, db_column='login', primary_key=True) + clave = models.CharField(max_length=60, blank=True, null=True) + clave_anterior = models.CharField(max_length=60, blank=True, null=True) + fecha_modificacion = models.DateField(blank=True, null=True) + codigo = models.DecimalField(max_digits=8, decimal_places=0, blank=True, null=True) + + class Meta: + managed = False + db_table = 'usuario_clave' + + +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) + vigente = models.BooleanField(blank=True, null=True) + + class Meta: + 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') + vigente = models.BooleanField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'vehiculo_linea' + unique_together = (('patente', 'id_linea'),) + + +class ZAgency(models.Model): + agency_id = models.TextField(blank=True, null=True) + agency_name = models.TextField(blank=True, null=True) + agency_url = models.TextField(blank=True, null=True) + agency_timezone = models.TextField(blank=True, null=True) + agency_lang = models.TextField(blank=True, null=True) + agency_phone = models.TextField(blank=True, null=True) + agency_fare_url = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_agency' + + +class ZCalendar(models.Model): + service_id = models.TextField(blank=True, null=True) + start_date = models.TextField(blank=True, null=True) + end_date = models.TextField(blank=True, null=True) + monday = models.TextField(blank=True, null=True) + tuesday = models.TextField(blank=True, null=True) + wednesday = models.TextField(blank=True, null=True) + thursday = models.TextField(blank=True, null=True) + friday = models.TextField(blank=True, null=True) + saturday = models.TextField(blank=True, null=True) + sunday = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_calendar' + + +class ZFeedInfo(models.Model): + feed_publisher_name = models.TextField(blank=True, null=True) + feed_publisher_url = models.TextField(blank=True, null=True) + feed_lang = models.TextField(blank=True, null=True) + feed_start_date = models.TextField(blank=True, null=True) + feed_end_date = models.TextField(blank=True, null=True) + feed_version = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_feed_info' + + +class ZRoutes(models.Model): + route_id = models.TextField(blank=True, null=True) + agency_id = models.TextField(blank=True, null=True) + route_short_name = models.TextField(blank=True, null=True) + route_long_name = models.TextField(blank=True, null=True) + route_desc = models.TextField(blank=True, null=True) + route_type = models.TextField(blank=True, null=True) + route_url = models.TextField(blank=True, null=True) + route_color = models.TextField(blank=True, null=True) + route_text_color = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_routes' + + +class ZShapes(models.Model): + shape_id = models.TextField(blank=True, null=True) + shape_pt_lat = models.TextField(blank=True, null=True) + shape_pt_lon = models.TextField(blank=True, null=True) + shape_pt_sequence = models.TextField(blank=True, null=True) + shape_dist_traveled = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_shapes' + + +class ZStopTimes(models.Model): + trip_id = models.TextField(blank=True, null=True) + arrival_time = models.TextField(blank=True, null=True) + departure_time = models.TextField(blank=True, null=True) + stop_id = models.TextField(blank=True, null=True) + stop_sequence = models.TextField(blank=True, null=True) + stop_headsign = models.TextField(blank=True, null=True) + pickup_type = models.TextField(blank=True, null=True) + drop_off_type = models.TextField(blank=True, null=True) + timepoint = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_stop_times' + + +class ZStops(models.Model): + stop_id = models.TextField(blank=True, null=True) + stop_code = models.TextField(blank=True, null=True) + stop_name = models.TextField(blank=True, null=True) + stop_desc = models.TextField(blank=True, null=True) + stop_lat = models.TextField(blank=True, null=True) + stop_lon = models.TextField(blank=True, null=True) + zone_id = models.TextField(blank=True, null=True) + stop_url = models.TextField(blank=True, null=True) + location_type = models.TextField(blank=True, null=True) + parent_station = models.TextField(blank=True, null=True) + wheelchair_boarding = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_stops' + + +class ZTrips(models.Model): + route_id = models.TextField(blank=True, null=True) + service_id = models.CharField(max_length=50, blank=True, null=True) + trip_id = models.TextField(blank=True, null=True) + trip_headsign = models.TextField(blank=True, null=True) + trip_short_name = models.TextField(blank=True, null=True) + direction_id = models.TextField(blank=True, null=True) + block_id = models.TextField(blank=True, null=True) + shape_id = models.TextField(blank=True, null=True) + wheelchair_accessible = models.TextField(blank=True, null=True) + bikes_allowed = models.TextField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'z_trips' diff --git a/project/api/serializers.py b/project/api/serializers.py index edca5f2..7286e0b 100755 --- a/project/api/serializers.py +++ b/project/api/serializers.py @@ -138,4 +138,14 @@ class RolLineaSerializer(serializers.ModelSerializer): class LetreroLUR_Serializer(serializers.ModelSerializer): class Meta: model = models.LetreroLUR + fields = '__all__' + +class RedTransporteSerializer(serializers.ModelSerializer): + class Meta: + model = models.RedTransporte + fields = '__all__' + +class GtfsArchivoSerializer(serializers.ModelSerializer): + class Meta: + model = models.GtfsArchivo fields = '__all__' \ No newline at end of file diff --git a/project/api/urls.py b/project/api/urls.py index 6df33dc..150eab3 100755 --- a/project/api/urls.py +++ b/project/api/urls.py @@ -2,7 +2,7 @@ from django.urls import path, include from rest_framework import routers # from api import views from api.views import usuario, auth, aplicacion, tipo, persona, comuna, region, rol, rolaplicacion -from api.views import mapa, linea, letrero_lur, operador +from api.views import mapa, linea, letrero_lur, operador,red_transporte,gtfs_archivo from api.views import paradero, paradero_imagen, linea_paradero from api.views import dispositivo from api.views import rol_linea @@ -26,6 +26,8 @@ router.register('lineas', linea.LineaViewSet) router.register('lineas-paradero', linea_paradero.LineaParaderoViewSet) router.register('letreros-lur', letrero_lur.LetreroLUR_ViewSet) router.register('operadores', operador.OperadorViewSet) +router.register('red-transporte', red_transporte.RedTransporteViewSet) +router.register('gtfs-archivo', gtfs_archivo.GtfsArchivoViewSet) router.register('roles', rol.RolViewSet) router.register('rolyaplicacion', rolaplicacion.RolAplicacionViewSet, basename='rol_aplicacion') router.register('roles-lineas', rol_linea.RolLineaViewSet, basename='rol_linea') diff --git a/project/api/views/actualiza_GTFS.sql b/project/api/views/actualiza_GTFS.sql index d902ea0..46d81d4 100644 --- a/project/api/views/actualiza_GTFS.sql +++ b/project/api/views/actualiza_GTFS.sql @@ -6,7 +6,7 @@ ALTER TABLE rol_linea drop CONSTRAINT IF EXISTS rol_linea_id_linea_fkey; ALTER TABLE linea_paradero drop CONSTRAINT IF EXISTS linea_paradero_id_linea_fkey; ----- - +/* update operador set vigente =false where id_operador not in (select agency_id from z_agency za); @@ -26,7 +26,7 @@ from z_agency za where agency_id not in (select id_operador from operador za); ----- - +*/ delete from gtfs_calendar ; ----- @@ -36,11 +36,11 @@ select service_id, monday::bool , tuesday::bool , wednesday::bool , thursday::bo from z_calendar zc; ----- - +/* update paradero p set vigente = false where id_paradero::text not in (select stop_id from z_stops ); - +*/ ----- update paradero @@ -69,55 +69,92 @@ delete from linea_paradero; ----- -delete from linea ; +/*delete from linea*/ ; ----- +update linea +set vigente = false +where id_red in (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' ) +and id_linea not in (select trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) + from z_routes zr + inner join z_trips zt + on zr.route_id =zt.route_id + + ); + +update linea +set vigente = true +where id_red in (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' ) +and id_linea in (select trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) + from z_routes zr + inner join z_trips zt + on zr.route_id =zt.route_id + + ); + +/* +update linea +route_short_name = (select substring(zt.trip_headsign FROM '(\S+) -') as route_short_name ) +route_desc = +route_type = +route_url +route_color +route_text_color +route_long_name +vigente +id_red = (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) +id_linea +*/ insert into linea select distinct trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, - zr.agency_id , + null,--zr.agency_id , substring(zt.trip_headsign FROM '(\S+) -') as route_short_name , zr.route_desc , zr.route_type::numeric , zr.route_url, zr.route_color , zr.route_text_color , - zt.trip_headsign as route_long_name , true + zt.trip_headsign as route_long_name , true , + (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red from z_routes zr inner join z_trips zt on zr.route_id =zt.route_id and replace (zt.trip_headsign,' ','') =replace ((SPLIT_PART(route_long_name, '-', 1)||'-'||SPLIT_PART(route_long_name, '-', 2)),' ','') where route_long_name not like '%'||route_short_name ||'%' +and (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea ) union select distinct trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, - zr.agency_id , + null,--zr.agency_id , substring(zt.trip_headsign FROM '(\S+) -') as route_short_name , zr.route_desc , zr.route_type::numeric , zr.route_url, zr.route_color , zr.route_text_color , - zt.trip_headsign as route_long_name , true + zt.trip_headsign as route_long_name , true , + (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red from z_routes zr inner join z_trips zt on zr.route_id =zt.route_id and replace (zt.trip_headsign,' ','') =replace ((SPLIT_PART(route_long_name, '-', 3)||'-'||SPLIT_PART(route_long_name, '-', 4)),' ','') where route_long_name not like '%'||route_short_name ||'%' - +and (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea ) union select distinct trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) as route_id, - zr.agency_id , + null,--zr.agency_id , route_short_name , zr.route_desc , zr.route_type::numeric , zr.route_url, zr.route_color , zr.route_text_color , - zt.trip_headsign as route_long_name , true + zt.trip_headsign as route_long_name , true , + (select id_red from gtfs_archivo where trim(upper(status))='PROCESANDO' limit 1) as id_red from z_routes zr inner join z_trips zt on zr.route_id =zt.route_id @@ -126,6 +163,7 @@ select distinct or route_long_name like '%'||route_short_name ||'%' ) +where (trim(zr.route_id)||'-'||trim(zt.direction_id::varchar) ) not in (select id_linea from linea ) order by 1; ----- @@ -192,6 +230,10 @@ SET stop_name = REGEXP_REPLACE( 'gi' ); +----- + 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); + ----- ALTER TABLE rol_linea ADD CONSTRAINT rol_linea_id_linea_fkey FOREIGN KEY (id_linea) REFERENCES linea(id_linea); diff --git a/project/api/views/gtfs_archivo.py b/project/api/views/gtfs_archivo.py new file mode 100644 index 0000000..0b3437a --- /dev/null +++ b/project/api/views/gtfs_archivo.py @@ -0,0 +1,24 @@ + +from rest_framework import viewsets +from rest_framework.response import Response +from rest_framework.decorators import action +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework import status +from .. import models , serializers +from django.db import models as dj_models + +class GtfsArchivoViewSet(viewsets.ModelViewSet): + queryset = models.GtfsArchivo.objects.all() + serializer_class = serializers.GtfsArchivoSerializer + filter_backends = [DjangoFilterBackend] + filterset_fields = ['id_gtfs', 'id_red', 'archivo','valida_from','created','usuario','vigente','status'] + + + def create(self, request, *args, **kwargs): + # se indica que si no se indico el id, entonces sea el maximo + 1 + if not request.data.get('id_gtfs', None): + max_id = models.GtfsArchivo.objects.aggregate(dj_models.Max('id_gtfs'))['id_gtfs__max'] + new_id = max_id + 1 if max_id is not None else 1 + request.data['id_gtfs'] = new_id + + return super().create(request, *args, **kwargs) \ No newline at end of file diff --git a/project/api/views/operador.py b/project/api/views/operador.py index 2f7ecbb..40a350e 100755 --- a/project/api/views/operador.py +++ b/project/api/views/operador.py @@ -3,6 +3,7 @@ from rest_framework import viewsets from rest_framework.response import Response from rest_framework.decorators import action from django_filters.rest_framework import DjangoFilterBackend +from rest_framework import status from .. import models, serializers class OperadorViewSet(viewsets.ModelViewSet): @@ -10,3 +11,16 @@ class OperadorViewSet(viewsets.ModelViewSet): serializer_class = serializers.OperadorSerializer filter_backends = [DjangoFilterBackend] filterset_fields = ['id_region', 'nombre_operador', 'vigente'] + + def create(self, request, *args, **kwargs): + # Comprueba si 'id_operador' está presente en la petición y no está vacío + id_operador = request.data.get('id_operador') + if not id_operador: + # Si 'id_operador' no está presente o está vacío, retorna un error 400 + return Response( + {"error": "No se puede crear el operador: 'id_operador' no proporcionado."}, + status=status.HTTP_400_BAD_REQUEST + ) + + # Si 'id_operador' está presente, procede con la creación normal + return super().create(request, *args, **kwargs) \ No newline at end of file diff --git a/project/api/views/red_transporte.py b/project/api/views/red_transporte.py new file mode 100644 index 0000000..83855b9 --- /dev/null +++ b/project/api/views/red_transporte.py @@ -0,0 +1,24 @@ + +from rest_framework import viewsets +from rest_framework.response import Response +from rest_framework.decorators import action +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework import status +from .. import models , serializers +from django.db import models as dj_models + +class RedTransporteViewSet(viewsets.ModelViewSet): + queryset = models.RedTransporte.objects.all() + serializer_class = serializers.RedTransporteSerializer + filter_backends = [DjangoFilterBackend] + filterset_fields = ['id_red', 'nombre_red', 'descripcion','vigente'] + + + def create(self, request, *args, **kwargs): + # se indica que si no se indico el id, entonces sea el maximo + 1 + if not request.data.get('id_red', None): + max_id = models.RedTransporte.objects.aggregate(dj_models.Max('id_red'))['id_red__max'] + new_id = max_id + 1 if max_id is not None else 1 + request.data['id_red'] = new_id + + return super().create(request, *args, **kwargs) \ No newline at end of file