From 04c1802b69f6ceb96d748307ca6d94d0c22a7f67 Mon Sep 17 00:00:00 2001 From: Francisco Sandoval Date: Sun, 19 Nov 2023 17:17:56 -0300 Subject: [PATCH] se agrega datos de db en GetInfoDevice --- docs/rest/dispositivo.rest | 5 ++ project/api/views/dispositivo.py | 88 +++++++++++--------------------- 2 files changed, 35 insertions(+), 58 deletions(-) diff --git a/docs/rest/dispositivo.rest b/docs/rest/dispositivo.rest index b057709..b229e05 100644 --- a/docs/rest/dispositivo.rest +++ b/docs/rest/dispositivo.rest @@ -61,4 +61,9 @@ Content-Type: application/json } + + ### + +GET {{server}}/proto/ +Authorization: Bearer {{token}} \ No newline at end of file diff --git a/project/api/views/dispositivo.py b/project/api/views/dispositivo.py index 6c3d769..9a3de57 100644 --- a/project/api/views/dispositivo.py +++ b/project/api/views/dispositivo.py @@ -2,6 +2,7 @@ from rest_framework import viewsets from django.http import JsonResponse from django.db.models import F +from django.db import connection from rest_framework.decorators import action from .. import models, serializers import json @@ -42,68 +43,39 @@ class DispositivoViewSet(viewsets.ModelViewSet): @action(detail=False, methods=['post']) def getInfoDevice(self, request, pk=None): input = json.loads(request.body) + getInfoDevice = input['GetInfoDevice'] - linea1 = { - "Linea": "803010", - "Descripcion": "Tucapel", - "TipoLocomocion": 1, - "colorFondo": "Hexadecimal", - "colorLetra": "Hexadecimal", - "Llegadas": [ - { - "Patente": "RPDA-98", - "Planificada": "", - "EstimadaGPS": "15:08", - "DistanciaGPS": "1.0 KM" - }, - { - "Patente": "WYXYZ-22", - "Planificada": "", - "EstimadaGPS": "15:42", - "DistanciaGPS": "5.0 KM" - }, - { - "Patente": "ABCA-65", - "Planificada": "", - "EstimadaGPS": "16:18", - "DistanciaGPS": "13.4 KM" - } - ], - "Mensajelinea": "" - } - linea2 = { - "Linea": "5487", - "Descripcion": "Centauro", - "TipoLocomocion": 1, - "colorFondo": "Hexadecimal", - "colorLetra": "Hexadecimal", - "Llegadas": [ - { - "Patente": "PLKJ-32", - "Planificada": "15:13", - "EstimadaGPS": "", - "DistanciaGPS": "", - }, - { - "Patente": "GHLK-11", - "Planificada": "15:39", - "EstimadaGPS": "", - "DistanciaGPS": "", - }, - { - "Patente": "DFQW-55", - "Planificada": "16:22", - "EstimadaGPS": "", - "DistanciaGPS": "", - } - ], - "Mensajelinea": "Sin info. GPS, la informacion es estimada" - } + record = models.Paradero.objects \ + .filter(dispositivo__id_dispositivo=getInfoDevice['idDispositivo']) \ + .annotate(nro_paradero=F('id_paradero'), nombre_paradero=F('stop_name')) \ + .first() + + query = "SELECT json_data \ + from gtfs_posiciones_json \ + where stop_id = %s" + + params = [ record.nro_paradero ] + + with connection.cursor() as cursor: + cursor.execute(query, params) + row = cursor.fetchone() + + connection.close() detalle_lineas = [] - detalle_lineas.append(linea1) - detalle_lineas.append(linea2) + + for linea in row[0]: + # logging.error(linea['linea']) + data_linea = { + 'Linea': linea['linea'], + 'Descripcion': linea['Descripcion'], + 'TipoLocomocion': linea['tipo_locomocion'], + 'colorFondo': None, + 'colorLetra': linea['colorLetra'], + 'Llegadas': linea['Llegadas'] + } + detalle_lineas.append(data_linea) return JsonResponse({ "GetInfoDeviceResponse": {