Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
21 lines
620 B
Python
21 lines
620 B
Python
"""Which series a unit is, from its serial prefix (decided with Brian, 2026-10-20)."""
|
|
from __future__ import annotations
|
|
|
|
from .errors import BadRequest
|
|
|
|
SERIES_BY_PREFIX = {"UM": 4, "BE": 3, "BA": 3}
|
|
|
|
|
|
def normalise_serial(serial: str) -> str:
|
|
return (serial or "").strip().upper()
|
|
|
|
|
|
def series_for_serial(serial: str) -> int:
|
|
s = normalise_serial(serial)
|
|
for prefix, series in SERIES_BY_PREFIX.items():
|
|
if s.startswith(prefix) and len(s) > len(prefix):
|
|
return series
|
|
raise BadRequest(
|
|
f"unknown serial {serial!r}: expected UM... (Series 4) or BE.../BA... (Series 3)"
|
|
)
|