update for spectra changes (#1363)

This commit is contained in:
NotSoToothless
2026-06-29 11:05:51 -07:00
committed by GitHub
parent fa203c653b
commit 6d251be97c
4 changed files with 79 additions and 16 deletions
+8 -2
View File
@@ -14,6 +14,8 @@ from __future__ import annotations
import logging
from typing import Any, Optional
from spectra_replay_normalize import strip_model_prefix
log = logging.getLogger("tssbot.transform")
# Imported lazily/defensively so the module is importable (and unit-testable for the
@@ -61,7 +63,7 @@ def _build_units(units: list[dict[str, Any]], translate, dead: set[str] | None =
dead = dead or set()
out: list[dict[str, Any]] = []
for u in units or []:
internal = str(u.get("unit") or "").strip()
internal = strip_model_prefix(u.get("unit"))
if not internal:
continue
flag = u.get("dead", u.get("died"))
@@ -71,6 +73,9 @@ def _build_units(units: list[dict[str, Any]], translate, dead: set[str] | None =
"name": translate(internal) or u.get("unit_normalized") or internal,
"used": bool(u.get("used")),
"dead": is_dead,
"unit_type": u.get("unit_type"),
"unit_class": u.get("unit_class"),
"unit_country": u.get("unit_country"),
})
return out
@@ -81,7 +86,7 @@ def _dead_units_by_uid(game: dict[str, Any]) -> dict[str, set[str]]:
kills = ((game.get("events") or {}).get("kills")) or []
for k in kills:
uid = str(k.get("offended_uid") or "")
unit = str(k.get("offended_unit") or "").strip()
unit = strip_model_prefix(k.get("offended_unit"))
if uid and unit:
out.setdefault(uid, set()).add(unit)
return out
@@ -143,6 +148,7 @@ def build_scoreboard_model(game: dict[str, Any], lang_column: str = "<English>")
"fake_nick": None,
"tag": str(p.get("tag") or ""),
"country_id": p.get("country_id"),
"country": p.get("country"),
"air_kills": int(p.get("air_kills") or 0),
"ground_kills": int(p.get("ground_kills") or 0),
"assists": int(p.get("assists") or 0),