update for spectra changes (#1363)
This commit is contained in:
@@ -55,6 +55,12 @@ def normalize_ws_message(data: Any) -> Optional[List[Dict[str, Any]]]:
|
|||||||
if isinstance(data, dict) and 'completed' in data:
|
if isinstance(data, dict) and 'completed' in data:
|
||||||
return data['completed']
|
return data['completed']
|
||||||
|
|
||||||
|
if isinstance(data, dict) and isinstance(data.get('data'), dict):
|
||||||
|
return [data['data']]
|
||||||
|
|
||||||
|
if isinstance(data, dict) and isinstance(data.get('data'), list):
|
||||||
|
return data['data']
|
||||||
|
|
||||||
logger.warning(f"Unknown WS message format: {type(data)}")
|
logger.warning(f"Unknown WS message format: {type(data)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
+39
-14
@@ -3185,6 +3185,10 @@ def _unit_to_model_name(unit_name: str) -> str:
|
|||||||
internal = (unit_name or "").strip()
|
internal = (unit_name or "").strip()
|
||||||
if not internal:
|
if not internal:
|
||||||
return "tankModels/unknown"
|
return "tankModels/unknown"
|
||||||
|
if internal.startswith(("tankModels/", "airModels/")):
|
||||||
|
return internal
|
||||||
|
if internal.startswith("aircrafts/"):
|
||||||
|
return f"airModels/{internal.split('/', 1)[1]}"
|
||||||
tags = _get_unit_tags(internal) or []
|
tags = _get_unit_tags(internal) or []
|
||||||
tag_set = set(tags)
|
tag_set = set(tags)
|
||||||
if "type_strike_ucav" in tag_set or "ucav" in internal.lower():
|
if "type_strike_ucav" in tag_set or "ucav" in internal.lower():
|
||||||
@@ -3245,6 +3249,15 @@ def _position_at_time(path: list[dict[str, float]], time_ms: float) -> dict[str,
|
|||||||
return prev
|
return prev
|
||||||
|
|
||||||
|
|
||||||
|
def _event_position_to_dict(pos: Any) -> dict[str, float] | None:
|
||||||
|
if not isinstance(pos, list) or len(pos) < 3:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return {"X": float(pos[0]), "Y": float(pos[1]), "Z": float(pos[2])}
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _zone_geometry_from_raw_zones(zones_src: Any) -> dict[str, dict]:
|
def _zone_geometry_from_raw_zones(zones_src: Any) -> dict[str, dict]:
|
||||||
if not isinstance(zones_src, dict):
|
if not isinstance(zones_src, dict):
|
||||||
return {}
|
return {}
|
||||||
@@ -3307,7 +3320,7 @@ def _convert_ws_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, Any]:
|
|||||||
if not isinstance(ent, dict):
|
if not isinstance(ent, dict):
|
||||||
continue
|
continue
|
||||||
uid = _to_int(ent.get("uid"), 0)
|
uid = _to_int(ent.get("uid"), 0)
|
||||||
unit = str(ent.get("unit") or "")
|
unit = str(ent.get("model_path") or ent.get("unit") or "")
|
||||||
path_raw = ent.get("path") or []
|
path_raw = ent.get("path") or []
|
||||||
if not isinstance(path_raw, list):
|
if not isinstance(path_raw, list):
|
||||||
continue
|
continue
|
||||||
@@ -3349,16 +3362,22 @@ def _convert_ws_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, Any]:
|
|||||||
kill_time = float(kill.get("time") or 0.0)
|
kill_time = float(kill.get("time") or 0.0)
|
||||||
victim_path = entity_paths_by_uid.get(victim_id, [])
|
victim_path = entity_paths_by_uid.get(victim_id, [])
|
||||||
killer_path = entity_paths_by_uid.get(killer_id, [])
|
killer_path = entity_paths_by_uid.get(killer_id, [])
|
||||||
victim_pos = _position_at_time(victim_path, kill_time)
|
victim_pos = (
|
||||||
killer_pos = _position_at_time(killer_path, kill_time)
|
_position_at_time(victim_path, kill_time)
|
||||||
|
or _event_position_to_dict(kill.get("offended_pos"))
|
||||||
|
)
|
||||||
|
killer_pos = (
|
||||||
|
_position_at_time(killer_path, kill_time)
|
||||||
|
or _event_position_to_dict(kill.get("offender_pos"))
|
||||||
|
)
|
||||||
payload: dict[str, Any] = {
|
payload: dict[str, Any] = {
|
||||||
"Time": kill_time,
|
"Time": kill_time,
|
||||||
"VictimID": victim_id,
|
"VictimID": victim_id,
|
||||||
"KillerID": killer_id,
|
"KillerID": killer_id,
|
||||||
"VictimEntityIndex": uid_to_entity_index.get(victim_id, 0),
|
"VictimEntityIndex": uid_to_entity_index.get(victim_id, 0),
|
||||||
"Weapon": str(kill.get("used_weapon") or kill.get("weapon") or ""),
|
"Weapon": str(kill.get("used_weapon") or kill.get("weapon") or ""),
|
||||||
"VictimModel": _unit_to_model_name(str(kill.get("offended_unit") or "")),
|
"VictimModel": _unit_to_model_name(str(kill.get("offended_unit_model_path") or kill.get("offended_unit") or "")),
|
||||||
"KillerModel": _unit_to_model_name(str(kill.get("offender_unit") or "")),
|
"KillerModel": _unit_to_model_name(str(kill.get("offender_unit_model_path") or kill.get("offender_unit") or "")),
|
||||||
"crashed": bool(kill.get("crashed", False)),
|
"crashed": bool(kill.get("crashed", False)),
|
||||||
}
|
}
|
||||||
if victim_pos:
|
if victim_pos:
|
||||||
@@ -3383,8 +3402,8 @@ def _convert_ws_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, Any]:
|
|||||||
"Time": float(dmg.get("time") or 0.0),
|
"Time": float(dmg.get("time") or 0.0),
|
||||||
"OffenderID": _to_int(dmg.get("offender_uid"), 0),
|
"OffenderID": _to_int(dmg.get("offender_uid"), 0),
|
||||||
"OffendedID": _to_int(dmg.get("offended_uid"), 0),
|
"OffendedID": _to_int(dmg.get("offended_uid"), 0),
|
||||||
"OffenderModel": _unit_to_model_name(str(dmg.get("offender_unit") or "")),
|
"OffenderModel": _unit_to_model_name(str(dmg.get("offender_unit_model_path") or dmg.get("offender_unit") or "")),
|
||||||
"OffendedModel": _unit_to_model_name(str(dmg.get("offended_unit") or "")),
|
"OffendedModel": _unit_to_model_name(str(dmg.get("offended_unit_model_path") or dmg.get("offended_unit") or "")),
|
||||||
"Afire": bool(dmg.get("afire", False)),
|
"Afire": bool(dmg.get("afire", False)),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -3468,7 +3487,7 @@ def _convert_local_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, An
|
|||||||
if not isinstance(ent, dict):
|
if not isinstance(ent, dict):
|
||||||
continue
|
continue
|
||||||
uid = _to_int(ent.get("uid"), 0)
|
uid = _to_int(ent.get("uid"), 0)
|
||||||
unit = str(ent.get("unit") or "")
|
unit = str(ent.get("model_path") or ent.get("unit") or "")
|
||||||
path_raw = ent.get("path") or []
|
path_raw = ent.get("path") or []
|
||||||
if not isinstance(path_raw, list):
|
if not isinstance(path_raw, list):
|
||||||
continue
|
continue
|
||||||
@@ -3510,16 +3529,22 @@ def _convert_local_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, An
|
|||||||
kill_time = float(kill.get("time") or 0.0)
|
kill_time = float(kill.get("time") or 0.0)
|
||||||
victim_path = entity_paths_by_uid.get(victim_id, [])
|
victim_path = entity_paths_by_uid.get(victim_id, [])
|
||||||
killer_path = entity_paths_by_uid.get(killer_id, [])
|
killer_path = entity_paths_by_uid.get(killer_id, [])
|
||||||
victim_pos = _position_at_time(victim_path, kill_time)
|
victim_pos = (
|
||||||
killer_pos = _position_at_time(killer_path, kill_time)
|
_position_at_time(victim_path, kill_time)
|
||||||
|
or _event_position_to_dict(kill.get("offended_pos"))
|
||||||
|
)
|
||||||
|
killer_pos = (
|
||||||
|
_position_at_time(killer_path, kill_time)
|
||||||
|
or _event_position_to_dict(kill.get("offender_pos"))
|
||||||
|
)
|
||||||
payload: dict[str, Any] = {
|
payload: dict[str, Any] = {
|
||||||
"Time": kill_time,
|
"Time": kill_time,
|
||||||
"VictimID": victim_id,
|
"VictimID": victim_id,
|
||||||
"KillerID": killer_id,
|
"KillerID": killer_id,
|
||||||
"VictimEntityIndex": uid_to_entity_index.get(victim_id, 0),
|
"VictimEntityIndex": uid_to_entity_index.get(victim_id, 0),
|
||||||
"Weapon": str(kill.get("used_weapon") or kill.get("weapon") or ""),
|
"Weapon": str(kill.get("used_weapon") or kill.get("weapon") or ""),
|
||||||
"VictimModel": _unit_to_model_name(str(kill.get("offended_unit") or "")),
|
"VictimModel": _unit_to_model_name(str(kill.get("offended_unit_model_path") or kill.get("offended_unit") or "")),
|
||||||
"KillerModel": _unit_to_model_name(str(kill.get("offender_unit") or "")),
|
"KillerModel": _unit_to_model_name(str(kill.get("offender_unit_model_path") or kill.get("offender_unit") or "")),
|
||||||
"crashed": bool(kill.get("crashed", False)),
|
"crashed": bool(kill.get("crashed", False)),
|
||||||
}
|
}
|
||||||
if victim_pos:
|
if victim_pos:
|
||||||
@@ -3544,8 +3569,8 @@ def _convert_local_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, An
|
|||||||
"Time": float(dmg.get("time") or 0.0),
|
"Time": float(dmg.get("time") or 0.0),
|
||||||
"OffenderID": _to_int(dmg.get("offender_uid"), 0),
|
"OffenderID": _to_int(dmg.get("offender_uid"), 0),
|
||||||
"OffendedID": _to_int(dmg.get("offended_uid"), 0),
|
"OffendedID": _to_int(dmg.get("offended_uid"), 0),
|
||||||
"OffenderModel": _unit_to_model_name(str(dmg.get("offender_unit") or "")),
|
"OffenderModel": _unit_to_model_name(str(dmg.get("offender_unit_model_path") or dmg.get("offender_unit") or "")),
|
||||||
"OffendedModel": _unit_to_model_name(str(dmg.get("offended_unit") or "")),
|
"OffendedModel": _unit_to_model_name(str(dmg.get("offended_unit_model_path") or dmg.get("offended_unit") or "")),
|
||||||
"Afire": bool(dmg.get("afire", False)),
|
"Afire": bool(dmg.get("afire", False)),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -41,6 +41,7 @@ from data_parser import (
|
|||||||
apply_vehicle_name_filters,
|
apply_vehicle_name_filters,
|
||||||
normalize_name,
|
normalize_name,
|
||||||
)
|
)
|
||||||
|
from spectra_replay_normalize import normalize_spectra_replay
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@@ -1251,7 +1252,7 @@ def transform_to_local_format(api_data: Dict[str, Any]) -> Optional[Dict[str, An
|
|||||||
logging.error("Invalid API data structure")
|
logging.error("Invalid API data structure")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
replay = api_data["completed"][0]
|
replay = normalize_spectra_replay(api_data["completed"][0])
|
||||||
|
|
||||||
winner_winged = str(replay.get("winner") or "")
|
winner_winged = str(replay.get("winner") or "")
|
||||||
loser_winged = str(replay.get("loser") or "")
|
loser_winged = str(replay.get("loser") or "")
|
||||||
|
|||||||
Reference in New Issue
Block a user