- fix remaining audio results uploading

This commit is contained in:
Dmytro Bogovych 2023-09-11 12:15:11 +03:00
parent c186badb43
commit ed3b91d8c1
2 changed files with 26 additions and 30 deletions

View File

@ -93,6 +93,7 @@ def upload_results():
path_audio = t[1] path_audio = t[1]
utils.log(f'Found {path_report.name} and {path_audio.name} files.') utils.log(f'Found {path_report.name} and {path_audio.name} files.')
if path_report is not None and path_report.exists():
try: try:
with open(path_report, 'rt') as f: with open(path_report, 'rt') as f:
report = json.loads(f.read()) report = json.loads(f.read())
@ -104,26 +105,16 @@ def upload_results():
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 os.remove(path_report)
# 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' if path_audio is not None and path_audio.exists():
# path_audio = path_audio.rename(path_audio_fixed)
if path_audio.exists():
utils.log(f'Uploading {path_audio.name} file...') utils.log(f'Uploading {path_audio.name} file...')
# Upload recorded audio # Upload recorded audio
upload_result = BACKEND.upload_audio(upload_id, path_audio) upload_result = BACKEND.upload_audio(upload_id, path_audio)
if upload_result: if upload_result:
utils.log(f' Recorded audio {upload_id}.wav is uploaded ok.') utils.log(f' Recorded audio {upload_id}.wav is uploaded ok.')
os.remove(path_audio) os.remove(path_audio)
else:
utils.log(f'No recorded audio file found, skipping audio upload.')
os.remove(path_report)
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

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