поправил треды с pregame и pregame-full-stats, когда матч ОНЛАЙН они перестают обновляться. и поправил функцию team, что если данных по сезону и карьере нет, то мы спокойно отрабатывает с данными по текущей игре

This commit is contained in:
2025-11-06 11:37:54 +03:00
parent eec811a8d2
commit ffe9d357d5

View File

@@ -193,6 +193,7 @@ def start_live_threads(season, game_id):
),
600,
stop_event_live,
True,
),
daemon=True,
),
@@ -205,6 +206,7 @@ def start_live_threads(season, game_id):
),
600,
stop_event_live,
True,
),
daemon=True,
),
@@ -1436,15 +1438,18 @@ async def team(who: str):
full_stat = get_latest_game_safe("pregame-full-stats")
if not full_stat:
raise HTTPException(status_code=503, detail="pregame-full-stats data not ready")
# ⚠️ full_stat_data отсутствует — работаем только с game_data
logger.debug(f"[{who}] full_stat_data not found → continuing with game_data only")
full_stat_data = {}
else:
full_stat_data = full_stat["data"] if "data" in full_stat else full_stat
# нормализуем доступ к данным
game_data = game["data"] if "data" in game else game
full_stat_data = full_stat["data"] if "data" in full_stat else full_stat
result = game_data[
"result"
] # здесь уже безопасно, мы проверили в get_latest_game_safe
result_full = full_stat_data["result"]
result_full = full_stat_data.get("result", {}) if full_stat_data else {}
# в result ожидаем "teams"
teams = result.get("teams")
@@ -1455,10 +1460,10 @@ async def team(who: str):
# выбираем команду
if who == "team1":
payload = next((t for t in teams if t.get("teamNumber") == 1), None)
payload_full = result_full.get("team1PlayersStats")
payload_full = result_full.get("team1PlayersStats") if result_full else []
else:
payload = next((t for t in teams if t.get("teamNumber") == 2), None)
payload_full = result_full.get("team2PlayersStats")
payload_full = result_full.get("team2PlayersStats") if result_full else []
if payload is None:
raise HTTPException(status_code=404, detail=f"{who} not found in game data")