v1.2.0 独立详情页+赛季选择+季后赛对阵图:/team|player|game|news|person/<id> 详情页(交叉链接);弹窗加查看完整详情;排名页多赛季切换(2024-25/2025-26);季后赛bracket对阵图(playoffs.py);seed_seasons补充数据

This commit is contained in:
2026-08-17 13:31:26 +08:00
parent fcf5d3fee4
commit 4e360be8c7
10 changed files with 711 additions and 16 deletions
+48 -3
View File
@@ -68,6 +68,7 @@ def _fmt_team(t):
def _fmt_player(p):
return {"id": p["id"], "name": p["name"], "name_en": p["name_en"], "team": p.get("team_name"),
"team_id": p.get("team_id"),
"position": p["position"], "number": p["number"], "height_cm": p["height_cm"],
"weight_kg": p["weight_kg"], "country": p["country"], "draft": f"{p['draft_year']}年 第{p['draft_pick']}顺位" if p["draft_year"] else "落选秀",
"salary_m": p["salary_m"], "season": {"pts": p["season_pts"], "reb": p["season_reb"],
@@ -259,12 +260,15 @@ def get_game_detail(game_id):
# ================================================================== 排名
def search_standings(query_text, limit=20):
def search_standings(query_text, limit=20, season=None):
q = (query_text or "").strip()
tids = _match_team_ids(q)
sql = """SELECT s.*, t.name AS team_name, t.code
FROM standings s JOIN teams t ON s.team_id=t.id"""
conds, args = [], []
if season:
conds.append("s.season=?")
args.append(season)
if tids:
marks = ",".join("?" for _ in tids)
conds.append(f"s.team_id IN ({marks})")
@@ -276,8 +280,49 @@ def search_standings(query_text, limit=20):
where = ("WHERE " + " AND ".join(conds)) if conds else ""
rows = query(f"{sql} {where} ORDER BY s.conference DESC, s.rank ASC LIMIT ?", args + [limit])
return {"_source": "standings", "results": [
{"team": r["team_name"], "code": r["code"], "conference": r["conference"], "rank": r["rank"],
"wins": r["wins"], "losses": r["losses"], "win_pct": round(r["win_pct"] * 100, 1)} for r in rows]}
{"team": r["team_name"], "team_id": r["team_id"], "code": r["code"], "conference": r["conference"], "rank": r["rank"],
"wins": r["wins"], "losses": r["losses"], "win_pct": round(r["win_pct"] * 100, 1),
"season": r["season"]} for r in rows]}
# ================================================================== 比赛结果(按赛季)
def team_games(team_id, season=None, limit=15):
"""球队参与的比赛(详情页用),可按赛季过滤"""
conds, args = ["(g.home_team_id=? OR g.away_team_id=?)"], [team_id, team_id]
if season:
conds.append("g.season=?")
args.append(season)
rows = query(f"""SELECT g.*, ht.name AS home_name, ht.code AS home_code,
at.name AS away_name, at.code AS away_code
FROM games g JOIN teams ht ON g.home_team_id=ht.id JOIN teams at ON g.away_team_id=at.id
WHERE {" AND ".join(conds)} ORDER BY g.game_time DESC LIMIT ?""",
args + [limit])
return [_fmt_game(r) for r in rows]
# ================================================================== 球员比赛记录(技术统计)
def player_game_logs(player_id, limit=10):
"""球员参与的比赛与单场数据(详情页用)"""
rows = query("""SELECT gs.*, g.round_name, g.game_time, g.home_score, g.away_score,
ht.name AS home_name, at.name AS away_name
FROM game_player_stats gs
JOIN games g ON gs.game_id=g.id
JOIN teams ht ON g.home_team_id=ht.id JOIN teams at ON g.away_team_id=at.id
WHERE gs.player_id=? ORDER BY g.game_time DESC LIMIT ?""", (player_id, limit))
out = []
for r in rows:
out.append({"game_id": r["game_id"], "round_name": r["round_name"], "game_time": r["game_time"],
"home_team": r["home_name"], "away_team": r["away_name"],
"home_score": r["home_score"], "away_score": r["away_score"],
"pts": r["points"], "reb": r["rebounds"], "ast": r["assists"],
"stl": r["steals"], "blk": r["blocks"], "min": r["minutes"]})
return out
# ================================================================== 新闻(SQL 关键词 + 向量语义 + 可选 rerank 融合)
def search_news(query_text, limit=5):
q = (query_text or "").strip()
seen, out = set(), []
# ================================================================== 新闻(SQL 关键词 + 向量语义 + 可选 rerank 融合)