third place fix und polymarket

This commit is contained in:
2026-06-27 14:03:11 -05:00
parent a721de5b23
commit 2b3cadfcb5
4 changed files with 361 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { fetchMatchesAndTeams, fetchOdds, attachOdds, fetchLiveScores, applyLiveScores, assignKONumbersBySlots } from "@/lib/feeds";
import { fetchMatchesAndTeams, fetchOdds, attachOdds, attachKOOdds, fetchLiveScores, applyLiveScores, assignKONumbersBySlots } from "@/lib/feeds";
import { computeGroupTables, computeThirdPlaceTable } from "@/lib/standings";
import { qualifiedThirdGroups, resolveAnnexC } from "@/lib/bracket";
import { securelyQualifiedThirdTeams } from "@/lib/third-place-security";
@@ -14,8 +14,9 @@ export async function GET() {
// Odds sind optional: fällt der Polymarket-Call aus, liefern wir trotzdem.
let matches = rawMatches;
let odds: Awaited<ReturnType<typeof fetchOdds>> | null = null;
try {
const odds = await fetchOdds();
odds = await fetchOdds();
matches = attachOdds(rawMatches, teams, odds);
} catch (err) {
console.error("[polymarket] fetchOdds fehlgeschlagen:", err);
@@ -35,6 +36,27 @@ export async function GET() {
// K.o.-Match-Nummern per Slot-Auflösung vergeben (FIFA-Topologie)
assignKONumbersBySlots(matches, teams);
// Zweiter Durchlauf: Polymarket-Odds auf K.o.-Matches mit aufgelöster R32-Paarung
console.log("[ROUTE] vor attachKOOdds | odds vorhanden:", !!odds, "| odds länge:", odds?.length);
if (odds) {
try {
matches = attachKOOdds(matches, teams, odds);
console.log("[ROUTE] nach attachKOOdds | matches länge:", matches?.length);
} catch (err) {
console.error("[ROUTE] attachKOOdds fehlgeschlagen:", err);
}
}
console.log("[ROUTE] vor PM-SNAPSHOT | matches länge:", matches?.length);
const withProb = matches.filter(m => m.prob != null);
console.log("[PM-SNAPSHOT]", new Date().toISOString(),
"| anzahl mit prob:", withProb.length,
"| spiele:", withProb.map(m => {
const h = teams.find(t=>t.id===m.homeTeamId)?.code;
const a = teams.find(t=>t.id===m.awayTeamId)?.code;
return `${h}-${a}`;
}).join(", "));
// prob-Feld normalisieren: immer null statt undefined, damit JSON konsistent ist
const normalizedMatches = matches.map((m) => ({ ...m, prob: m.prob ?? null }));