flags
This commit is contained in:
13
lib/feeds.ts
13
lib/feeds.ts
@@ -59,8 +59,10 @@ interface FdMatchesResponse {
|
||||
matchday?: number | null;
|
||||
stage: string;
|
||||
group?: string | null;
|
||||
homeTeam: { id: number | null; name: string | null; tla?: string | null };
|
||||
awayTeam: { id: number | null; name: string | null; tla?: string | null };
|
||||
venue?: string | null;
|
||||
attendance?: number | null;
|
||||
homeTeam: { id: number | null; name: string | null; tla?: string | null; crest?: string | null };
|
||||
awayTeam: { id: number | null; name: string | null; tla?: string | null; crest?: string | null };
|
||||
score: { fullTime: { home: number | null; away: number | null } };
|
||||
}>;
|
||||
}
|
||||
@@ -97,7 +99,10 @@ export async function fetchMatchesAndTeams(): Promise<{ matches: Match[]; teams:
|
||||
if (side.id != null && side.name && group) {
|
||||
const id = String(side.id);
|
||||
if (!teamMap.has(id)) {
|
||||
teamMap.set(id, { id, name: side.name, code: side.tla ?? "", group });
|
||||
teamMap.set(id, {
|
||||
id, name: side.name, code: side.tla ?? "", group,
|
||||
crest: side.crest ?? null,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +118,8 @@ export async function fetchMatchesAndTeams(): Promise<{ matches: Match[]; teams:
|
||||
awayTeamId: m.awayTeam.id != null ? String(m.awayTeam.id) : null,
|
||||
homeScore: m.score.fullTime.home,
|
||||
awayScore: m.score.fullTime.away,
|
||||
venue: m.venue ?? null,
|
||||
attendance: m.attendance ?? null,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,14 @@ import {
|
||||
ThirdAssignment, slotLabel,
|
||||
} from "@/lib/bracket";
|
||||
|
||||
// Eine Gruppe gilt als abgeschlossen, wenn alle ihre Gruppenspiele beendet sind
|
||||
// (regulär 6 Spiele pro Vierergruppe). Erst dann sind Platzierungen fix.
|
||||
function groupFinished(group: GroupId, matches: Match[]): boolean {
|
||||
const groupMatches = matches.filter((m) => m.group === group);
|
||||
if (groupMatches.length === 0) return false;
|
||||
return groupMatches.every((m) => m.status === "FINISHED");
|
||||
}
|
||||
|
||||
// Ein aufgelöster Teilnehmer einer K.o.-Begegnung.
|
||||
export interface ResolvedSide {
|
||||
teamId: string | null; // null = noch Platzhalter
|
||||
@@ -11,6 +19,7 @@ export interface ResolvedSide {
|
||||
code: string;
|
||||
score: number | null;
|
||||
isWinner: boolean;
|
||||
provisional: boolean; // true = nur auf Basis aktueller Tabelle, noch nicht fix
|
||||
}
|
||||
|
||||
export interface ResolvedTie {
|
||||
@@ -44,36 +53,44 @@ function loserOf(m: Match | undefined): string | null {
|
||||
}
|
||||
|
||||
// Löst einen R32-Slot (W/R/3) zu einer Team-ID auf, sofern bereits bekannt.
|
||||
// provisional = true, solange die zugrunde liegende Gruppe/Zuordnung nicht fix ist.
|
||||
function resolveR32Slot(
|
||||
slot: BracketSlot,
|
||||
winnerGroup: GroupId | undefined,
|
||||
tables: GroupTable[],
|
||||
assignment: ThirdAssignment | null,
|
||||
thirds: ThirdPlaceRow[],
|
||||
): string | null {
|
||||
matches: Match[],
|
||||
annexResolved: boolean,
|
||||
): { teamId: string | null; provisional: boolean } {
|
||||
const table = (g: GroupId) => tables.find((t) => t.group === g);
|
||||
if (slot.type === "W") {
|
||||
const t = table(slot.group!);
|
||||
return t?.rows.find((r) => r.rank === 1)?.teamId ?? null;
|
||||
const teamId = t?.rows.find((r) => r.rank === 1)?.teamId ?? null;
|
||||
return { teamId, provisional: !groupFinished(slot.group!, matches) };
|
||||
}
|
||||
if (slot.type === "R") {
|
||||
const t = table(slot.group!);
|
||||
return t?.rows.find((r) => r.rank === 2)?.teamId ?? null;
|
||||
const teamId = t?.rows.find((r) => r.rank === 2)?.teamId ?? null;
|
||||
return { teamId, provisional: !groupFinished(slot.group!, matches) };
|
||||
}
|
||||
// 3. Platz: braucht Annex-C-Zuordnung + den Gruppensieger dieses Spiels
|
||||
if (slot.type === "3" && assignment && winnerGroup) {
|
||||
const thirdGroup = assignment[winnerGroup];
|
||||
if (thirdGroup) {
|
||||
const row = thirds.find((r) => r.group === thirdGroup && r.qualifies);
|
||||
return row?.teamId ?? null;
|
||||
// Fix nur, wenn Annex C aufgelöst UND die Quellgruppe abgeschlossen ist.
|
||||
const fix = annexResolved && groupFinished(thirdGroup, matches);
|
||||
return { teamId: row?.teamId ?? null, provisional: !fix };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return { teamId: null, provisional: true };
|
||||
}
|
||||
|
||||
function sideFrom(
|
||||
teamId: string | null, fallbackLabel: string,
|
||||
teams: Team[], feed: Match | undefined, which: "home" | "away",
|
||||
provisional: boolean,
|
||||
): ResolvedSide {
|
||||
const team = teamId ? teams.find((t) => t.id === teamId) : undefined;
|
||||
const score = feed
|
||||
@@ -86,6 +103,7 @@ function sideFrom(
|
||||
code: team?.code ?? "",
|
||||
score,
|
||||
isWinner: teamId != null && w === teamId,
|
||||
provisional: teamId != null && provisional,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -93,10 +111,13 @@ function sideFrom(
|
||||
export function resolveBracket(
|
||||
matches: Match[], teams: Team[], tables: GroupTable[],
|
||||
thirds: ThirdPlaceRow[], assignment: ThirdAssignment | null,
|
||||
annexResolved: boolean,
|
||||
): { r32: ResolvedTie[]; later: Record<number, ResolvedTie> } {
|
||||
// Map: Match-Nummer -> Sieger-Team-ID (für Propagation in Folgerunden)
|
||||
const winners = new Map<number, string | null>();
|
||||
const losers = new Map<number, string | null>();
|
||||
// Map: Match-Nummer -> ist das Spiel beendet (Sieger fix)?
|
||||
const decided = new Map<number, boolean>();
|
||||
|
||||
const r32: ResolvedTie[] = R32.map((rm: R32Match) => {
|
||||
const feed = feedMatch(matches, rm.matchNumber);
|
||||
@@ -105,13 +126,14 @@ export function resolveBracket(
|
||||
// Für 3.-Platz-Slots: Gruppensieger ist die andere Seite (immer W)
|
||||
const winnerGroup = (homeGroup ?? awayGroup) as GroupId | undefined;
|
||||
|
||||
const homeId = resolveR32Slot(rm.home, winnerGroup, tables, assignment, thirds);
|
||||
const awayId = resolveR32Slot(rm.away, winnerGroup, tables, assignment, thirds);
|
||||
const home = sideFrom(homeId, slotLabel(rm.home, assignment, winnerGroup), teams, feed, "home");
|
||||
const away = sideFrom(awayId, slotLabel(rm.away, assignment, winnerGroup), teams, feed, "away");
|
||||
const h = resolveR32Slot(rm.home, winnerGroup, tables, assignment, thirds, matches, annexResolved);
|
||||
const a = resolveR32Slot(rm.away, winnerGroup, tables, assignment, thirds, matches, annexResolved);
|
||||
const home = sideFrom(h.teamId, slotLabel(rm.home, assignment, winnerGroup), teams, feed, "home", h.provisional);
|
||||
const away = sideFrom(a.teamId, slotLabel(rm.away, assignment, winnerGroup), teams, feed, "away", a.provisional);
|
||||
|
||||
winners.set(rm.matchNumber, winnerOf(feed));
|
||||
losers.set(rm.matchNumber, loserOf(feed));
|
||||
decided.set(rm.matchNumber, feed?.status === "FINISHED");
|
||||
return {
|
||||
matchNumber: rm.matchNumber, stage: "R32",
|
||||
home, away, status: feed?.status ?? "SCHEDULED", prob: feed?.prob,
|
||||
@@ -124,12 +146,16 @@ export function resolveBracket(
|
||||
const src = km.losers ? losers : winners;
|
||||
const homeId = src.get(km.fromHome) ?? null;
|
||||
const awayId = src.get(km.fromAway) ?? null;
|
||||
// Ein Folgeteam ist fix, wenn das speisende Spiel beendet ist.
|
||||
const homeProv = !(decided.get(km.fromHome) ?? false);
|
||||
const awayProv = !(decided.get(km.fromAway) ?? false);
|
||||
const homeLabel = `${km.losers ? "Verlierer" : "Sieger"} ${km.fromHome}`;
|
||||
const awayLabel = `${km.losers ? "Verlierer" : "Sieger"} ${km.fromAway}`;
|
||||
const home = sideFrom(homeId, homeLabel, teams, feed, "home");
|
||||
const away = sideFrom(awayId, awayLabel, teams, feed, "away");
|
||||
const home = sideFrom(homeId, homeLabel, teams, feed, "home", homeProv);
|
||||
const away = sideFrom(awayId, awayLabel, teams, feed, "away", awayProv);
|
||||
winners.set(km.matchNumber, winnerOf(feed));
|
||||
losers.set(km.matchNumber, loserOf(feed));
|
||||
decided.set(km.matchNumber, feed?.status === "FINISHED");
|
||||
later[km.matchNumber] = {
|
||||
matchNumber: km.matchNumber, stage: km.stage,
|
||||
home, away, status: feed?.status ?? "SCHEDULED", prob: feed?.prob,
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface Team {
|
||||
name: string; // Anzeigename
|
||||
code: string; // 3-Buchstaben-Code, z.B. GER
|
||||
group: GroupId;
|
||||
crest?: string | null; // URL zur Flagge / zum Wappen (football-data: crest)
|
||||
}
|
||||
|
||||
export type MatchStatus =
|
||||
@@ -33,6 +34,8 @@ export interface Match {
|
||||
awayScore: number | null;
|
||||
// Wahrscheinlichkeiten 0..1 (Polymarket), falls vorhanden
|
||||
prob?: { home: number; draw: number | null; away: number } | null;
|
||||
venue?: string | null; // Austragungsort
|
||||
attendance?: number | null; // Zuschauerzahl, falls verfügbar
|
||||
}
|
||||
|
||||
// Eine berechnete Tabellenzeile innerhalb einer Gruppe.
|
||||
|
||||
Reference in New Issue
Block a user