|
@@ -24,6 +24,7 @@ recognizer = FilePerSecondRecognizer
|
|
|
|
|
|
|
|
|
def obt_siguiente_trabajo():
|
|
|
+ log.info("Consultando trabajo")
|
|
|
url = 'https://api.fourier.audio/na/calendario/pendiente?id=%s' % (config['device_id'],)
|
|
|
response = requests.get(url)
|
|
|
return response.json()
|
|
@@ -128,9 +129,13 @@ def procesar_siguiente_pila():
|
|
|
def procesar_trabajo(pendiente):
|
|
|
ciudad = pendiente['origen']
|
|
|
estacion = pendiente['estacion']
|
|
|
- segmento = 10
|
|
|
- if "segmento" in pendiente:
|
|
|
- segmento = int(pendiente["segmento"])
|
|
|
+ confianza = 35
|
|
|
+ segmento = 5
|
|
|
+ #if "segmento" in pendiente:
|
|
|
+ # segmento = int(pendiente["segmento"])
|
|
|
+
|
|
|
+ #if "confianza" in pendiente:
|
|
|
+ # confianza = int(pendiente["confianza"])
|
|
|
|
|
|
# Descarga de anuncios
|
|
|
log.info("Descargando anuncios")
|
|
@@ -145,7 +150,6 @@ def procesar_trabajo(pendiente):
|
|
|
|
|
|
anuncio = descargar_anuncio(i["ruta"])
|
|
|
if anuncio is not None:
|
|
|
- log.info("Listo %s" % (i['ruta'],))
|
|
|
anuncios.append(anuncio)
|
|
|
|
|
|
except Exception as err:
|
|
@@ -158,16 +162,16 @@ def procesar_trabajo(pendiente):
|
|
|
for i in pendiente["media"]:
|
|
|
archivo = descargar_media(ciudad, estacion, i["ruta"])
|
|
|
if archivo is not None:
|
|
|
- log.info("Listo %s %s %s" % (ciudad, estacion, i['ruta'],))
|
|
|
media.append((archivo, i["fecha"], i["timestamp"]))
|
|
|
|
|
|
except Exception as err:
|
|
|
log.info(err)
|
|
|
|
|
|
+ log.info("Inicia la comparacion, tamaño de segmento %s" % (segmento,))
|
|
|
try:
|
|
|
-
|
|
|
dejavu = None
|
|
|
resultados = {}
|
|
|
+ aux = {}
|
|
|
if len(media) > 0 and len(anuncio) > 0:
|
|
|
dejavu = Dejavu({"database_type": "mem"})
|
|
|
try:
|
|
@@ -179,18 +183,17 @@ def procesar_trabajo(pendiente):
|
|
|
log.info(ex)
|
|
|
|
|
|
for anuncio in anuncios:
|
|
|
- log.info("Buscando anuncio %s" % (anuncio,))
|
|
|
- for i in dejavu.recognize(recognizer, anuncio, segmento):
|
|
|
+ for i in dejavu.recognize(recognizer, anuncio, 5):
|
|
|
if not "id" in i:
|
|
|
continue
|
|
|
|
|
|
- if i["confidence"] < 35:
|
|
|
- continue
|
|
|
+ nombre_anuncio = os.path.split(anuncio)[-1]
|
|
|
+ id = id_by_ad[nombre_anuncio]
|
|
|
+ if id not in resultados:
|
|
|
+ resultados[id] = []
|
|
|
|
|
|
obj = i
|
|
|
obj["match_time"] = None
|
|
|
- nombre_anuncio = os.path.split(anuncio)[-1]
|
|
|
- id = id_by_ad[nombre_anuncio]
|
|
|
dict = {
|
|
|
"id": id,
|
|
|
"anuncio": anuncio,
|
|
@@ -200,36 +203,51 @@ def procesar_trabajo(pendiente):
|
|
|
"longitud": obj["length"],
|
|
|
"desfase_segundos": obj["offset_seconds"]
|
|
|
}
|
|
|
+ resultados[id].append(dict)
|
|
|
+
|
|
|
+ for k in resultados.keys():
|
|
|
+ lista = sorted(resultados[k], key=lambda d: d['timestamp'])
|
|
|
+ lista_nueva = []
|
|
|
+ ult = None
|
|
|
+ for x in range(0, len(lista)):
|
|
|
+ if x == 0:
|
|
|
+ ult = x
|
|
|
+ lista_nueva.append(lista[ult])
|
|
|
+ else:
|
|
|
+ dif = lista[x]['timestamp'] - lista[x - 1]['timestamp']
|
|
|
+ if dif <= 30:
|
|
|
+ lista_nueva[ult]['confianza'] = int(lista_nueva[ult]['confianza']) + int(lista[x]['confianza'])
|
|
|
+ lista_nueva[ult]['longitud'] = int(lista_nueva[ult]['longitud']) +int(lista[x]['longitud'])
|
|
|
+ else:
|
|
|
+ lista_nueva.append(lista[x])
|
|
|
+ ult = len(lista_nueva) - 1
|
|
|
+
|
|
|
+ aux[k] = lista_nueva
|
|
|
|
|
|
- if id in resultados.keys():
|
|
|
- resultados[id]["longitud"] += dict["longitud"]
|
|
|
- resultados[id]["confianza"] += dict["confianza"]
|
|
|
- continue
|
|
|
-
|
|
|
- resultados[id] = dict
|
|
|
else:
|
|
|
for i in pendiente['elementos']:
|
|
|
i['comentario'] = 'Problemas técnicos'
|
|
|
|
|
|
- for id in resultados:
|
|
|
- e = resultados[id]
|
|
|
- for i in pendiente['elementos']:
|
|
|
- i['comentario'] = ''
|
|
|
- anuncio = e['anuncio'].replace('/tmp/ads/', '')
|
|
|
- if i['id'] == e['id'] and i['anuncio'] == anuncio:
|
|
|
- if 'encontrados' not in i:
|
|
|
- i['encontrados'] = []
|
|
|
- obj = {
|
|
|
- "fecha": e["fecha"],
|
|
|
- "anuncio": anuncio,
|
|
|
- "longitud": int(e["longitud"] / 1000),
|
|
|
- "confianza": e["confianza"],
|
|
|
- "timestamp": e["timestamp"],
|
|
|
- "desfase_segundos": e["desfase_segundos"]
|
|
|
- }
|
|
|
- i['encontrados'].append(obj)
|
|
|
- break
|
|
|
-
|
|
|
+ for id in aux:
|
|
|
+ for e in aux[id]:
|
|
|
+ for i in pendiente['elementos']:
|
|
|
+ i['comentario'] = ''
|
|
|
+ anuncio = e['anuncio'].replace('/tmp/ads/', '')
|
|
|
+ if i['id'] == e['id'] and i['anuncio'] == anuncio:
|
|
|
+ if 'encontrados' not in i:
|
|
|
+ i['encontrados'] = []
|
|
|
+ obj = {
|
|
|
+ "fecha": e["fecha"],
|
|
|
+ "anuncio": anuncio,
|
|
|
+ "longitud": int(e["longitud"] / 1000),
|
|
|
+ "confianza": e["confianza"],
|
|
|
+ "timestamp": e["timestamp"],
|
|
|
+ "desfase_segundos": e["desfase_segundos"]
|
|
|
+ }
|
|
|
+ i['encontrados'].append(obj)
|
|
|
+ break
|
|
|
+
|
|
|
+ # log.info(json.dumps(extras))
|
|
|
log.info("[Resultado] %s" % (json.dumps(resultados)))
|
|
|
pendiente["media"] = None
|
|
|
enviar_resultados(pendiente)
|
|
@@ -247,4 +265,4 @@ if __name__ == '__main__':
|
|
|
log.info('Starting ondemand service')
|
|
|
loop.start()
|
|
|
except KeyboardInterrupt:
|
|
|
- log.error('Process killed')
|
|
|
+ log.error('Process killed')
|