diff --git a/src/agent_gsm.py b/src/agent_gsm.py index a7f95d3..db24856 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -92,38 +92,29 @@ def upload_results(): # Path to audio 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 + 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: + 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(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: 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') # 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') 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 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