|
@@ -141,12 +141,18 @@ def process_queue_with_threads():
|
|
item = queue.get(False)
|
|
item = queue.get(False)
|
|
station = item['station']
|
|
station = item['station']
|
|
date = dateutil.parser.parse(item['date'])
|
|
date = dateutil.parser.parse(item['date'])
|
|
|
|
+ calibration = calibrations.get(station)
|
|
|
|
+
|
|
|
|
+ audios = [f for f in iterate_audios(
|
|
|
|
+ date, station,
|
|
|
|
+ calibration=calibration
|
|
|
|
+ )]
|
|
|
|
|
|
thread = MultiAPI(target=process_segment,
|
|
thread = MultiAPI(target=process_segment,
|
|
args=(item,),
|
|
args=(item,),
|
|
kwargs={
|
|
kwargs={
|
|
- 'audios': [f for f in iterate_audios(date, station)],
|
|
|
|
- 'calibration': calibrations.get(station),
|
|
|
|
|
|
+ 'audios': audios,
|
|
|
|
+ 'calibration': calibration,
|
|
}
|
|
}
|
|
)
|
|
)
|
|
threads[index] = thread
|
|
threads[index] = thread
|
|
@@ -177,13 +183,16 @@ def process_segment(item, audios=None, calibration=None):
|
|
segment_size = calibration['segmentSize']
|
|
segment_size = calibration['segmentSize']
|
|
audio_length = 0
|
|
audio_length = 0
|
|
|
|
|
|
- log.info('[process_segment] (th: {}, tl: {}, ft: {}, ss: {}) {}'.format(
|
|
|
|
- calibration['threshold'],
|
|
|
|
- calibration['tolerance'],
|
|
|
|
- calibration['fallTolerance'],
|
|
|
|
- calibration['segmentSize'],
|
|
|
|
- item,
|
|
|
|
- ))
|
|
|
|
|
|
+ log.info('[process_segment] (th: {}, tl: {}, ft: {}, ss: {}, ho: {}) {}'\
|
|
|
|
+ .format(
|
|
|
|
+ calibration['threshold'],
|
|
|
|
+ calibration['tolerance'],
|
|
|
|
+ calibration['fallTolerance'],
|
|
|
|
+ calibration['segmentSize'],
|
|
|
|
+ calibration['hourlyOffset'],
|
|
|
|
+ item,
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
|
|
# 1. obtener el audio desde firebase
|
|
# 1. obtener el audio desde firebase
|
|
# y calcular su fingerprint.
|
|
# y calcular su fingerprint.
|
|
@@ -223,7 +232,7 @@ def process_segment(item, audios=None, calibration=None):
|
|
de datos en modo de cursor.
|
|
de datos en modo de cursor.
|
|
"""
|
|
"""
|
|
audios_iterable = audios if audios \
|
|
audios_iterable = audios if audios \
|
|
- else iterate_audios(date, station)
|
|
|
|
|
|
+ else iterate_audios(date, station, calibration=calibration)
|
|
|
|
|
|
# 2. Read the list of files from local database
|
|
# 2. Read the list of files from local database
|
|
audios_counter = 0
|
|
audios_counter = 0
|
|
@@ -344,14 +353,23 @@ def find_repetitions(results, segments_needed=2, calibration=None):
|
|
|
|
|
|
return found
|
|
return found
|
|
|
|
|
|
-def iterate_audios(dt, station):
|
|
|
|
|
|
+def iterate_audios(dt, station, calibration=None):
|
|
""" Given a datetime object and an station,
|
|
""" Given a datetime object and an station,
|
|
iterate a list of files that are between
|
|
iterate a list of files that are between
|
|
the the date and itself plus 5 minutes;
|
|
the the date and itself plus 5 minutes;
|
|
station must match too """
|
|
station must match too """
|
|
- from_time = time.mktime(dt.timetuple()) \
|
|
|
|
- - AHEAD_TIME_AUDIO_TOLERANCE
|
|
|
|
- to_time = from_time + 3599 + AHEAD_TIME_AUDIO_TOLERANCE
|
|
|
|
|
|
+
|
|
|
|
+ tm = time.mktime(dt.timetuple())
|
|
|
|
+
|
|
|
|
+ if calibration and calibration['hourlyOffset']:
|
|
|
|
+ hoffset = calibration['hourlyOffset']
|
|
|
|
+ from_time = tm + hoffset
|
|
|
|
+ to_time = tm + 3599 + hoffset
|
|
|
|
+
|
|
|
|
+ elif AHEAD_TIME_AUDIO_TOLERANCE:
|
|
|
|
+ """ Conventional mode """
|
|
|
|
+ from_time = tm + AHEAD_TIME_AUDIO_TOLERANCE
|
|
|
|
+ to_time = from_time + 3599 + AHEAD_TIME_AUDIO_TOLERANCE
|
|
|
|
|
|
log.info('from {} to {}'.format(int(from_time), int(to_time)))
|
|
log.info('from {} to {}'.format(int(from_time), int(to_time)))
|
|
|
|
|