- more checks about failed recordings attempts
This commit is contained in:
parent
0c4710bbc7
commit
cd84f8c60b
|
|
@ -127,7 +127,7 @@ def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
|
||||||
|
|
||||||
result = False
|
result = False
|
||||||
|
|
||||||
if file_test:
|
if file_test.exists():
|
||||||
# Wait 5 seconds to give a chance to flush recorded file
|
# Wait 5 seconds to give a chance to flush recorded file
|
||||||
time.sleep(5.0)
|
time.sleep(5.0)
|
||||||
|
|
||||||
|
|
@ -205,10 +205,10 @@ def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
|
||||||
upload_result = BACKEND.upload_audio(r['id'], file_test)
|
upload_result = BACKEND.upload_audio(r['id'], file_test)
|
||||||
|
|
||||||
if upload_result:
|
if upload_result:
|
||||||
utils.log('Recorded audio is uploaded ok.')
|
utils.log(' Recorded audio is uploaded ok.')
|
||||||
result = True
|
result = True
|
||||||
else:
|
else:
|
||||||
utils.log_error('Recorded audio is not uploaded.')
|
utils.log_error(' Recorded audio is not uploaded.')
|
||||||
CACHE.add_recorded_audio(file_test, probe_id=upload_id)
|
CACHE.add_recorded_audio(file_test, probe_id=upload_id)
|
||||||
else:
|
else:
|
||||||
CACHE.add_recorded_audio(file_test, probe_id=upload_id)
|
CACHE.add_recorded_audio(file_test, probe_id=upload_id)
|
||||||
|
|
@ -216,7 +216,7 @@ def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
utils.log_error(e)
|
utils.log_error(e)
|
||||||
else:
|
else:
|
||||||
utils.log_error('Seems the file is not recorded. Usually it happens because adb logcat is not stable sometimes. Return signal to restart')
|
utils.log_error('Seems the file is not recorded. Skipping analysis and upload.')
|
||||||
|
|
||||||
# Increase finished calls counter
|
# Increase finished calls counter
|
||||||
CALL_COUNTER.value = CALL_COUNTER.value + 1
|
CALL_COUNTER.value = CALL_COUNTER.value + 1
|
||||||
|
|
@ -543,10 +543,12 @@ if __name__ == '__main__':
|
||||||
if BACKEND.load_audio(BACKEND.phone.audio_id, CONFIG.ReferenceAudio):
|
if BACKEND.load_audio(BACKEND.phone.audio_id, CONFIG.ReferenceAudio):
|
||||||
CACHE.add_reference_audio(BACKEND.phone.audio_id, CONFIG.ReferenceAudio)
|
CACHE.add_reference_audio(BACKEND.phone.audio_id, CONFIG.ReferenceAudio)
|
||||||
else:
|
else:
|
||||||
utils.log_error('Audio is not available online.')
|
utils.log('Audio is not available online...')
|
||||||
if not CACHE.get_reference_audio(BACKEND.phone.audio_id, CONFIG.REFERENCE_AUDIO):
|
if not CACHE.get_reference_audio(BACKEND.phone.audio_id, CONFIG.ReferenceAudio):
|
||||||
utils.log_error('Reference audio is not cached, sorry. Exiting.')
|
utils.log_error(' Reference audio is not cached, sorry. Exiting.')
|
||||||
sys.exit(EXIT_ERROR)
|
sys.exit(EXIT_ERROR)
|
||||||
|
else:
|
||||||
|
utils.log(f' Found in cache.')
|
||||||
|
|
||||||
# Preparing reference audio
|
# Preparing reference audio
|
||||||
utils.log('Running answering loop...')
|
utils.log('Running answering loop...')
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,21 @@ def ParseAttributes(t: str) -> dict:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
# Time of operation start
|
||||||
|
TRACE_START_TIME = None
|
||||||
|
|
||||||
|
# 10 seconds for I/O operation
|
||||||
|
TRACE_TOTAL_TIMEOUT = 30
|
||||||
|
|
||||||
|
|
||||||
|
# This function serves as a "hook" that executes for each Python statement
|
||||||
|
# down the road. There may be some performance penalty, but as downloading
|
||||||
|
# a webpage is mostly I/O bound, it's not going to be significant.
|
||||||
|
|
||||||
|
def trace_function(frame, event, arg):
|
||||||
|
if time.time() - TRACE_START_TIME > TRACE_TOTAL_TIMEOUT:
|
||||||
|
raise Exception('Timed out!') # Use whatever exception you consider appropriate.
|
||||||
|
|
||||||
|
|
||||||
class QualtestBackend:
|
class QualtestBackend:
|
||||||
address: str
|
address: str
|
||||||
|
|
@ -98,11 +113,15 @@ class QualtestBackend:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def upload_audio(self, probe_id, path_recorded):
|
def upload_audio(self, probe_id, path_recorded: Path):
|
||||||
result = False
|
result = False
|
||||||
|
|
||||||
# Log about upload attempt
|
# Log about upload attempt
|
||||||
utils.log_verbose(f"Uploading to {self.address} audio {path_recorded}")
|
utils.log_verbose(f"Uploading to {self.address} audio {path_recorded}")
|
||||||
|
if not path_recorded.exists():
|
||||||
|
utils.log_error(' File doesn\'t exists, skip.')
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Find URL for uploading
|
# Find URL for uploading
|
||||||
url = utils.join_host_and_path(self.address, "/upload_audio/")
|
url = utils.join_host_and_path(self.address, "/upload_audio/")
|
||||||
|
|
@ -112,8 +131,16 @@ class QualtestBackend:
|
||||||
'audio_kind': (None, '1'),
|
'audio_kind': (None, '1'),
|
||||||
'audio_name': (None, os.path.basename(path_recorded))}
|
'audio_name': (None, os.path.basename(path_recorded))}
|
||||||
|
|
||||||
# values = {'probe_id': probe_id}
|
try:
|
||||||
response = requests.post(url, files=files, timeout=utils.NETWORK_TIMEOUT)
|
# Limit POST time by TRACE_TOTAL_TIMEOUT seconds
|
||||||
|
TRACE_START_TIME = time.time()
|
||||||
|
sys.settrace(trace_function)
|
||||||
|
response = requests.post(url, files=files, timeout=utils.NETWORK_TIMEOUT)
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
sys.settrace(None)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
utils.log_error(f"Upload audio to {self.address} finished with error {response.status_code}", None)
|
utils.log_error(f"Upload audio to {self.address} finished with error {response.status_code}", None)
|
||||||
else:
|
else:
|
||||||
|
|
@ -213,7 +240,10 @@ class QualtestBackend:
|
||||||
|
|
||||||
|
|
||||||
def load_audio(self, audio_id: int, output_path: Path):
|
def load_audio(self, audio_id: int, output_path: Path):
|
||||||
|
global TRACE_START_TIME
|
||||||
|
|
||||||
utils.log(f'Loading audio with ID: {audio_id} ...')
|
utils.log(f'Loading audio with ID: {audio_id} ...')
|
||||||
|
TRACE_START_TIME = time.time()
|
||||||
try:
|
try:
|
||||||
# Build query for both V1 & V2 API
|
# Build query for both V1 & V2 API
|
||||||
params = urllib.parse.urlencode({"audio_id": audio_id})
|
params = urllib.parse.urlencode({"audio_id": audio_id})
|
||||||
|
|
@ -221,8 +251,15 @@ class QualtestBackend:
|
||||||
# Find URL
|
# Find URL
|
||||||
url = utils.join_host_and_path(self.address, "/play_audio/?") + params
|
url = utils.join_host_and_path(self.address, "/play_audio/?") + params
|
||||||
|
|
||||||
# Get response from server
|
sys.settrace(trace_function)
|
||||||
response = requests.get(url, timeout=(utils.NETWORK_TIMEOUT, 5))
|
try:
|
||||||
|
# Get response from server
|
||||||
|
response = requests.get(url, timeout=(utils.NETWORK_TIMEOUT, 5))
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
sys.settrace(None)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
utils.log_error(f' Failed to get audio. Error code: {response.status_code}, msg: {response.content}')
|
utils.log_error(f' Failed to get audio. Error code: {response.status_code}, msg: {response.content}')
|
||||||
return False
|
return False
|
||||||
|
|
@ -233,7 +270,7 @@ class QualtestBackend:
|
||||||
utils.log(' Done.')
|
utils.log(' Done.')
|
||||||
return True
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
utils.log_error(f' Exception when fetching audio: {str(err)}')
|
utils.log_error(f' Exception when fetching audio: {str(err)}')
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue