Spaces:
Running
Running
standings: 淘汰赛对阵图置顶(32强比分+预测,胜者填入16强),小组赛积分下移
Browse files- apps/web/app/standings/page.tsx +222 -61
- services/api/main.py +97 -0
apps/web/app/standings/page.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
"use client";
|
| 2 |
import { useEffect, useState } from "react";
|
| 3 |
import Link from "next/link";
|
| 4 |
-
import { api, cn, pct } from "@/lib/api";
|
| 5 |
-
import { Spinner, ErrorBox, Flag } from "@/components/ui";
|
| 6 |
|
| 7 |
type Row = {
|
| 8 |
team: string;
|
|
@@ -36,88 +36,249 @@ type Standings = {
|
|
| 36 |
}[];
|
| 37 |
};
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
export default function StandingsPage() {
|
| 40 |
const [d, setD] = useState<Standings | null>(null);
|
|
|
|
| 41 |
const [err, setErr] = useState("");
|
| 42 |
|
| 43 |
useEffect(() => {
|
| 44 |
api<Standings>("/api/standings").then(setD).catch((e) => setErr(String(e.message)));
|
|
|
|
| 45 |
}, []);
|
| 46 |
|
| 47 |
if (err) return <ErrorBox msg={err} />;
|
| 48 |
if (!d) return <Spinner />;
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return (
|
| 51 |
-
<div className="space-y-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
<
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
{/*
|
| 63 |
-
<
|
| 64 |
-
<
|
| 65 |
-
<
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
<
|
| 72 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
</div>
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
</div>
|
| 114 |
-
)
|
|
|
|
| 115 |
</div>
|
| 116 |
-
|
| 117 |
</div>
|
| 118 |
);
|
| 119 |
}
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
function GroupTable({ g, anyPlayed }: { g: Standings["groups"][0]; anyPlayed: boolean }) {
|
| 122 |
return (
|
| 123 |
<div className="card overflow-hidden">
|
|
|
|
| 1 |
"use client";
|
| 2 |
import { useEffect, useState } from "react";
|
| 3 |
import Link from "next/link";
|
| 4 |
+
import { api, cn, pct, bjDate, bjHM } from "@/lib/api";
|
| 5 |
+
import { Spinner, ErrorBox, Flag, ProbBar } from "@/components/ui";
|
| 6 |
|
| 7 |
type Row = {
|
| 8 |
team: string;
|
|
|
|
| 36 |
}[];
|
| 37 |
};
|
| 38 |
|
| 39 |
+
type Pred = {
|
| 40 |
+
p_home: number;
|
| 41 |
+
p_draw: number;
|
| 42 |
+
p_away: number;
|
| 43 |
+
score: [number, number] | null;
|
| 44 |
+
};
|
| 45 |
+
type R32M = {
|
| 46 |
+
match_id: number;
|
| 47 |
+
home: string | null;
|
| 48 |
+
away: string | null;
|
| 49 |
+
home_score: number | null;
|
| 50 |
+
away_score: number | null;
|
| 51 |
+
date: string | null;
|
| 52 |
+
kickoff: string | null;
|
| 53 |
+
played: boolean;
|
| 54 |
+
winner: string | null;
|
| 55 |
+
pred: Pred | null;
|
| 56 |
+
};
|
| 57 |
+
type R16M = {
|
| 58 |
+
match_id: number;
|
| 59 |
+
feeders: [number, number];
|
| 60 |
+
home: string | null;
|
| 61 |
+
away: string | null;
|
| 62 |
+
};
|
| 63 |
+
type KO = { r32: R32M[]; r16: R16M[] };
|
| 64 |
+
|
| 65 |
export default function StandingsPage() {
|
| 66 |
const [d, setD] = useState<Standings | null>(null);
|
| 67 |
+
const [ko, setKo] = useState<KO | null>(null);
|
| 68 |
const [err, setErr] = useState("");
|
| 69 |
|
| 70 |
useEffect(() => {
|
| 71 |
api<Standings>("/api/standings").then(setD).catch((e) => setErr(String(e.message)));
|
| 72 |
+
api<KO>("/api/ko_bracket").then(setKo).catch(() => {});
|
| 73 |
}, []);
|
| 74 |
|
| 75 |
if (err) return <ErrorBox msg={err} />;
|
| 76 |
if (!d) return <Spinner />;
|
| 77 |
|
| 78 |
+
const r32map: Record<number, R32M> = {};
|
| 79 |
+
ko?.r32.forEach((m) => (r32map[m.match_id] = m));
|
| 80 |
+
const hasBracket = !!ko && ko.r32.length > 0;
|
| 81 |
+
|
| 82 |
return (
|
| 83 |
+
<div className="space-y-8">
|
| 84 |
+
{/* ===== knockout bracket (top) ===== */}
|
| 85 |
+
{hasBracket && (
|
| 86 |
+
<section className="space-y-4">
|
| 87 |
+
<div>
|
| 88 |
+
<h1 className="text-3xl font-black">🏆 淘汰赛对阵图</h1>
|
| 89 |
+
<p className="mt-1 text-white/50">
|
| 90 |
+
32 强对阵与 AI 比分预测 · 每场胜者自动填入右侧 16 强对战(
|
| 91 |
+
<span className="text-emerald-400">加粗</span> = 晋级)
|
| 92 |
+
</p>
|
| 93 |
+
</div>
|
| 94 |
+
<div className="grid gap-4 xl:grid-cols-2">
|
| 95 |
+
{ko!.r16.map((blk) => (
|
| 96 |
+
<BracketBlock key={blk.match_id} blk={blk} r32map={r32map} />
|
| 97 |
+
))}
|
| 98 |
+
</div>
|
| 99 |
+
</section>
|
| 100 |
+
)}
|
| 101 |
|
| 102 |
+
{/* ===== group stage (below) ===== */}
|
| 103 |
+
<section className="space-y-6">
|
| 104 |
+
<div>
|
| 105 |
+
<h2 className="text-2xl font-black">📋 小组赛积分榜</h2>
|
| 106 |
+
<p className="mt-1 text-white/50">
|
| 107 |
+
{d.any_played
|
| 108 |
+
? "依据真实比赛结果实时更新积分与排名"
|
| 109 |
+
: "赛事尚未开始 — 当前排名按模型出线概率投影"}
|
| 110 |
+
,绿色=直接出线,黄色=争最佳第三
|
| 111 |
+
</p>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
{/* legend */}
|
| 115 |
+
<div className="flex flex-wrap gap-4 text-xs text-white/50">
|
| 116 |
+
<span className="flex items-center gap-1.5">
|
| 117 |
+
<span className="h-3 w-3 rounded bg-emerald-500/60" /> 前2名直接出线
|
| 118 |
+
</span>
|
| 119 |
+
<span className="flex items-center gap-1.5">
|
| 120 |
+
<span className="h-3 w-3 rounded bg-amber-500/60" /> 小组第3(争8个最佳第三名额)
|
| 121 |
+
</span>
|
| 122 |
+
<span className="flex items-center gap-1.5">
|
| 123 |
+
<span className="h-3 w-3 rounded bg-emerald-400 ring-1 ring-emerald-300" /> 第3且当前排进前8
|
| 124 |
+
</span>
|
| 125 |
+
</div>
|
| 126 |
+
|
| 127 |
+
{/* 12 group tables */}
|
| 128 |
+
<div className="grid gap-5 lg:grid-cols-2">
|
| 129 |
+
{d.groups.map((g) => (
|
| 130 |
+
<GroupTable key={g.group} g={g} anyPlayed={d.any_played} />
|
| 131 |
+
))}
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
{/* best-third race */}
|
| 135 |
+
<div className="card p-6">
|
| 136 |
+
<h2 className="mb-1 text-lg font-bold">最佳第三名争夺</h2>
|
| 137 |
+
<p className="mb-4 text-xs text-white/40">
|
| 138 |
+
12 个小组第三名中,成绩最好的 8 个晋级 32 强(前8 = 出线)
|
| 139 |
+
</p>
|
| 140 |
+
<div className="space-y-1.5">
|
| 141 |
+
{d.thirds_race.map((t, i) => (
|
| 142 |
+
<div
|
| 143 |
+
key={t.team}
|
| 144 |
+
className={`flex items-center gap-3 rounded-lg px-3 py-2 ${
|
| 145 |
+
t.in8 ? "bg-emerald-500/10" : "bg-white/[0.02]"
|
| 146 |
+
}`}
|
| 147 |
+
>
|
| 148 |
+
<span className={`w-6 text-sm font-bold ${i < 8 ? "text-emerald-400" : "text-white/30"}`}>
|
| 149 |
+
{i + 1}
|
| 150 |
+
</span>
|
| 151 |
+
<Flag team={t.team} h={14} />
|
| 152 |
+
<Link
|
| 153 |
+
href={`/teams/${encodeURIComponent(t.team)}`}
|
| 154 |
+
className="flex-1 text-sm hover:text-gold"
|
| 155 |
+
>
|
| 156 |
+
{cn(t.team)}
|
| 157 |
+
<span className="ml-1 text-xs text-white/30">{t.group}组</span>
|
| 158 |
+
</Link>
|
| 159 |
+
<span className="text-xs text-white/40">
|
| 160 |
+
{t.pts}分 净{t.gd >= 0 ? "+" : ""}
|
| 161 |
+
{t.gd}
|
| 162 |
+
</span>
|
| 163 |
+
<span className="w-12 text-right text-xs text-gold">{pct(t.p_advance, 0)}</span>
|
| 164 |
+
{i === 7 && <span className="ml-1 text-[10px] text-emerald-400">出线线 ↑</span>}
|
| 165 |
+
</div>
|
| 166 |
+
))}
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
</section>
|
| 170 |
+
</div>
|
| 171 |
+
);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* ---------- knockout bracket ---------- */
|
| 175 |
+
|
| 176 |
+
function BracketBlock({ blk, r32map }: { blk: R16M; r32map: Record<number, R32M> }) {
|
| 177 |
+
const [fa, fb] = blk.feeders;
|
| 178 |
+
return (
|
| 179 |
+
<div className="card p-3 sm:p-4">
|
| 180 |
+
<div className="grid grid-cols-[1fr_auto] items-center gap-3">
|
| 181 |
+
<div className="space-y-2">
|
| 182 |
+
<R32Card m={r32map[fa]} />
|
| 183 |
+
<R32Card m={r32map[fb]} />
|
| 184 |
+
</div>
|
| 185 |
+
<div className="flex h-full flex-col items-stretch justify-center gap-1 border-l border-white/10 pl-3">
|
| 186 |
+
<span className="mb-0.5 text-center text-[10px] font-semibold text-gold">16 强</span>
|
| 187 |
+
<Advancer team={blk.home} />
|
| 188 |
+
<span className="text-center text-[9px] text-white/20">vs</span>
|
| 189 |
+
<Advancer team={blk.away} />
|
| 190 |
+
</div>
|
| 191 |
</div>
|
| 192 |
+
</div>
|
| 193 |
+
);
|
| 194 |
+
}
|
| 195 |
|
| 196 |
+
function Advancer({ team }: { team: string | null }) {
|
| 197 |
+
if (!team)
|
| 198 |
+
return (
|
| 199 |
+
<div className="rounded-md bg-white/[0.03] px-2 py-1.5 text-center text-xs text-white/25">
|
| 200 |
+
待定
|
| 201 |
</div>
|
| 202 |
+
);
|
| 203 |
+
return (
|
| 204 |
+
<Link
|
| 205 |
+
href={`/teams/${encodeURIComponent(team)}`}
|
| 206 |
+
className="flex items-center gap-1.5 rounded-md bg-gold/10 px-2 py-1.5 hover:bg-gold/20"
|
| 207 |
+
>
|
| 208 |
+
<Flag team={team} h={13} />
|
| 209 |
+
<span className="truncate text-xs font-semibold text-gold">{cn(team)}</span>
|
| 210 |
+
</Link>
|
| 211 |
+
);
|
| 212 |
+
}
|
| 213 |
|
| 214 |
+
function R32Card({ m }: { m?: R32M }) {
|
| 215 |
+
if (!m || (!m.home && !m.away))
|
| 216 |
+
return <div className="rounded-lg border border-white/8 bg-white/[0.02] p-2 text-xs text-white/25">待定</div>;
|
| 217 |
+
const when = m.kickoff
|
| 218 |
+
? `${bjDate(m.kickoff)} ${bjHM(m.kickoff)}`
|
| 219 |
+
: m.date || "";
|
| 220 |
+
return (
|
| 221 |
+
<div className="rounded-lg border border-white/8 bg-white/[0.02] p-2">
|
| 222 |
+
<div className="mb-1 flex items-center justify-between text-[10px] text-white/30">
|
| 223 |
+
<span>{when}</span>
|
| 224 |
+
<span className={m.played ? "text-white/40" : "text-sky-400/70"}>
|
| 225 |
+
{m.played ? "完场" : "AI预测"}
|
| 226 |
+
</span>
|
| 227 |
+
</div>
|
| 228 |
+
<TeamLine
|
| 229 |
+
team={m.home}
|
| 230 |
+
score={m.home_score}
|
| 231 |
+
played={m.played}
|
| 232 |
+
won={!!m.winner && m.winner === m.home}
|
| 233 |
+
/>
|
| 234 |
+
<TeamLine
|
| 235 |
+
team={m.away}
|
| 236 |
+
score={m.away_score}
|
| 237 |
+
played={m.played}
|
| 238 |
+
won={!!m.winner && m.winner === m.away}
|
| 239 |
+
/>
|
| 240 |
+
{!m.played && m.pred && (
|
| 241 |
+
<div className="mt-1.5 space-y-1 border-t border-white/5 pt-1.5">
|
| 242 |
+
{m.pred.score && (
|
| 243 |
+
<div className="text-[10px] text-white/40">
|
| 244 |
+
推荐比分 <b className="text-gold">{m.pred.score[0]}:{m.pred.score[1]}</b>
|
| 245 |
</div>
|
| 246 |
+
)}
|
| 247 |
+
<ProbBar home={m.pred.p_home} draw={m.pred.p_draw} away={m.pred.p_away} />
|
| 248 |
</div>
|
| 249 |
+
)}
|
| 250 |
</div>
|
| 251 |
);
|
| 252 |
}
|
| 253 |
|
| 254 |
+
function TeamLine({
|
| 255 |
+
team,
|
| 256 |
+
score,
|
| 257 |
+
played,
|
| 258 |
+
won,
|
| 259 |
+
}: {
|
| 260 |
+
team: string | null;
|
| 261 |
+
score: number | null;
|
| 262 |
+
played: boolean;
|
| 263 |
+
won: boolean;
|
| 264 |
+
}) {
|
| 265 |
+
return (
|
| 266 |
+
<div className={`flex items-center gap-1.5 py-0.5 ${won ? "" : "opacity-70"}`}>
|
| 267 |
+
{team ? <Flag team={team} h={13} /> : null}
|
| 268 |
+
<span className={`flex-1 truncate text-xs ${won ? "font-bold text-emerald-400" : ""}`}>
|
| 269 |
+
{team ? cn(team) : "待定"}
|
| 270 |
+
</span>
|
| 271 |
+
{played && score != null && (
|
| 272 |
+
<span className={`text-xs tabular-nums ${won ? "font-bold text-emerald-400" : "text-white/60"}`}>
|
| 273 |
+
{score}
|
| 274 |
+
</span>
|
| 275 |
+
)}
|
| 276 |
+
</div>
|
| 277 |
+
);
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
/* ---------- group stage ---------- */
|
| 281 |
+
|
| 282 |
function GroupTable({ g, anyPlayed }: { g: Standings["groups"][0]; anyPlayed: boolean }) {
|
| 283 |
return (
|
| 284 |
<div className="card overflow-hidden">
|
services/api/main.py
CHANGED
|
@@ -890,6 +890,103 @@ def full_schedule():
|
|
| 890 |
return out
|
| 891 |
|
| 892 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
def _get_projected_bracket():
|
| 894 |
"""Helper: get bracket from simulation projections."""
|
| 895 |
with connect() as conn:
|
|
|
|
| 890 |
return out
|
| 891 |
|
| 892 |
|
| 893 |
+
@app.get("/api/ko_bracket")
|
| 894 |
+
def ko_bracket_view():
|
| 895 |
+
"""Round-of-32 bracket with real results + score predictions, and the R16
|
| 896 |
+
pairings formed by the R32 winners. Built deterministically from the real
|
| 897 |
+
knockout fixtures in the DB (authoritative pairings/scores) laid over the
|
| 898 |
+
official bracket template — so third-place slots and penalty-shootout
|
| 899 |
+
advancers come from actual data, not the flaky projection matching."""
|
| 900 |
+
now = time.time()
|
| 901 |
+
if _cache.get("ko_bracket") and _cache["ko_bracket"]["ts"] > now - 900:
|
| 902 |
+
return _cache["ko_bracket"]["data"]
|
| 903 |
+
|
| 904 |
+
with connect() as conn:
|
| 905 |
+
ko = conn.execute(
|
| 906 |
+
"SELECT date,home_team,away_team,home_score,away_score FROM matches "
|
| 907 |
+
"WHERE stage='knockout' ORDER BY date, id").fetchall()
|
| 908 |
+
r32_rows = [dict(r) for r in ko[:16]] # 16 chronologically-first = R32
|
| 909 |
+
later_rows = [dict(r) for r in ko[16:]] # R16+ scheduled so far
|
| 910 |
+
|
| 911 |
+
# teams appearing in a later round have, by definition, advanced past R32 —
|
| 912 |
+
# this resolves penalty-shootout winners that a level score can't.
|
| 913 |
+
advanced = {t for r in later_rows for t in (r["home_team"], r["away_team"])}
|
| 914 |
+
by_team = {} # team -> its R32 fixture row
|
| 915 |
+
for r in r32_rows:
|
| 916 |
+
by_team.setdefault(r["home_team"], r)
|
| 917 |
+
by_team.setdefault(r["away_team"], r)
|
| 918 |
+
|
| 919 |
+
winners, runners, _ = _resolve_bracket_from_standings(_compute_group_standings())
|
| 920 |
+
kmap = _kickoff_map()
|
| 921 |
+
|
| 922 |
+
def _slot_team(slot):
|
| 923 |
+
kind, val = slot
|
| 924 |
+
if kind == "W":
|
| 925 |
+
return winners.get(val)
|
| 926 |
+
if kind == "RU":
|
| 927 |
+
return runners.get(val)
|
| 928 |
+
return None # "3": resolved from the DB row
|
| 929 |
+
|
| 930 |
+
def _actual_winner(row):
|
| 931 |
+
hs, as_ = row["home_score"], row["away_score"]
|
| 932 |
+
if hs is None or as_ is None:
|
| 933 |
+
return None
|
| 934 |
+
if hs != as_:
|
| 935 |
+
return row["home_team"] if hs > as_ else row["away_team"]
|
| 936 |
+
# level score -> decided on penalties; use who turns up in the next round
|
| 937 |
+
h_adv, a_adv = row["home_team"] in advanced, row["away_team"] in advanced
|
| 938 |
+
if h_adv != a_adv:
|
| 939 |
+
return row["home_team"] if h_adv else row["away_team"]
|
| 940 |
+
return None
|
| 941 |
+
|
| 942 |
+
r32, winner_by_mid = [], {}
|
| 943 |
+
for mid in sorted(B.R32):
|
| 944 |
+
sA, sB = B.R32[mid]
|
| 945 |
+
ta, tb = _slot_team(sA), _slot_team(sB)
|
| 946 |
+
row = by_team.get(ta) or by_team.get(tb)
|
| 947 |
+
date = kickoff = hs = as_ = winner = pred = None
|
| 948 |
+
played = False
|
| 949 |
+
if row:
|
| 950 |
+
# fill an unknown (third-place) slot from the real opponent
|
| 951 |
+
other = row["away_team"] if row["home_team"] in (ta, tb) else row["home_team"]
|
| 952 |
+
if ta is None:
|
| 953 |
+
ta = other
|
| 954 |
+
if tb is None:
|
| 955 |
+
tb = other
|
| 956 |
+
date = row["date"]
|
| 957 |
+
kickoff = (kmap.get(f"{row['home_team']}__{row['away_team']}")
|
| 958 |
+
or kmap.get(f"{row['away_team']}__{row['home_team']}"))
|
| 959 |
+
if row["home_score"] is not None:
|
| 960 |
+
played = True
|
| 961 |
+
hs, as_ = ((row["home_score"], row["away_score"])
|
| 962 |
+
if row["home_team"] == ta
|
| 963 |
+
else (row["away_score"], row["home_score"]))
|
| 964 |
+
winner = _actual_winner(row)
|
| 965 |
+
if ta and tb and MODEL.can_predict(ta, tb):
|
| 966 |
+
s = MODEL.match_summary(ta, tb, neutral=True)
|
| 967 |
+
top = (s.get("top_scores") or [None])[0]
|
| 968 |
+
pred = {"p_home": s["p_home"], "p_draw": s["p_draw"], "p_away": s["p_away"],
|
| 969 |
+
"score": [top[0], top[1]] if top else None}
|
| 970 |
+
if winner is None and not played: # project the not-yet-played winner
|
| 971 |
+
winner = ta if s["p_home"] >= s["p_away"] else tb
|
| 972 |
+
winner_by_mid[mid] = winner
|
| 973 |
+
r32.append({
|
| 974 |
+
"match_id": mid, "home": ta, "away": tb,
|
| 975 |
+
"home_score": hs, "away_score": as_,
|
| 976 |
+
"date": date, "kickoff": kickoff,
|
| 977 |
+
"played": played, "winner": winner, "pred": pred,
|
| 978 |
+
})
|
| 979 |
+
|
| 980 |
+
r16 = [{"match_id": mid, "feeders": list(B.FEED[mid]),
|
| 981 |
+
"home": winner_by_mid.get(B.FEED[mid][0]),
|
| 982 |
+
"away": winner_by_mid.get(B.FEED[mid][1])}
|
| 983 |
+
for mid in (89, 90, 91, 92, 93, 94, 95, 96)]
|
| 984 |
+
|
| 985 |
+
data = {"r32": r32, "r16": r16}
|
| 986 |
+
_cache["ko_bracket"] = {"ts": time.time(), "data": data}
|
| 987 |
+
return data
|
| 988 |
+
|
| 989 |
+
|
| 990 |
def _get_projected_bracket():
|
| 991 |
"""Helper: get bracket from simulation projections."""
|
| 992 |
with connect() as conn:
|