"""Offline staging of the reviewed DG2 partition of Ritar's public DG table."""
import re
from math import isfinite
from .bsb import _Table
MODELS = tuple(
f"DG2-{n}" for n in (200, 250, 300, 400, 500, 600, 800, 1000, 1200, 1500, 2000, 2500, 3000)
)
[docs]
def stage_dg2(html: str) -> list[dict]:
"""Preserve C20 cell Ah and terminal dimensions; no energy/power inference."""
parser = _Table()
parser.feed(html)
rows = parser.rows
if len(rows) < 2 or rows[:2] != [
[
"Battery model",
"Rated voltage \uff08V\uff09",
"Rated capacity C20\uff08Ah\uff09",
"Battery size",
"Terminal options",
"Terminal location",
],
["Length/mm", "Width/mm", "Height/mm", "Total height/mm"],
]:
raise ValueError("Changed headers/units")
chosen = [(i, r) for i, r in enumerate(rows, 1) if r and r[0].startswith("DG2-")]
if tuple(r[0] for _, r in chosen) != MODELS:
raise ValueError("Changed, missing or duplicate model")
result = []
for index, row in chosen:
if len(row) != 9 or row[7] != "F10(M8)" or row[8] not in {"G", "H", "K", "L"}:
raise ValueError("Changed terminal/shape")
values = [float(x) for x in row[1:7]]
if (
not all(isfinite(x) and x > 0 for x in values)
or values[0] != 2
or values[-1] < values[-2]
):
raise ValueError("Invalid voltage/dimensions/capacity")
result.append(
dict(
model=row[0],
voltage_v=values[0],
c20_ah=values[1],
length_mm=values[2],
width_mm=values[3],
body_height_mm=values[4],
total_height_mm=values[5],
terminal=row[7],
terminal_location=row[8],
table_row=index,
capacity_temperature_c=None,
capacity_endpoint_v=None,
)
)
return result
MONOBLOC_MODELS = (
"DG12-26",
"DG6-100",
"DG6-150",
"DG6-180",
"DG6-200",
"DG6-200S",
"DG6-225",
"DG6-225S",
"DG6-280",
"DG6-310",
"DG6-335",
"DG12-33",
"DG12-40",
"DG12-55",
"DG12-60",
"DG12-65",
"DG12-70",
"DG12-70S",
"DG12-75",
"DG12-75S",
"DG12-80",
"DG12-100S",
"DG12-100",
"DG12-120",
"DG12-134",
"DG12-145",
"DG12-150",
"DG12-160",
"DG12-180",
"DG12-200",
"DG12-225",
"DG12-230",
"DG12-260",
)
[docs]
def stage_monoblocs(html: str) -> list[dict]:
"""Stage 33 reviewed DG6/DG12 codes, preserving block Ah and suffixes.
The live table supplies no capacity temperature or final voltage. Never
infer capacity from the model code, cell Ah, kWh or an optional terminal SKU.
Source rights and PDF discrepancies require review before ingestion.
"""
parser = _Table()
parser.feed(html)
rows = parser.rows
expected_headers = [
[
"Battery model",
"Rated voltage \uff08V\uff09",
"Rated capacity C20\uff08Ah\uff09",
"Battery size",
"Terminal options",
"Terminal location",
],
["Length/mm", "Width/mm", "Height/mm", "Total height/mm"],
]
if rows[:2] != expected_headers:
raise ValueError("Changed headers/units")
selected = [(i, r) for i, r in enumerate(rows, 1) if r and r[0].startswith(("DG6-", "DG12-"))]
if tuple(r[0] for _, r in selected) != MONOBLOC_MODELS:
raise ValueError("Changed, missing or duplicate model")
result = []
for index, row in selected:
if len(row) != 9 or row[8] not in {"A", "B", "C", "D", "E"}:
raise ValueError("Changed terminal/shape")
terminal_pattern = r"(?:F[0-9]+(?:-BP)?\(M[0-9]+\)|T[0-9]+\(M[0-9]+\)|L[0-9]+)"
if not re.fullmatch(terminal_pattern + r"(?:\s*/\s*" + terminal_pattern + ")*", row[7]):
raise ValueError("Changed terminal units")
values = [float(x) for x in row[1:7]]
if (
not all(isfinite(x) and x > 0 for x in values)
or values[0] != (6 if row[0].startswith("DG6-") else 12)
or values[-1] < values[-2]
):
raise ValueError("Invalid voltage/dimensions/capacity")
result.append(
dict(
model=row[0],
voltage_v=values[0],
c20_ah=values[1],
length_mm=values[2],
width_mm=values[3],
body_height_mm=values[4],
total_height_mm=values[5],
terminal=row[7],
terminal_location=row[8],
table_row=index,
capacity_temperature_c=None,
capacity_endpoint_v=None,
capacity_boundary="one monobloc, not one cell",
)
)
return result