se agrega datos de db en GetInfoDevice
parent
c52860eda9
commit
04c1802b69
|
@ -61,4 +61,9 @@ Content-Type: application/json
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
###
|
||||
|
||||
GET {{server}}/proto/
|
||||
Authorization: Bearer {{token}}
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue