|
@@ -171,7 +171,6 @@ def procesar_trabajo(pendiente):
|
|
|
try:
|
|
|
dejavu = None
|
|
|
resultados = {}
|
|
|
- extras = {}
|
|
|
if len(media) > 0 and len(anuncio) > 0:
|
|
|
dejavu = Dejavu({"database_type": "mem"})
|
|
|
try:
|
|
@@ -183,15 +182,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
|
|
|
|
|
|
- obj = i
|
|
|
- obj["match_time"] = None
|
|
|
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
|
|
|
dict = {
|
|
|
"id": id,
|
|
|
"anuncio": anuncio,
|
|
@@ -201,43 +202,50 @@ def procesar_trabajo(pendiente):
|
|
|
"longitud": obj["length"],
|
|
|
"desfase_segundos": obj["offset_seconds"]
|
|
|
}
|
|
|
+ resultados[id].append(dict)
|
|
|
+
|
|
|
+ aux = {}
|
|
|
+ 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 not in extras:
|
|
|
- extras[id] = []
|
|
|
-
|
|
|
- extras[id].append(dict)
|
|
|
-
|
|
|
- if i["confidence"] < confianza:
|
|
|
- continue
|
|
|
-
|
|
|
- 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)))
|