Pequeños detalles en Explorer.
This commit is contained in:
parent
7a795d1fb8
commit
b77a4752b8
2 changed files with 129 additions and 58 deletions
|
|
@ -18,10 +18,11 @@ class Explorer():
|
|||
working_hours = {'start': datetime.time(9, 0, 0),
|
||||
'end': datetime.time(18, 0, 0)}
|
||||
monthly_capture_target = 1000
|
||||
|
||||
|
||||
def __init__(self):
|
||||
try:
|
||||
self.anunciosdb = get_anunciosdb()
|
||||
self.tasksdb = get_tasksdb()
|
||||
except:
|
||||
print("Could not connect to anuncios DB")
|
||||
|
||||
|
|
@ -58,6 +59,7 @@ class Explorer():
|
|||
pass
|
||||
|
||||
def there_is_work(self):
|
||||
#TODO Añadir que no se trabaja si se ha lanzado tarea en los ultimos 10 minutos
|
||||
"""
|
||||
Funcion que agrupa las condiciones que se deben cumplir para poder trabajar
|
||||
"""
|
||||
|
|
@ -98,50 +100,50 @@ class Explorer():
|
|||
return False
|
||||
|
||||
def in_working_hours(self):
|
||||
return Explorer.working_hours['start'] <= datetime.now().time() <= Explorer.working_hours['end']
|
||||
return Explorer.working_hours['start'] <= datetime.datetime.now().time() <= Explorer.working_hours['end']
|
||||
|
||||
def get_referencias_acquired_today(self):
|
||||
"""
|
||||
Cuenta cuantas nuevas referencias han aparecido en las ultimas 24 horas
|
||||
"""
|
||||
|
||||
query_statement = """ SELECT count(referencias)
|
||||
query_statement = """ SELECT count(referencia)
|
||||
FROM primera_captura_full
|
||||
WHERE fecha_captura >= now() - INTERVAL 1 DAY;
|
||||
"""
|
||||
|
||||
cursor_result = self.anunciosdb.query(query_statement)
|
||||
|
||||
return cursor_result.fetchone()
|
||||
return cursor_result.fetchone()[0]
|
||||
|
||||
def get_max_referencias_for_today(self):
|
||||
"""
|
||||
Calcula la cantidad objetivo para las ultimas 24 horas en base a la
|
||||
diferencia con el objetivo mensual
|
||||
"""
|
||||
query_statement = """ SELECT count(referencias)
|
||||
query_statement = """ SELECT count(referencia)
|
||||
FROM primera_captura_full
|
||||
WHERE fecha_captura >= now() - INTERVAL 30 DAY;
|
||||
"""
|
||||
cursor_result = self.anunciosdb.query(query_statement)
|
||||
new_referencias_last_30 = cursor_result.fetchone()
|
||||
|
||||
new_referencias_last_30 = cursor_result.fetchone()[0]
|
||||
|
||||
deviation = (Explorer.monthly_capture_target - new_referencias_last_30) / Explorer.monthly_capture_target
|
||||
max_referencias = (Explorer.monthly_capture_target/30) * (1 + (deviation))
|
||||
|
||||
max_referencias = (Explorer.monthly_capture_target/30) * (1 + deviation)
|
||||
|
||||
return max_referencias
|
||||
|
||||
|
||||
def get_tasks_created_today(self):
|
||||
"""
|
||||
Mira en el task log cuantas tareas se han iniciado en las ultimas 24 horas
|
||||
"""
|
||||
query_statement = """ SELECT count(uuid)
|
||||
FROM exploring_tasks
|
||||
FROM exploring_tasks_logs
|
||||
WHERE status = 'Attacked'
|
||||
AND write_time >= now() - INTERVAL 1 DAY;
|
||||
"""
|
||||
cursor_result = self.tasksdb.query(query_statement)
|
||||
tasks_created_today = cursor_result.fetchone()
|
||||
tasks_created_today = cursor_result.fetchone()[0]
|
||||
|
||||
return tasks_created_today
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue