|
@@ -166,6 +166,7 @@ def process_queue_with_threads():
|
|
def process_segment(item, audios=None, calibration=None):
|
|
def process_segment(item, audios=None, calibration=None):
|
|
""" Procesa una hora de audio """
|
|
""" Procesa una hora de audio """
|
|
|
|
|
|
|
|
+ tolerance = calibration['tolerance']
|
|
station = item['station']
|
|
station = item['station']
|
|
date = dateutil.parser.parse(item['date'])
|
|
date = dateutil.parser.parse(item['date'])
|
|
|
|
|
|
@@ -187,9 +188,7 @@ def process_segment(item, audios=None, calibration=None):
|
|
try:
|
|
try:
|
|
audio = mutagen.mp3.MP3(filename)
|
|
audio = mutagen.mp3.MP3(filename)
|
|
segments_needed = int(round(float(audio.info.length) / float(5)))
|
|
segments_needed = int(round(float(audio.info.length) / float(5)))
|
|
- segments_needed = int(round(
|
|
|
|
- segments_needed * SEGMENTS_TOLERANCE_RATE
|
|
|
|
- ))
|
|
|
|
|
|
+ segments_needed = int(round(segments_needed * tolerance))
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
log.error('[process_segment] file {} is not an mp3'.format(filename))
|
|
log.error('[process_segment] file {} is not an mp3'.format(filename))
|
|
log.error(str(ex))
|
|
log.error(str(ex))
|
|
@@ -255,7 +254,8 @@ def process_segment(item, audios=None, calibration=None):
|
|
item['id'],
|
|
item['id'],
|
|
None, # TODO: send results again
|
|
None, # TODO: send results again
|
|
found=find_repetitions(results,
|
|
found=find_repetitions(results,
|
|
- segments_needed=segments_needed
|
|
|
|
|
|
+ segments_needed=segments_needed,
|
|
|
|
+ calibration=calibration,
|
|
),
|
|
),
|
|
missing_files=(12 - audios_counter) \
|
|
missing_files=(12 - audios_counter) \
|
|
if audios_counter < 12 else 0
|
|
if audios_counter < 12 else 0
|
|
@@ -266,16 +266,17 @@ def process_segment(item, audios=None, calibration=None):
|
|
except UserWarning as warn:
|
|
except UserWarning as warn:
|
|
log.warning(str(warn))
|
|
log.warning(str(warn))
|
|
|
|
|
|
-def find_repetitions(results, segments_needed=2):
|
|
|
|
|
|
+def find_repetitions(results, segments_needed=2, calibration=None):
|
|
found_counter = 0
|
|
found_counter = 0
|
|
found_index = None
|
|
found_index = None
|
|
expect_space = False
|
|
expect_space = False
|
|
expect_recover = False
|
|
expect_recover = False
|
|
last_value_in_threshold_index = -1
|
|
last_value_in_threshold_index = -1
|
|
|
|
+ fall_tolerance = calibration['fallTolerance']
|
|
found = []
|
|
found = []
|
|
|
|
|
|
if threshold_mode == THRESHOLD_FIXED:
|
|
if threshold_mode == THRESHOLD_FIXED:
|
|
- threshold = THRESHOLD
|
|
|
|
|
|
+ threshold = calibration['threshold']
|
|
elif threshold_mode == THRESHOLD_AVERAGE:
|
|
elif threshold_mode == THRESHOLD_AVERAGE:
|
|
values = [x['confidence'] for x in results]
|
|
values = [x['confidence'] for x in results]
|
|
threshold = math.ceil(float(sum(values)) / float(len(values)))
|
|
threshold = math.ceil(float(sum(values)) / float(len(values)))
|
|
@@ -293,7 +294,7 @@ def find_repetitions(results, segments_needed=2):
|
|
if expect_recover:
|
|
if expect_recover:
|
|
expect_recover = False
|
|
expect_recover = False
|
|
|
|
|
|
- elif FALL_TOLERANCE_SEGMENTS:
|
|
|
|
|
|
+ elif fall_tolerance:
|
|
if not expect_recover:
|
|
if not expect_recover:
|
|
if last_value_in_threshold_index != -1:
|
|
if last_value_in_threshold_index != -1:
|
|
""" Solo cuando ya haya entrado por lo menos
|
|
""" Solo cuando ya haya entrado por lo menos
|