update to read from db
This commit is contained in:
+31
-33
@@ -1,10 +1,12 @@
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import tempfile
|
||||
import smbclient
|
||||
|
||||
from db_py import (
|
||||
clear_tests,
|
||||
extract_measurement_metrics,
|
||||
get_config,
|
||||
mark_completed,
|
||||
reset_all_results_state,
|
||||
@@ -13,11 +15,9 @@ from db_py import (
|
||||
upsert_test,
|
||||
)
|
||||
from parser import (
|
||||
parse_elapsed_time,
|
||||
parse_result_filename,
|
||||
parse_target_filename,
|
||||
parse_timestamp,
|
||||
parse_tput_rssi,
|
||||
)
|
||||
|
||||
|
||||
@@ -431,26 +431,20 @@ def process_result_dir(results_dir, result_dir_name):
|
||||
result_dir_path = _join_path(results_dir, result_dir_name)
|
||||
|
||||
try:
|
||||
log_files = [
|
||||
entry.name
|
||||
for entry in _iter_dir_entries(result_dir_path)
|
||||
if entry.is_file()
|
||||
and entry.name.endswith(".txt")
|
||||
and test_id in entry.name
|
||||
]
|
||||
files = [entry.name for entry in _iter_dir_entries(result_dir_path) if entry.is_file()]
|
||||
except OSError as exc:
|
||||
print(f"[scanner] Cannot read result dir {result_dir_name}: {exc}")
|
||||
return
|
||||
|
||||
if not log_files:
|
||||
print(f"[scanner] completed (no log yet): {test_id}")
|
||||
measurement_db = next((name for name in files if name.lower() == "measurement.db"), None)
|
||||
if not measurement_db:
|
||||
print(f"[scanner] completed (no measurement.db yet): {test_id}")
|
||||
mark_completed(test_id, device, None, None)
|
||||
return
|
||||
|
||||
latest_log = sorted(log_files)[-1]
|
||||
log_path = _join_path(result_dir_path, latest_log)
|
||||
completed_at = parse_timestamp(latest_log)
|
||||
data = extract_log_data(log_path)
|
||||
db_path = _join_path(result_dir_path, measurement_db)
|
||||
completed_at = parse_timestamp(result_dir_name)
|
||||
data = extract_measurement_data(db_path)
|
||||
|
||||
'''print(
|
||||
f"[scanner] completed: {test_id} device={device} "
|
||||
@@ -472,25 +466,29 @@ def parse_deleted_result_dir_name(dir_name):
|
||||
return test_id, device
|
||||
|
||||
|
||||
def extract_log_data(log_file_path):
|
||||
elapsed_regex = re.compile(r"\[.*?INFO\]\s+Elapsed time\s*:\s*([\d]+:[\d]{2}:[\d]{2}\.[\d]+)")
|
||||
tput_regex = re.compile(
|
||||
r"\[.*?INFO\]\s+STA(\d+) over angles >> AVG IxChariot TPUT: (\d+) Mbps, AVG DL RSSI: (-?\d+) dBm, AVG UL RSSI: (-?\d+) dBm"
|
||||
)
|
||||
|
||||
def extract_measurement_data(db_file_path):
|
||||
result = {"duration_seconds": None, "tputResults": []}
|
||||
try:
|
||||
for line in _read_text_lines(log_file_path):
|
||||
time_match = elapsed_regex.search(line)
|
||||
if time_match:
|
||||
result["duration_seconds"] = parse_elapsed_time(time_match.group(1))
|
||||
continue
|
||||
local_db_path = None
|
||||
|
||||
if tput_regex.search(line):
|
||||
parsed = parse_tput_rssi(line)
|
||||
if parsed:
|
||||
result["tputResults"].append(parsed)
|
||||
except OSError as exc:
|
||||
print(f"[scanner] Cannot read log file {log_file_path}: {exc}")
|
||||
try:
|
||||
source_db_path = _normalize_input_path(db_file_path)
|
||||
if _is_unc_path(source_db_path):
|
||||
_register_smb_session_if_needed(source_db_path)
|
||||
with smbclient.open_file(source_db_path, mode="rb") as src_fh:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=".db") as tmp_fh:
|
||||
tmp_fh.write(src_fh.read())
|
||||
local_db_path = tmp_fh.name
|
||||
source_db_path = local_db_path
|
||||
|
||||
result = extract_measurement_metrics(source_db_path)
|
||||
|
||||
except (OSError, ValueError, Exception) as exc:
|
||||
print(f"[scanner] Cannot read measurement db {db_file_path}: {exc}")
|
||||
finally:
|
||||
if local_db_path:
|
||||
try:
|
||||
os.remove(local_db_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user