From 7c910e9199680fb8d84eb4c699a5c5b50919e82d Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Mon, 29 Jun 2026 13:39:17 -0500 Subject: [PATCH] goals fix --- lib/feeds.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/feeds.ts b/lib/feeds.ts index 1b190ce..5b6f336 100644 --- a/lib/feeds.ts +++ b/lib/feeds.ts @@ -1,4 +1,4 @@ -import { GroupId, Match, MatchStatus, Team } from "./types"; +import { GroupId, GoalEvent, Match, MatchStatus, Team } from "./types"; import { venueFor } from "./venues"; import { localisedTeamName } from "./team-mappings"; import { R32, LATER_ROUNDS, resolveAnnexC, qualifiedThirdGroups } from "./bracket"; @@ -568,7 +568,8 @@ interface Wc26Game { home_score?: string; away_score?: string; time_elapsed?: string; - goals?: Array<{ name?: string; minute?: string; team?: string }>; + home_scorers?: string; + away_scorers?: string; current_minute?: string; } @@ -736,15 +737,28 @@ export function attachKOLiveData(matches: Match[], teams: Team[], koGames: Wc26G if (!isNaN(min)) result.minute = min; } - // Torereignisse - if (wm.goals && wm.goals.length > 0) { - result.goals = wm.goals.map(g => ({ - scorer: g.name ?? "?", - minute: parseInt(g.minute ?? "0", 10) || 0, - team: g.team?.toLowerCase() === "away" ? "away" as const : "home" as const, - })); + // Torereignisse aus home_scorers / away_scorers parsen (Format: "{\"Name Minute'\"}") + const goals: GoalEvent[] = []; + if (wm.home_scorers) parseScorers(wm.home_scorers, "home", goals); + if (wm.away_scorers) parseScorers(wm.away_scorers, "away", goals); + if (goals.length > 0) { + goals.sort((a, b) => a.minute - b.minute); + result.goals = goals; } return result; }); +} + +// Parst worldcup26-Scorer-String: "{\"Casemiro 56'\"}" oder "{\"Player 12'\",\"Other 34'\"}" +function parseScorers(raw: string, team: "home" | "away", out: GoalEvent[]): void { + const cleaned = raw.replace(/[{}"\\]/g, "").trim(); + if (!cleaned) return; + const parts = cleaned.split(","); + for (const p of parts) { + const m = /^(.+?)\s+(\d+)'?\s*$/.exec(p.trim()); + if (m) { + out.push({ scorer: m[1].trim(), minute: parseInt(m[2], 10), team }); + } + } } \ No newline at end of file