Add RCON player profile enrichment

This commit is contained in:
devRaGonSa
2026-05-19 15:34:42 +02:00
parent 419d686671
commit 87c916a7e4
4 changed files with 156 additions and 4 deletions

View File

@@ -253,9 +253,21 @@ def _build_materialized_recent_item(item: dict[str, object]) -> dict[str, object
def _build_materialized_detail_item(materialized: dict[str, object]) -> dict[str, object]:
from .rcon_admin_log_storage import get_latest_rcon_player_profile_summaries
match = materialized["match"]
recent_item = _build_materialized_recent_item(match)
players = [_build_player_row(row) for row in materialized["players"]]
profile_summaries = get_latest_rcon_player_profile_summaries(
target_key=str(match["target_key"]),
player_ids=[str(row["player_id"]) for row in materialized["players"] if row.get("player_id")],
)
players = [
_build_player_row(
row,
profile_summary=profile_summaries.get(str(row.get("player_id"))),
)
for row in materialized["players"]
]
return {
**recent_item,
"match_id": match["match_key"],
@@ -270,10 +282,14 @@ def _build_materialized_detail_item(materialized: dict[str, object]) -> dict[str
}
def _build_player_row(row: dict[str, object]) -> dict[str, object]:
def _build_player_row(
row: dict[str, object],
*,
profile_summary: dict[str, object] | None = None,
) -> dict[str, object]:
kills = _coerce_optional_int(row.get("kills")) or 0
deaths = _coerce_optional_int(row.get("deaths")) or 0
return {
player = {
"player_name": row.get("player_name"),
"team": row.get("team"),
"kills": kills,
@@ -284,6 +300,9 @@ def _build_player_row(row: dict[str, object]) -> dict[str, object]:
"most_killed": _top_counter(row.get("most_killed_json")),
"death_by": _top_counter(row.get("death_by_json")),
}
if profile_summary:
player["profile_summary"] = profile_summary
return player
def _top_counter(raw_value: object, *, limit: int = 5) -> list[dict[str, object]]: