avance con rutas de servicios en lineas

develop/Rodrigo/Backend
Francisco Sandoval 2023-08-15 22:22:38 -04:00
parent 15e5e389b9
commit df7a02a1c7
24 changed files with 97 additions and 142 deletions

0
project/api/__init__.py 100644 → 100755
View File

20
project/api/admin.py 100644 → 100755
View File

@ -1,13 +1,13 @@
from django.contrib import admin from django.contrib import admin
from .models import Usuario, Rol, UsuarioRol # from .models import Usuario, Rol, UsuarioRol
from .models import Aplicacion, RolAplicacion # from .models import Aplicacion, RolAplicacion
from .models import Persona, TipoTratamientoPersona # from .models import Persona, TipoTratamientoPersona
# Register your models here. # Register your models here.
admin.site.register(Usuario) # admin.site.register(Usuario)
admin.site.register(UsuarioRol) # admin.site.register(UsuarioRol)
admin.site.register(Persona) # admin.site.register(Persona)
admin.site.register(TipoTratamientoPersona) # admin.site.register(TipoTratamientoPersona)
admin.site.register(Rol) # admin.site.register(Rol)
admin.site.register(RolAplicacion) # admin.site.register(RolAplicacion)
admin.site.register(Aplicacion) # admin.site.register(Aplicacion)

0
project/api/apps.py 100644 → 100755
View File

0
project/api/exceptions.py 100644 → 100755
View File

0
project/api/middlewares.py 100644 → 100755
View File

View File

@ -1,101 +0,0 @@
# Generated by Django 4.2.2 on 2023-06-24 17:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Aplicaciones',
fields=[
('id_aplicacion', models.IntegerField(primary_key=True, serialize=False)),
('app', models.CharField(blank=True, max_length=100, null=True)),
('vigente', models.BooleanField(blank=True, null=True)),
],
options={
'db_table': 'aplicaciones',
'managed': False,
},
),
migrations.CreateModel(
name='Persona',
fields=[
('rut', models.DecimalField(decimal_places=0, max_digits=12, primary_key=True, serialize=False)),
('dv', models.CharField(blank=True, max_length=1, null=True)),
('nombres', models.CharField(blank=True, max_length=100, null=True)),
('apellido_a', models.CharField(blank=True, max_length=100, null=True)),
('apellido_b', models.CharField(blank=True, max_length=100, null=True)),
('fono', models.CharField(blank=True, max_length=100, null=True)),
('email', models.CharField(blank=True, max_length=100, null=True)),
('fecha_nacimiento', models.DateField(blank=True, null=True)),
],
options={
'db_table': 'persona',
'managed': False,
},
),
migrations.CreateModel(
name='Rol',
fields=[
('id_rol', models.IntegerField(primary_key=True, serialize=False)),
('nombre_rol', models.CharField(max_length=100)),
],
options={
'db_table': 'rol',
'managed': False,
},
),
migrations.CreateModel(
name='TipoTratamientoPersona',
fields=[
('id_tipo_tratamiento', models.IntegerField(primary_key=True, serialize=False)),
('tratamiento', models.CharField(blank=True, max_length=50, null=True)),
],
options={
'db_table': 'tipo_tratamiento_persona',
'db_table_comment': 'Establece el tratamiento de como dirigirse hacia una persona:\r\nEjemplo\r\nSe<EFBFBD>or\r\nSe<EFBFBD>ora\r\nSrta',
'managed': False,
},
),
migrations.CreateModel(
name='Usuario',
fields=[
('login', models.CharField(max_length=20, primary_key=True, serialize=False)),
('clave', models.CharField(blank=True, max_length=20, null=True)),
('vigente', models.BooleanField(blank=True, null=True)),
],
options={
'db_table': 'usuario',
'managed': False,
},
),
migrations.CreateModel(
name='UsuarioRol',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('vigente', models.BooleanField(blank=True, null=True)),
],
options={
'db_table': 'usuario_rol',
'managed': False,
},
),
migrations.CreateModel(
name='RolAplicacion',
fields=[
('id_aplicacion', models.OneToOneField(db_column='id_aplicacion', on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.aplicaciones')),
('solo_visualizar', models.BooleanField(blank=True, null=True)),
],
options={
'db_table': 'rol_aplicacion',
'managed': False,
},
),
]

68
project/api/models.py 100644 → 100755
View File

@ -5,10 +5,8 @@
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior # * 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 # * 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. # Feel free to rename the models, but don't rename db_table values or field names.
from typing import Collection, Optional
from django.db import models from django.db import models
from .validaciones import rut_valido from .validaciones import rut_valido
import logging
class Aplicacion(models.Model): class Aplicacion(models.Model):
@ -64,7 +62,7 @@ class Funcionario(models.Model):
class GtfsCalendar(models.Model): class GtfsCalendar(models.Model):
id_linea = models.OneToOneField('Linea', models.DO_NOTHING, db_column='id_linea', primary_key=True) id_linea = models.CharField(primary_key=True, max_length=150)
monday = models.BooleanField(blank=True, null=True) monday = models.BooleanField(blank=True, null=True)
tuesday = models.BooleanField(blank=True, null=True) tuesday = models.BooleanField(blank=True, null=True)
wednesday = models.BooleanField(blank=True, null=True) wednesday = models.BooleanField(blank=True, null=True)
@ -79,7 +77,7 @@ class GtfsCalendar(models.Model):
class GtfsFrequencie(models.Model): class GtfsFrequencie(models.Model):
id_trips = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trips', 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)
end_time = models.TimeField(blank=True, null=True) end_time = models.TimeField(blank=True, null=True)
headway_secs = models.IntegerField(blank=True, null=True) headway_secs = models.IntegerField(blank=True, null=True)
@ -109,6 +107,13 @@ class GtfsRoutes(models.Model):
route_color = models.CharField(max_length=6, blank=True, null=True) route_color = models.CharField(max_length=6, blank=True, null=True)
route_text_color = models.CharField(max_length=6, blank=True, null=True) route_text_color = models.CharField(max_length=6, blank=True, null=True)
route_sort_order = models.IntegerField(blank=True, null=True) route_sort_order = models.IntegerField(blank=True, null=True)
route_id = models.IntegerField(blank=True, null=True)
agency_id = models.CharField(max_length=50, blank=True, null=True)
route_short_name = models.CharField(max_length=50, blank=True, null=True)
route_long_name = models.CharField(max_length=50, blank=True, null=True)
route_desc = models.CharField(max_length=50, blank=True, null=True)
route_type = models.IntegerField(blank=True, null=True)
route_url = models.CharField(max_length=50, blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -116,20 +121,24 @@ class GtfsRoutes(models.Model):
class GtfsShape(models.Model): class GtfsShape(models.Model):
id_shapes = models.IntegerField(primary_key=True) id_shape = models.DecimalField(max_digits=18, decimal_places=0)
shape_pt_lat = models.TextField(blank=True, null=True) # This field type is a guess. shape_pt_lat = models.FloatField(blank=True, null=True)
shape_pt_lon = models.TextField(blank=True, null=True) # This field type is a guess. shape_pt_lon = models.FloatField(blank=True, null=True)
shape_pt_sequence = models.IntegerField(blank=True, null=True) shape_pt_sequence = models.IntegerField(blank=True, null=True)
shaoe_dist_traveled = models.FloatField(blank=True, null=True) shaoe_dist_traveled = models.FloatField(blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
db_table = 'gtfs_shape' db_table = 'gtfs_shape'
unique_together = (('id_shape','shape_pt_sequence'),)
def __str__(self):
return f"{self.id_shape}-{self.shape_pt_sequence}"
class GtfsStopTimes(models.Model): 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_trips) found, that is not supported. The first column is selected. 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_trips = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trips') id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip')
arrival_time = models.TimeField(blank=True, null=True) arrival_time = models.TimeField(blank=True, null=True)
stop_sequence = models.IntegerField(blank=True, null=True) stop_sequence = models.IntegerField(blank=True, null=True)
stop_headsign = models.CharField(max_length=100, blank=True, null=True) stop_headsign = models.CharField(max_length=100, blank=True, null=True)
@ -137,15 +146,15 @@ class GtfsStopTimes(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'gtfs_stop_times' db_table = 'gtfs_stop_times'
unique_together = (('id_paradero', 'id_trips'),) unique_together = (('id_paradero', 'id_trip'),)
class GtfsTrips(models.Model): class GtfsTrips(models.Model):
id_trips = models.IntegerField(primary_key=True) id_trip = models.CharField(primary_key=True, max_length=150)
id_routes = models.ForeignKey(GtfsRoutes, models.DO_NOTHING, db_column='id_routes', blank=True, null=True) id_routes = models.ForeignKey(GtfsRoutes, models.DO_NOTHING, db_column='id_routes', blank=True, null=True)
id_linea = models.ForeignKey('Linea', models.DO_NOTHING, db_column='id_linea', blank=True, null=True) id_linea = models.CharField(max_length=150, blank=True, null=True)
id_shapes = models.ForeignKey(GtfsShape, models.DO_NOTHING, db_column='id_shapes', blank=True, null=True) id_shapes = models.IntegerField(blank=True, null=True)
id_trips_regreso = models.ForeignKey('self', models.DO_NOTHING, db_column='id_trips_regreso', 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_headsign = models.CharField(max_length=100, blank=True, null=True)
short_name = models.CharField(max_length=100, blank=True, null=True) short_name = models.CharField(max_length=100, blank=True, null=True)
direccion_id = models.IntegerField(blank=True, null=True) direccion_id = models.IntegerField(blank=True, null=True)
@ -156,13 +165,16 @@ class GtfsTrips(models.Model):
class Linea(models.Model): class Linea(models.Model):
id_linea = models.IntegerField(primary_key=True) id_linea = models.CharField(max_length=150)
id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True) service_id = models.CharField(max_length=150, blank=True, null=True)
iid_tipo_transporte = models.ForeignKey('TipoTransporte', models.DO_NOTHING, db_column='iid_tipo_transporte', blank=True, null=True) trip_id = models.CharField(primary_key=True, max_length=150, blank=False, null=False)
id_region = models.ForeignKey('Region', models.DO_NOTHING, db_column='id_region', blank=True, null=True) trip_headsign = models.CharField(max_length=150, blank=True, null=True)
vigente = models.BooleanField(blank=True, null=True) trip_short_name = models.CharField(max_length=150, blank=True, null=True)
nombre = models.CharField(max_length=100, blank=True, null=True) direction_id = models.CharField(max_length=150, blank=True, null=True)
url = models.CharField(max_length=300, blank=True, null=True) block_id = models.CharField(max_length=150, blank=True, null=True)
shape_id = models.CharField(max_length=150, blank=True, null=True)
wheelchair_accessible = models.CharField(max_length=150, blank=True, null=True)
bikes_allowed = models.CharField(max_length=150, blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -170,9 +182,10 @@ class Linea(models.Model):
class Operador(models.Model): class Operador(models.Model):
id_operador = models.IntegerField(primary_key=True) 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)
vigente = models.BooleanField(blank=True, null=True) vigente = models.BooleanField(blank=True, null=True)
nombre_operador = models.CharField(max_length=150, blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -187,8 +200,8 @@ class Paradero(models.Model):
stop_code = models.CharField(max_length=100, 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_name = models.CharField(max_length=100, blank=True, null=True)
stop_desc = models.CharField(max_length=300, blank=True, null=True) stop_desc = models.CharField(max_length=300, blank=True, null=True)
stop_lat = models.TextField(blank=True, null=True) # This field type is a guess. stop_lat = models.FloatField(blank=True, null=True)
stop_lon = models.TextField(blank=True, null=True) # This field type is a guess. stop_lon = models.FloatField(blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -198,7 +211,7 @@ class Paradero(models.Model):
class ParaderoImagen(models.Model): class ParaderoImagen(models.Model):
id_paradero = models.OneToOneField(Paradero, models.DO_NOTHING, db_column='id_paradero', primary_key=True) id_paradero = models.OneToOneField(Paradero, models.DO_NOTHING, db_column='id_paradero', primary_key=True)
imagen = models.BinaryField(blank=True, null=True) imagen = models.BinaryField(blank=True, null=True)
content_type = models.CharField(max_length=100, blank=False, null=True) content_type = models.CharField(max_length=50, blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -231,6 +244,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)
@ -291,7 +305,7 @@ class TipoParadero(models.Model):
class TipoTransporte(models.Model): class TipoTransporte(models.Model):
iid_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)
class Meta: class Meta:
@ -364,7 +378,7 @@ class Vehiculo(models.Model):
class VehiculoLinea(models.Model): class VehiculoLinea(models.Model):
patente = models.ForeignKey(Vehiculo, models.DO_NOTHING, db_column='patente', blank=True, null=True) patente = models.ForeignKey(Vehiculo, models.DO_NOTHING, db_column='patente', blank=True, null=True)
id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea', blank=True, null=True) id_linea = models.CharField(max_length=150, blank=True, null=True)
vigente = models.BooleanField(blank=True, null=True) vigente = models.BooleanField(blank=True, null=True)
class Meta: class Meta:

0
project/api/schemas.py 100644 → 100755
View File

5
project/api/serializers.py 100644 → 100755
View File

@ -54,6 +54,11 @@ class ParaderoSerializer(serializers.ModelSerializer):
model = models.Paradero model = models.Paradero
fields = '__all__' fields = '__all__'
class LineaSerializer(serializers.ModelSerializer):
class Meta:
model = models.Linea
fields = '__all__'
class UsuarioSerializer(serializers.ModelSerializer): class UsuarioSerializer(serializers.ModelSerializer):
# muestro informacion de persona en un objeto aparte # muestro informacion de persona en un objeto aparte
persona = serializers.SerializerMethodField() persona = serializers.SerializerMethodField()

0
project/api/tests.py 100644 → 100755
View File

4
project/api/urls.py 100644 → 100755
View File

@ -2,7 +2,7 @@ from django.urls import path, include
from rest_framework import routers from rest_framework import routers
# from api import views # from api import views
from api.views import usuario, auth, aplicacion, tipo, persona, comuna, region, paradero from api.views import usuario, auth, aplicacion, tipo, persona, comuna, region, paradero
from api.views import mapa from api.views import mapa, linea
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register('aplicaciones', aplicacion.AplicacionViewSet) router.register('aplicaciones', aplicacion.AplicacionViewSet)
@ -16,10 +16,12 @@ router.register('tipos/vehiculo', tipo.TipoVehiculoViewSet)
router.register('comunas', comuna.ComunaViewSet) router.register('comunas', comuna.ComunaViewSet)
router.register('regiones', region.RegionViewSet) router.register('regiones', region.RegionViewSet)
router.register('paraderos', paradero.ParaderoViewSet) router.register('paraderos', paradero.ParaderoViewSet)
router.register('lineas', linea.LineaViewSet)
urlpatterns = [ urlpatterns = [
path('', include(router.urls)), path('', include(router.urls)),
path('auth/', auth.jwt_login, name='auth'), path('auth/', auth.jwt_login, name='auth'),
path('mapas/paraderos/', mapa.paraderos, name='mapa-paraderos'), path('mapas/paraderos/', mapa.paraderos, name='mapa-paraderos'),
path('mapas/rutas/', mapa.rutas, name='mapa-rutas'),
path('paraderos/image/<int:id>/', paradero.image, name='paradero-image') path('paraderos/image/<int:id>/', paradero.image, name='paradero-image')
] ]

0
project/api/validaciones.py 100644 → 100755
View File

0
project/api/views/__init__.py 100644 → 100755
View File

0
project/api/views/aplicacion.py 100644 → 100755
View File

0
project/api/views/auth.py 100644 → 100755
View File

0
project/api/views/comuna.py 100644 → 100755
View File

View File

@ -0,0 +1,17 @@
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework.decorators import action
from .. import models, serializers
class LineaViewSet(viewsets.ModelViewSet):
queryset = models.Linea.objects.all()
serializer_class = serializers.LineaSerializer
@action(detail=False, methods=['GET'])
def servicios(self, request):
distinct_values = models.Linea.objects \
.values('id_linea', 'service_id') \
.order_by('id_linea', 'service_id') \
.distinct()
return Response(distinct_values)

24
project/api/views/mapa.py 100644 → 100755
View File

@ -3,18 +3,18 @@ from django.http import JsonResponse
from rest_framework.decorators import action, api_view, schema from rest_framework.decorators import action, api_view, schema
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from ..models import Paradero, ParaderoImagen from ..models import Paradero, ParaderoImagen
from ..models import Linea, GtfsShape
from .paradero import url_image_paradero from .paradero import url_image_paradero
from logging import error from logging import error
google_api_key = 'AIzaSyDnFO9w_SsodjBuY5tOK8-kQJns_l5klQ4'
center = {'lat': -36.8077884, 'lng': -73.0775401}
@csrf_exempt @csrf_exempt
@action(detail=False, methods=['get']) @action(detail=False, methods=['get'])
@api_view(['GET']) @api_view(['GET'])
# @schema(schemas.AuthSchema())
def paraderos(request): def paraderos(request):
google_api_key = 'AIzaSyDnFO9w_SsodjBuY5tOK8-kQJns_l5klQ4'
zoom = 17 zoom = 17
center = {'lat': -36.8077884, 'lng': -73.0775401}
marks = [] marks = []
paraderos = Paradero.objects.all() paraderos = Paradero.objects.all()
@ -37,3 +37,21 @@ def paraderos(request):
'center': center, 'center': center,
'marks': marks 'marks': marks
}) })
@csrf_exempt
@action(detail=False, methods=['get'])
@api_view(['GET'])
def rutas(request):
id_linea = request.GET.get('id_linea')
service_id = request.GET.get('service_id')
linea = Linea.objects \
.filter(id_linea = id_linea, service_id = service_id, direction_id = '0') \
.values('shape_id') \
.first()
rutas = GtfsShape.objects \
.filter(id_shape = linea['shape_id']) \
.order_by('shape_pt_sequence') \
.values('shape_pt_lat','shape_pt_lon','shape_pt_sequence')
return JsonResponse(list(rutas), safe=False)

0
project/api/views/paradero.py 100644 → 100755
View File

0
project/api/views/persona.py 100644 → 100755
View File

0
project/api/views/region.py 100644 → 100755
View File

0
project/api/views/tipo.py 100644 → 100755
View File

0
project/api/views/usuario.py 100644 → 100755
View File