This commit is contained in:
Dmytro Bogovych 2023-09-14 08:17:09 +01:00
commit 19c9881784
3 changed files with 31 additions and 33 deletions

View File

@ -92,38 +92,29 @@ def upload_results():
# Path to audio # Path to audio
path_audio = t[1] path_audio = t[1]
utils.log(f'Found {path_report.name} and {path_audio.name} files.') utils.log(f'Found {t} report pair.')
try: if path_report is not None and path_report.exists():
with open(path_report, 'rt') as f: try:
report = json.loads(f.read()) with open(path_report, 'rt') as f:
except: report = json.loads(f.read())
utils.log_error(f'Error when processing {path_report.name}') except:
continue utils.log_error(f'Error when processing {path_report.name}')
continue
upload_id, success = BACKEND.upload_report(report, cache=None) upload_id, success = BACKEND.upload_report(report, cache=None)
if success: if success:
utils.log(f'Report {upload_id} is uploaded ok.') utils.log(f'Report {upload_id} is uploaded ok.')
# Rename files to make sync audio filename with reported ones
# path_report_fixed = CACHE.dir / f'{upload_id}.json'
# path_report = path_report.rename(path_report_fixed)
# path_audio_fixed = CACHE.dir / f'{upload_id}.wav'
# path_audio = path_audio.rename(path_audio_fixed)
if path_audio.exists():
utils.log(f'Uploading {path_audio.name} file...')
# Upload recorded audio
upload_result = BACKEND.upload_audio(upload_id, path_audio)
if upload_result:
utils.log(f' Recorded audio {upload_id}.wav is uploaded ok.')
os.remove(path_audio)
else:
utils.log(f'No recorded audio file found, skipping audio upload.')
os.remove(path_report) os.remove(path_report)
if path_audio is not None and path_audio.exists():
utils.log(f'Uploading {path_audio.name} file...')
# Upload recorded audio
upload_result = BACKEND.upload_audio(path_audio.stem, path_audio)
if upload_result:
utils.log(f' Recorded audio {path_audio.stem}.wav is uploaded ok.')
os.remove(path_audio)
else:
utils.log(f'Failed to upload report {path_report.name}')
break
def run_analyze(file_test: str, file_reference: str, number: str) -> bool: def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
global CALL_COUNTER global CALL_COUNTER
@ -147,8 +138,8 @@ def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
utils.log(f'Recorded audio call duration: {test_audio_length}s, reference audio length: {ref_audio_length}s') utils.log(f'Recorded audio call duration: {test_audio_length}s, reference audio length: {ref_audio_length}s')
# Check if audio length is strange - skip such calls. Usually this is missed call. # Check if audio length is strange - skip such calls. Usually this is missed call.
is_caller_audio_big = is_caller and test_audio_length > ref_audio_length * 1.5 is_caller_audio_big = is_caller and test_audio_length > ref_audio_length * 3
is_answerer_audio_big = is_answerer and test_audio_length > ref_audio_length * 1.5 is_answerer_audio_big = is_answerer and test_audio_length > ref_audio_length * 3
if is_caller_audio_big or is_answerer_audio_big: if is_caller_audio_big or is_answerer_audio_big:
utils.log_error(f'Recorded call is too big - looks like mobile operator prompt, skipping analysis') utils.log_error(f'Recorded call is too big - looks like mobile operator prompt, skipping analysis')

View File

@ -80,11 +80,16 @@ class InfoCache:
lst = os.listdir(self.dir) lst = os.listdir(self.dir)
for n in lst: for n in lst:
p = self.dir / n p = self.dir / n
if self.is_valid_uuid(p.stem) and n.endswith('.json'): if self.is_valid_uuid(p.stem) and (n.endswith('.json') or n.endswith(".wav")):
# Probe found # Probe found
p_json = p.with_suffix('.json')
p_audio = p.with_suffix('.wav') p_audio = p.with_suffix('.wav')
if p_audio.exists(): if p_json.exists() and p_audio.exists():
r.append((p, p.with_suffix('.wav'))) r.append((p_json, p_audio))
elif p_json.exists():
r.append((p_json, None))
elif p_audio.exists():
r.append((None, p_audio))
return r return r

View File

@ -58,6 +58,7 @@ TRACE_TOTAL_TIMEOUT = 30
# a webpage is mostly I/O bound, it's not going to be significant. # a webpage is mostly I/O bound, it's not going to be significant.
def trace_function(frame, event, arg): def trace_function(frame, event, arg):
global TRACE_START_TIME
if time.time() - TRACE_START_TIME > TRACE_TOTAL_TIMEOUT: if time.time() - TRACE_START_TIME > TRACE_TOTAL_TIMEOUT:
raise Exception('Timed out!') # Use whatever exception you consider appropriate. raise Exception('Timed out!') # Use whatever exception you consider appropriate.
@ -114,6 +115,7 @@ class QualtestBackend:
def upload_audio(self, probe_id, path_recorded: Path): def upload_audio(self, probe_id, path_recorded: Path):
global TRACE_START_TIME
result = False result = False
# Log about upload attempt # Log about upload attempt