- support offline mode

This commit is contained in:
Dmytro Bogovych 2023-08-22 08:50:48 +03:00
parent 9d2ba8c998
commit 937bafb493
4 changed files with 19 additions and 11 deletions

View File

@ -29,9 +29,9 @@ RECORD_FILE = "/dev/shm/qualtest_recorded.wav"
BackendServer : utils_qualtest.QualtestBackend = None
# Reference audio to play
REFERENCE_AUDIO = "/dev/shm/reference.wav"
REFERENCE_AUDIO = "/dev/shm/reference_original.wav"
# Loaded refernce audio (from backend)
# Loaded reference audio (from backend)
LOADED_AUDIO = Path("/dev/shm/loaded_audio.wav")
# Script to exec after mobile call answering
@ -105,6 +105,7 @@ def detect_reference_signal(file_reference: Path) -> SignalBoundaries:
def upload_results():
utils.log(f'Uploading remaining results...')
probe_list = CACHE.get_probe_list()
for t in probe_list:
# Path to .json report
@ -113,8 +114,12 @@ def upload_results():
# Path to audio
path_audio = t[1]
with open(path_report, 'rt') as f:
report = json.loads(f.read())
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 = BackendServer.upload_report(report, cache=None)
if success:
@ -136,6 +141,7 @@ def upload_results():
else:
break
else:
utils.log(f'Failed to upload report {path_report.name}')
break
def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
@ -249,8 +255,10 @@ def make_call(target: str):
# os.remove(record_file)
# Add prefix and suffix silence for reference to give a chance to record all the file
reference_filename = '/dev/shm/prepared_reference.wav'
utils.prepare_reference_file(fname=REFERENCE_AUDIO, silence_prefix_length=10.0, silence_suffix_length=5.0, output_fname=reference_filename)
reference_filename = Path('/dev/shm/reference_built.wav')
if reference_filename.exists():
os.remove(reference_filename)
utils.prepare_reference_file(fname=str(REFERENCE_AUDIO), silence_prefix_length=10.0, silence_suffix_length=5.0, output_fname=str(reference_filename))
# Find duration of prepared reference file
reference_length = int(utils.get_wav_length(reference_filename))

View File

@ -84,7 +84,7 @@ class InfoCache:
# Probe found
p_audio = p.with_suffix('.wav')
if p_audio.exists():
r.append(p, p.with_suffix('.wav'))
r.append((p, p.with_suffix('.wav')))
return r

View File

@ -233,7 +233,7 @@ class CallState(enum.Enum):
# Monitor logcat output and tell about events
# on_start is lambda with 3 parameters (file_test, file_reference, phone_number)
# on_finish is lambda with 3 parameters (file_test, file_reference, phone_number)
PREPARED_REFERENCE_AUDIO = '/dev/shm/reference_prepared.wav'
PREPARED_REFERENCE_AUDIO = '/dev/shm/built_reference.wav'
def gsm_monitor(file_to_play: str, file_to_record: str, on_start, on_finish, on_error):
global PREPARED_REFERENCE_AUDIO, STOP_FLAG, USE_ALSA_AUDIO, AUDIO_DEV_RECORD, AUDIO_DEV_PLAY

View File

@ -66,12 +66,12 @@ class QualtestBackend:
self.__phone = self.load_phone(cache)
def upload_report(self, report, cache: InfoCache) -> (str, bool):
def upload_report(self, report: dict, cache: InfoCache) -> (str, bool):
# UUID string as result
result = (None, False)
# Log about upload attempt
utils.log_verbose(f"Uploading to {self.address} report: {json.dumps(report, indent=4)}")
utils.log_verbose(f'Uploading to {self.address} report with audio duration: {report["duration"]}s, AQuA MOS: {round(report["mos_aqua"], 3)}')
url = utils.join_host_and_path(self.address, "/probes/")
try:
@ -82,7 +82,7 @@ class QualtestBackend:
result = (r.content.decode().strip(), True)
except Exception as e:
utils.log_error(f"Upload report to {self.address} finished with error.", err=e)
utils.log_error(f'Upload report to {self.address} finished with error: {str(e)}')
# Backup probe result
if cache is not None:
probe_id = cache.add_report(report)