Initial commit - Selenium automation framework
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def load_single_bid_json_matrix(json_path):
|
||||
|
||||
data_file = Path(json_path)
|
||||
if not data_file.exists():
|
||||
raise FileNotFoundError(f"JSON input file not found: {data_file}")
|
||||
|
||||
with data_file.open("r", encoding="utf-8") as file:
|
||||
payload = json.load(file)
|
||||
|
||||
if "matrix" in payload:
|
||||
matrix = [[_to_text(value) for value in row] for row in payload["matrix"]]
|
||||
elif "slot_range" in payload:
|
||||
matrix = _build_range_matrix(payload)
|
||||
else:
|
||||
price_row = [_to_text(value) for value in payload["price_row"]]
|
||||
slot_rows = [
|
||||
[_to_text(value) for value in slot["orders"]]
|
||||
for slot in payload.get("slots", [])
|
||||
]
|
||||
matrix = [price_row, *slot_rows]
|
||||
|
||||
if not matrix or not matrix[0]:
|
||||
raise ValueError(f"No bidding data found in {data_file}.")
|
||||
|
||||
tsv = "\n".join("\t".join(row) for row in matrix)
|
||||
return {
|
||||
"matrix": matrix,
|
||||
"tsv": tsv,
|
||||
"row_count": len(matrix),
|
||||
"column_count": len(matrix[0]),
|
||||
"first_value": matrix[0][0],
|
||||
}
|
||||
|
||||
|
||||
def _build_range_matrix(payload):
|
||||
|
||||
price_row = [_to_text(value) for value in payload["price_row"]]
|
||||
slot_range = payload["slot_range"]
|
||||
from_slot = int(slot_range["from_slot"])
|
||||
to_slot = int(slot_range["to_slot"])
|
||||
orders = payload.get("orders", [])
|
||||
|
||||
if from_slot < 1 or to_slot < from_slot:
|
||||
raise ValueError(f"Invalid slot_range: from_slot={from_slot}, to_slot={to_slot}")
|
||||
|
||||
expected_row_count = to_slot - from_slot + 1
|
||||
if len(orders) != expected_row_count:
|
||||
raise ValueError(
|
||||
"Order row count does not match slot range: "
|
||||
f"expected {expected_row_count}, found {len(orders)}"
|
||||
)
|
||||
|
||||
column_count = len(price_row)
|
||||
blank_row = [""] * column_count
|
||||
|
||||
slot_rows = []
|
||||
for _ in range(from_slot - 1):
|
||||
slot_rows.append(blank_row.copy())
|
||||
|
||||
for order_row in orders:
|
||||
normalized_row = [_to_text(value) for value in order_row]
|
||||
if len(normalized_row) != column_count:
|
||||
raise ValueError(
|
||||
"Each order row must have the same number of values as price_row: "
|
||||
f"expected {column_count}, found {len(normalized_row)}"
|
||||
)
|
||||
slot_rows.append(normalized_row)
|
||||
|
||||
return [price_row, *slot_rows]
|
||||
|
||||
|
||||
def _to_text(value):
|
||||
|
||||
if value is None:
|
||||
return ""
|
||||
return str(value)
|
||||
Reference in New Issue
Block a user