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 rest_framework import viewsets
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
|
from django.db import connection
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from .. import models, serializers
|
from .. import models, serializers
|
||||||
import json
|
import json
|
||||||
|
@ -42,68 +43,39 @@ class DispositivoViewSet(viewsets.ModelViewSet):
|
||||||
@action(detail=False, methods=['post'])
|
@action(detail=False, methods=['post'])
|
||||||
def getInfoDevice(self, request, pk=None):
|
def getInfoDevice(self, request, pk=None):
|
||||||
input = json.loads(request.body)
|
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 = {
|
record = models.Paradero.objects \
|
||||||
"Linea": "5487",
|
.filter(dispositivo__id_dispositivo=getInfoDevice['idDispositivo']) \
|
||||||
"Descripcion": "Centauro",
|
.annotate(nro_paradero=F('id_paradero'), nombre_paradero=F('stop_name')) \
|
||||||
"TipoLocomocion": 1,
|
.first()
|
||||||
"colorFondo": "Hexadecimal",
|
|
||||||
"colorLetra": "Hexadecimal",
|
query = "SELECT json_data \
|
||||||
"Llegadas": [
|
from gtfs_posiciones_json \
|
||||||
{
|
where stop_id = %s"
|
||||||
"Patente": "PLKJ-32",
|
|
||||||
"Planificada": "15:13",
|
params = [ record.nro_paradero ]
|
||||||
"EstimadaGPS": "",
|
|
||||||
"DistanciaGPS": "",
|
with connection.cursor() as cursor:
|
||||||
},
|
cursor.execute(query, params)
|
||||||
{
|
row = cursor.fetchone()
|
||||||
"Patente": "GHLK-11",
|
|
||||||
"Planificada": "15:39",
|
connection.close()
|
||||||
"EstimadaGPS": "",
|
|
||||||
"DistanciaGPS": "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Patente": "DFQW-55",
|
|
||||||
"Planificada": "16:22",
|
|
||||||
"EstimadaGPS": "",
|
|
||||||
"DistanciaGPS": "",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Mensajelinea": "Sin info. GPS, la informacion es estimada"
|
|
||||||
}
|
|
||||||
|
|
||||||
detalle_lineas = []
|
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({
|
return JsonResponse({
|
||||||
"GetInfoDeviceResponse": {
|
"GetInfoDeviceResponse": {
|
||||||
|
|
Loading…
Reference in New Issue