sync spectra_replay_normalize.py from production (case-insensitive tankModels/ prefix matching)

This commit is contained in:
deploy-migration
2026-07-02 15:01:09 +00:00
parent 6d7aa52bdf
commit 59350009ee
+10 -3
View File
@@ -10,17 +10,24 @@ MODEL_PREFIXES = ("tankModels/", "airModels/", "aircrafts/")
def strip_model_prefix(unit: Any) -> str: def strip_model_prefix(unit: Any) -> str:
"""Return a bare unit CDK from either ``foo`` or ``tankModels/foo``.""" """Return a bare unit CDK from either ``foo`` or ``tankModels/foo``.
Spectra is inconsistent about prefix casing across replays (observed both
``tankModels/`` and ``tankmodels/`` on the wire), so the match is
case-insensitive.
"""
value = str(unit or "").strip() value = str(unit or "").strip()
lowered = value.lower()
for prefix in MODEL_PREFIXES: for prefix in MODEL_PREFIXES:
if value.startswith(prefix): if lowered.startswith(prefix.lower()):
return value[len(prefix):] return value[len(prefix):]
return value return value
def _model_path(unit: Any) -> str: def _model_path(unit: Any) -> str:
value = str(unit or "").strip() value = str(unit or "").strip()
return value if any(value.startswith(prefix) for prefix in MODEL_PREFIXES) else "" lowered = value.lower()
return value if any(lowered.startswith(prefix.lower()) for prefix in MODEL_PREFIXES) else ""
def _as_number(value: Any) -> float | int | None: def _as_number(value: Any) -> float | int | None: