From c186badb43801c99211790c85218615154c8fbfd Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 11 Sep 2023 11:46:35 +0300 Subject: [PATCH 1/5] - fix false alarm when checking recorded audio is good --- src/agent_gsm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent_gsm.py b/src/agent_gsm.py index a7f95d3..c47ad35 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -147,8 +147,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') # 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_answerer_audio_big = is_answerer 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 * 3 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') From ed3b91d8c1c7e638acedbedb5bc7732a37f1f501 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 11 Sep 2023 12:15:11 +0300 Subject: [PATCH 2/5] - fix remaining audio results uploading --- src/agent_gsm.py | 45 ++++++++++++++++++--------------------------- src/utils_cache.py | 11 ++++++++--- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/agent_gsm.py b/src/agent_gsm.py index c47ad35..b246e13 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -93,37 +93,28 @@ def upload_results(): path_audio = t[1] utils.log(f'Found {path_report.name} and {path_audio.name} files.') - try: - with open(path_report, 'rt') as f: - report = json.loads(f.read()) - except: - utils.log_error(f'Error when processing {path_report.name}') - continue + if path_report is not None and path_report.exists(): + try: + with open(path_report, 'rt') as f: + report = json.loads(f.read()) + except: + utils.log_error(f'Error when processing {path_report.name}') + continue - upload_id, success = BACKEND.upload_report(report, cache=None) - if success: - utils.log(f'Report {upload_id} is uploaded ok.') + upload_id, success = BACKEND.upload_report(report, cache=None) + if success: + 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) + + 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(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'Failed to upload report {path_report.name}') - break def run_analyze(file_test: str, file_reference: str, number: str) -> bool: global CALL_COUNTER diff --git a/src/utils_cache.py b/src/utils_cache.py index 2fbf9e5..a466838 100644 --- a/src/utils_cache.py +++ b/src/utils_cache.py @@ -80,11 +80,16 @@ class InfoCache: lst = os.listdir(self.dir) for n in lst: 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 + p_json = p.with_suffix('.json') p_audio = p.with_suffix('.wav') - if p_audio.exists(): - r.append((p, p.with_suffix('.wav'))) + if p_json.exists() and p_audio.exists(): + 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 From ef9ac651f9af59bf496e0e41f482ec59cee19edc Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 11 Sep 2023 12:18:08 +0300 Subject: [PATCH 3/5] - fix error on None value --- src/agent_gsm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent_gsm.py b/src/agent_gsm.py index b246e13..fab89f8 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -92,7 +92,7 @@ def upload_results(): # Path to audio path_audio = t[1] - utils.log(f'Found {path_report.name} and {path_audio.name} files.') + utils.log(f'Found {t} report pair.') if path_report is not None and path_report.exists(): try: with open(path_report, 'rt') as f: From 7d21de2dd0cf46a888df87991a95d250a37d67ba Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 11 Sep 2023 12:19:32 +0300 Subject: [PATCH 4/5] - fix error on name --- src/agent_gsm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent_gsm.py b/src/agent_gsm.py index fab89f8..db24856 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -110,9 +110,9 @@ def upload_results(): 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(upload_id, path_audio) + upload_result = BACKEND.upload_audio(path_audio.stem, path_audio) if upload_result: - utils.log(f' Recorded audio {upload_id}.wav is uploaded ok.') + utils.log(f' Recorded audio {path_audio.stem}.wav is uploaded ok.') os.remove(path_audio) From cc5cec6cd21c3b7e17810cf7e9c2352913580bb0 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 11 Sep 2023 12:21:33 +0300 Subject: [PATCH 5/5] - fix global variable access --- src/utils_qualtest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils_qualtest.py b/src/utils_qualtest.py index 8680814..03fce30 100644 --- a/src/utils_qualtest.py +++ b/src/utils_qualtest.py @@ -58,6 +58,7 @@ TRACE_TOTAL_TIMEOUT = 30 # a webpage is mostly I/O bound, it's not going to be significant. def trace_function(frame, event, arg): + global TRACE_START_TIME if time.time() - TRACE_START_TIME > TRACE_TOTAL_TIMEOUT: 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): + global TRACE_START_TIME result = False # Log about upload attempt