|
@@ -18,25 +18,11 @@ from queue import Queue, Empty
|
|
|
log.basicConfig(format='[%(asctime)s] [%(module)s] %(message)s', level=log.INFO)
|
|
|
|
|
|
PATH = '/tmp'
|
|
|
-AHEAD_TIME_AUDIO_TOLERANCE = 2 # second
|
|
|
-MAX_SEGMENT_THREADS = 4
|
|
|
-THRESHOLD = 10
|
|
|
-SEGMENTS_TOLERANCE_RATE = 0.6
|
|
|
-FALL_TOLERANCE_SEGMENTS = 1
|
|
|
-
|
|
|
-THRESHOLD_FIXED = 1
|
|
|
-THRESHOLD_AVERAGE = 2
|
|
|
-
|
|
|
-QUEUE_SINGLE = 1
|
|
|
-
|
|
|
config = parse_config()
|
|
|
queue = Queue()
|
|
|
recognizer = FilePerSecondRecognizer
|
|
|
|
|
|
|
|
|
-threshold_mode = THRESHOLD_FIXED
|
|
|
-
|
|
|
-
|
|
|
def obt_siguiente_trabajo():
|
|
|
url = 'https://api.fourier.audio/na/calendario/pendiente?id=%s' % (config['device_id'],)
|
|
|
response = requests.get(url)
|
|
@@ -63,8 +49,7 @@ def descargar_anuncio(ad_path):
|
|
|
return ruta_anuncio
|
|
|
|
|
|
else:
|
|
|
- log.info("Error al descargar")
|
|
|
- log.info(response)
|
|
|
+ log.info("[Anuncio][error] %s" % (response.text))
|
|
|
return None
|
|
|
|
|
|
|
|
@@ -82,7 +67,7 @@ def descargar_media(box, station, media):
|
|
|
.replace("+","%2B")
|
|
|
cloud_base_url = '%s%s' % (
|
|
|
'https://firebasestorage.googleapis.com',
|
|
|
- '/v0/b/fourier-6e14d.appspot.com/o/'
|
|
|
+ '/v0/b/fourier-6e14d.appspot.com/o'
|
|
|
)
|
|
|
url = '{}/{}?alt=media'.format(cloud_base_url, filename)
|
|
|
response = requests.get(url)
|
|
@@ -92,8 +77,8 @@ def descargar_media(box, station, media):
|
|
|
fp.write(response.content)
|
|
|
return out_file
|
|
|
else:
|
|
|
- log.info("Error al descargar")
|
|
|
- log.info(response)
|
|
|
+ log.info("[Media][url] %s" % (response.text))
|
|
|
+ log.info("[Media][error] %s" % (response.text))
|
|
|
return None
|
|
|
|
|
|
|
|
@@ -118,7 +103,7 @@ def obt_calibracion(calibracion):
|
|
|
|
|
|
|
|
|
def enviar_resultados(trabajo):
|
|
|
- print('[resultados] %s' % (json.dumps(trabajo),))
|
|
|
+ log.info('[pendiente] %s' % (json.dumps(trabajo),))
|
|
|
url = 'https://api.fourier.audio/na/calendario/resultado'
|
|
|
response = requests.post(url, json=trabajo)
|
|
|
return response
|
|
@@ -164,6 +149,7 @@ def procesar_trabajo(pendiente):
|
|
|
estacion = pendiente['estacion']
|
|
|
|
|
|
# Descarga de anuncios
|
|
|
+ log.info("Descargando anuncios")
|
|
|
try:
|
|
|
anuncios = []
|
|
|
id_by_ad = {}
|
|
@@ -175,22 +161,29 @@ 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:
|
|
|
log.info('[process_segment] [{}] {}'.format(estacion, err))
|
|
|
|
|
|
# Descarga de media
|
|
|
+ log.info("Descargando anuncios")
|
|
|
try:
|
|
|
media = []
|
|
|
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)
|
|
|
|
|
|
+ if len(media) == 0 or len(anuncio) == 0:
|
|
|
+ log.info("No hay media o anuncios para comparar")
|
|
|
+ return
|
|
|
+
|
|
|
dejavu = None
|
|
|
resultados = {}
|
|
|
try:
|
|
@@ -237,12 +230,13 @@ def procesar_trabajo(pendiente):
|
|
|
e = resultados[id]
|
|
|
for i in pendiente['elementos']:
|
|
|
anuncio = e['anuncio'].replace('/tmp/ads/', '')
|
|
|
- if i['id'] == id and i['anuncio'] == anuncio:
|
|
|
+ if i['id'] == e['id'] and i['anuncio'] == anuncio:
|
|
|
if 'encontrados' not in i:
|
|
|
i['encontrados'] = []
|
|
|
i['encontrados'].append(e)
|
|
|
break
|
|
|
|
|
|
+ log.info("[Resultado] %s" % (json.dumps(resultados)))
|
|
|
enviar_resultados(pendiente)
|
|
|
|
|
|
except Exception as ex:
|