Files

85 lines
3.1 KiB
Python
Raw Permalink Normal View History

2026-05-26 14:36:34 -04:00
import re
_DEFAULT_SCAN_EXCLUSIONS = ""
2026-05-26 14:36:34 -04:00
INTERFERENCE_TYPES = {"COE", "P2P", "P3P"}
DIRECTION_TYPES = {"UL", "DL"}
def parse_target_filename(filename, parent_dir):
base_name = re.sub(r"\.ini$", "", filename, flags=re.IGNORECASE)
segments = base_name.split("_")[2:]
test_identifier = f"{parent_dir}/{base_name}"
interference = segments[0] if segments and segments[0] in INTERFERENCE_TYPES else None
test_id = next((s for s in segments if re.match(r"^R\d+[A-Z0-9]+$", s, re.IGNORECASE)), None)
2026-05-27 10:29:26 -04:00
throttled = None
if interference == "P3P" and test_id:
# P3P test_id carries throttle marker: TH = throttled, otherwise UT.
throttled = "TH" if "TH" in test_id.upper() else "UT"
2026-05-26 14:36:34 -04:00
device = segments[1] if len(segments) > 1 else None
test_point = next((s for s in segments if re.match(r"^TPT\w+$", s)), None)
rssi = next((s for s in segments if re.match(r"^RSSI\d+$", s)), None)
station = next((s for s in segments if re.match(r"^STA\d+$", s)), None)
band = next((s for s in segments if re.match(r"^\dGHZ$", s)), None)
channel = next((s for s in segments if re.match(r"^CH\d+$", s)), None)
bandwidth = next((s for s in segments if re.match(r"^BW\d+$", s)), None)
2026-05-28 15:14:21 -04:00
sp = next ((s for s in segments if re.match(r"^SP", s)), None)
2026-05-26 14:36:34 -04:00
last_segment = segments[-1] if segments else None
direction = last_segment if last_segment in DIRECTION_TYPES else None
rotation = None
if parent_dir:
rotation = next((s for s in parent_dir.split("_") if re.match(r"^ROT\d+$", s)), None)
return {
"id": test_identifier,
"test_id": test_id,
"interference": interference,
"device": device,
"test_point": test_point,
"rssi": rssi,
"station": station,
"band": band,
"channel": channel,
"bandwidth": bandwidth,
"direction": direction,
"rotation": rotation,
2026-05-27 10:29:26 -04:00
"throttled": throttled,
2026-05-28 15:14:21 -04:00
"sp": sp,
2026-05-26 14:36:34 -04:00
}
def parse_result_filename(filename):
segments = re.split(r"[_\-]", filename)
test_id = next((s for s in segments if re.match(r"^R\d+[A-Z0-9]+$", s)), None)
device = segments[1] if len(segments) > 1 else None
return {"test_id": test_id, "device": device}
def parse_timestamp(filename):
match = re.search(r"(\d{4}-\d{2}-\d{2}-\d{2}-\d{2}(?:-\d{2})?)(?:\.\w+)?$", filename)
if not match:
return None
parts = match.group(1).split("-")
year, month, day, hour, minute = parts[:5]
second = parts[5] if len(parts) > 5 else "00"
return f"{year}-{month}-{day}T{hour}:{minute}:{second}"
def parse_deleted_result_dir_name(dir_name):
segments = re.split(r"[_\-]", dir_name)
test_id = next((s for s in segments if re.match(r"^R\d+[A-Z0-9]+$", s, re.IGNORECASE)), None)
device = next((s for s in segments if re.match(r"^CGW\d+$", s, re.IGNORECASE)), None)
return test_id, device
def parse_scan_exclusions(value):
raw = value if value not in (None, "") else _DEFAULT_SCAN_EXCLUSIONS
if raw == "" or raw is None:
return None
parts = re.split(r"[,\n;]", str(raw))
return {token.strip().upper() for token in parts if token.strip()}
2026-05-26 14:36:34 -04:00